diff options
-rw-r--r-- | appinfo/routes.php | 1 | ||||
-rw-r--r-- | controller/iconcontroller.php | 22 | ||||
-rw-r--r-- | js/app/directives/iconpicker.js | 40 | ||||
-rw-r--r-- | templates/views/partials/icon-picker.html | 5 |
4 files changed, 53 insertions, 15 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php index ab7d9152..37fb1fbe 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -78,6 +78,7 @@ return [ #Icons + ['name' => 'icon#getSingleIcon', 'url' => '/api/v2/geticon/{base64Url}', 'verb' => 'GET'], ['name' => 'icon#getIcon', 'url' => '/api/v2/icon/{base64Url}', 'verb' => 'GET'], ['name' => 'icon#getIcon', 'url' => '/api/v2/icon/{base64Url}/{credentialId}', 'verb' => 'GET'], ['name' => 'icon#getLocalIconList', 'url' => '/api/v2/icon/list', 'verb' => 'GET'], diff --git a/controller/iconcontroller.php b/controller/iconcontroller.php index 792b7742..97a24813 100644 --- a/controller/iconcontroller.php +++ b/controller/iconcontroller.php @@ -56,6 +56,28 @@ class IconController extends ApiController { * @NoAdminRequired * @NoCSRFRequired */ + public function getSingleIcon($base64Url) { + $url = base64_decode(str_replace('_','/', $base64Url)); + if (!preg_match("~^(?:f|ht)tps?://~i", $url)) { + $url = "http://" . $url; + } + + + $icon = new IconService($url); + + if ($icon->icoExists) { + $icon_json['type']= $icon->icoType; + $icon_json['content']= base64_encode($icon->icoData); + return new JSONResponse($icon_json); + } + + return new JSONResponse(); + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ public function getIcon($base64Url, $credentialId) { $url = base64_decode(str_replace('_','/', $base64Url)); diff --git a/js/app/directives/iconpicker.js b/js/app/directives/iconpicker.js index fafb1136..195ee35e 100644 --- a/js/app/directives/iconpicker.js +++ b/js/app/directives/iconpicker.js @@ -115,26 +115,40 @@ $('#iconPicker').dialog('close'); }; + scope.refreshUrlIcon = function(){ + var queryUrl = OC.generateUrl('apps/passman/api/v2/geticon/'+btoa(scope.credential.url)); + $http.get(queryUrl).then(function (response) { + + scope.customIcon = {}; + scope.customIcon.data='data:image/'+response.data.type+';base64,'+response.data.content; + console.log(scope.customIcon.data); + + if (response.data) { + return response.data; + } else { + return response; + } + }); + }; + scope.useIcon = function() { if(scope.customIcon){ var data = scope.customIcon.data; scope.credential.icon.type = data.substring(data.lastIndexOf(":")+1,data.lastIndexOf(";")); scope.credential.icon.content = data.substring(data.lastIndexOf(",")+1, data.length); - $('#iconPicker').dialog('close'); - return; + }else{ + $http.get(scope.selectedIcon.url).then(function(result) { + var base64Data = window.btoa(result.data); + var mimeType = 'svg+xml'; + if(!scope.credential.icon){ + scope.credential.icon = {}; + } + scope.credential.icon.type = mimeType; + scope.credential.icon.content = base64Data; + }); } - - $http.get(scope.selectedIcon.url).then(function(result) { - var base64Data = window.btoa(result.data); - var mimeType = 'svg+xml'; - if(!scope.credential.icon){ - scope.credential.icon = {}; - } - scope.credential.icon.type = mimeType; - scope.credential.icon.content = base64Data; - $('#iconPicker').dialog('close'); - }); + $('#iconPicker').dialog('close'); }; $(element).click(function() { diff --git a/templates/views/partials/icon-picker.html b/templates/views/partials/icon-picker.html index 7ab33c6f..10aed43f 100644 --- a/templates/views/partials/icon-picker.html +++ b/templates/views/partials/icon-picker.html @@ -31,8 +31,9 @@ <br /> <button ng-click="useIcon()">{{ 'use.icon' | translate}}</button> </div> - <div ng-if="credential.icon"> - <button ng-click="deleteIcon()">{{ 'use.icon.delete' | translate}}</button> + <div > + <button ng-click="deleteIcon()" ng-if="credential.icon">{{ 'use.icon.delete' | translate}}</button> + <button ng-click="refreshUrlIcon()">{{ 'use.icon.refresh' | translate}}</button> </div> </div> </div> |