diff options
| author | pliablepixels <pliablepixels@gmail.com> | 2016-01-22 15:32:22 -0500 |
|---|---|---|
| committer | pliablepixels <pliablepixels@gmail.com> | 2016-01-22 15:32:22 -0500 |
| commit | 5c5a5fd83d8552de34cbe0a40d192b2443c62d83 (patch) | |
| tree | 6625e52dd49c238c683d9d3c66697f101f980797 /www/js | |
| parent | d3dede8181d813e4b490aba4a8a9099366b63711 (diff) | |
#147 directed images through http interceptor
Former-commit-id: ed7370e244a1bc7d0badfabd763b28e0229682b7
Diffstat (limited to 'www/js')
| -rw-r--r-- | www/js/app.js | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/www/js/app.js b/www/js/app.js index 005e9135..0b289623 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -69,6 +69,43 @@ angular.module('zmApp', [ }) +//credit http://stackoverflow.com/questions/20997406/force-http-interceptor-in-dynamic-ngsrc-request +.directive('httpSrc', [ + '$http', function ($http) { + var directive = { + link: link, + restrict: 'A' + }; + return directive; + + function link(scope, element, attrs) { + var requestConfig = { + method: 'Get', + url: attrs.httpSrc, + responseType: 'arraybuffer', + cache: 'true' + }; + + $http(requestConfig) + .success(function(data) { + var arr = new Uint8Array(data); + + var raw = ''; + var i, j, subArray, chunk = 5000; + for (i = 0, j = arr.length; i < j; i += chunk) { + subArray = arr.subarray(i, i + chunk); + raw += String.fromCharCode.apply(null, subArray); + } + + var b64 = btoa(raw); + + attrs.$set('src', "data:image/jpeg;base64," + b64); + }); + } + + } + ]) + //------------------------------------------------------------------ // switch between collection repeat or ng-repeat @@ -260,14 +297,14 @@ angular.module('zmApp', [ // handle basic auth properly if (config.url.indexOf("@") > -1) { - // console.log ("HTTP basic auth INTERCEPTOR URL IS " + config.url); + //console.log ("HTTP basic auth INTERCEPTOR URL IS " + config.url); var components = URI.parse(config.url); - //console.log ("Parsed data is " + JSON.stringify(components)); + // console.log ("Parsed data is " + JSON.stringify(components)); var credentials = btoa(components.userinfo); //var authorization = {'Authorization': 'Basic ' + credentials}; - config.headers.Authorization = 'Basic ' + credentials; + config.headers.Authorization = 'Basic ' + credentials; - //console.log ("Full headers: " + JSON.stringify(config.headers)); + // console.log ("Full headers: " + JSON.stringify(config.headers)); } |
