Skip to content
Snippets Groups Projects
Commit e4be2e45 authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Replace all OEmbed.cache

parent abe1cd3b
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,7 @@ Package.onUse(function(api) { ...@@ -28,6 +28,7 @@ Package.onUse(function(api) {
api.addFiles('client/oembedUrlWidget.coffee', 'client'); api.addFiles('client/oembedUrlWidget.coffee', 'client');
api.addFiles('server/server.coffee', 'server'); api.addFiles('server/server.coffee', 'server');
api.addFiles('server/models/OEmbedCache.coffee', 'server');
api.export('OEmbed', 'server'); api.export('OEmbed', 'server');
}); });
......
RocketChat.models.OEmbedCache = new class asd extends RocketChat.models._Base
constructor: ->
@model = new Meteor.Collection 'rocketchat_oembed_cache'
# FIND ONE
findOneById: (_id, options) ->
query =
_id: _id
return @findOne query, options
# INSERT
createWithIdAndData: (_id: data) ->
record =
_id: _id
data: data
updatedAt: new Date
record._id = @insert record
return record
...@@ -3,8 +3,7 @@ http = Npm.require('http') ...@@ -3,8 +3,7 @@ http = Npm.require('http')
https = Npm.require('https') https = Npm.require('https')
querystring = Npm.require('querystring') querystring = Npm.require('querystring')
OEmbed = OEmbed = {}
cache: new Meteor.Collection 'rocketchat_oembed_cache'
getUrlContent = (urlObj, redirectCount = 5, callback) -> getUrlContent = (urlObj, redirectCount = 5, callback) ->
if _.isString(urlObj) if _.isString(urlObj)
...@@ -117,14 +116,14 @@ OEmbed.getUrlMeta = (url, withFragment) -> ...@@ -117,14 +116,14 @@ OEmbed.getUrlMeta = (url, withFragment) ->
} }
OEmbed.getUrlMetaWithCache = (url, withFragment) -> OEmbed.getUrlMetaWithCache = (url, withFragment) ->
cache = OEmbed.cache.findOne {_id: url} cache = RocketChat.models.OEmbedCache.findOneById url
if cache? if cache?
return cache.data return cache.data
data = OEmbed.getUrlMeta url, withFragment data = OEmbed.getUrlMeta url, withFragment
if data? if data?
OEmbed.cache.insert {_id: url, data: data, updatedAt: new Date} RocketChat.models.OEmbedCache.createWithIdAndData url, data
return data return data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment