From 9ae25440f70d97ce33dc2b139b381a098f761349 Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Sat, 13 Jun 2015 00:41:53 +0300 Subject: Image proxy is WORKING --- .meteor/packages | 1 + .meteor/versions | 1 + client/button.js | 3 +++ client/templates/photos.html | 2 +- lib/router.js | 9 +++++++++ server/methods.js | 2 +- 6 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.meteor/packages b/.meteor/packages index c42999a..9d1fb01 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -14,3 +14,4 @@ iron:router http nemo64:bootstrap less +aldeed:http diff --git a/.meteor/versions b/.meteor/versions index 0236d4e..3f447c8 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -1,6 +1,7 @@ accounts-base@1.2.0 accounts-oauth@1.1.5 accounts-ui-unstyled@1.1.7 +aldeed:http@0.2.2 autopublish@1.0.3 autoupdate@1.2.1 base64@1.0.3 diff --git a/client/button.js b/client/button.js index 420224d..2fabf31 100644 --- a/client/button.js +++ b/client/button.js @@ -60,6 +60,9 @@ Template.photo.helpers({ date: function () { var d = new Date(parseInt(this.created_time) * 1000); return d.getDate() + '/' + (d.getMonth() + 1) + '/' + d.getFullYear(); + }, + proxy: function (url) { + return url.replace('https://scontent.cdninstagram.com', '/imgproxy?url=') } }) diff --git a/client/templates/photos.html b/client/templates/photos.html index c87b225..41873bc 100644 --- a/client/templates/photos.html +++ b/client/templates/photos.html @@ -14,7 +14,7 @@ diff --git a/lib/router.js b/lib/router.js index 67be61d..ed4e2ef 100644 --- a/lib/router.js +++ b/lib/router.js @@ -5,3 +5,12 @@ Router.configure({ Router.route('/', {name: 'login'}); Router.route('/dates', {name: 'dates'}); Router.route('/photos', {name: 'photos'}); + +Router.route('/imgproxy', function () { + var self = this; + var url = 'http://scontent.cdninstagram.com' + this.request._parsedUrl.search.match(/url\=[^\&]+/)[0].split('=')[1]; + self.response.setHeader('Content-Type', 'image/jpeg'); + var res = HTTP.call('GET', url, { responseType: 'buffer' }); + self.response.write(res.content); + self.response.end(); +}, { where: 'server' }); diff --git a/server/methods.js b/server/methods.js index a177eff..d4cbaec 100644 --- a/server/methods.js +++ b/server/methods.js @@ -1,7 +1,7 @@ Meteor.methods({ getInstagramMedia: function (year, month) { this.unblock(); - return Meteor.http.call('GET', 'https://api.instagram.com/v1/users/self/media/recent', { + return HTTP.get('https://api.instagram.com/v1/users/self/media/recent', { 'params': { 'access_token': Meteor.user().services.instagram.accessToken, 'min_timestamp': Math.round(Date.UTC(month==1?year-1:year, month==1?12:month-1) / 1000), -- cgit v1.3.1