From 05d6ccd17d8f5d592104bd7eff5661ab78dea110 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Sun, 4 Oct 2020 19:14:42 -0400 Subject: switch to browser fetch to download media for desktops, use timestamped filenames - should also resolve #989 --- www/js/EventCtrl.js | 54 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 12 deletions(-) (limited to 'www/js/EventCtrl.js') diff --git a/www/js/EventCtrl.js b/www/js/EventCtrl.js index a3f86425..3d4146af 100644 --- a/www/js/EventCtrl.js +++ b/www/js/EventCtrl.js @@ -723,13 +723,15 @@ angular.module('zmApp.controllers') } - function saveNow(imgsrc) { + function saveNow(imgsrc,eid) { + + NVR.debug ("saveNow in EventCtrl called with "+imgsrc+" and "+ eid); + var fname; + //var timestamp=moment().format('-MMM-Do-YY-HH-mm-ss'); - var fname = "zmninja.jpg"; var fn = "cordova.plugins.photoLibrary.saveImage"; var loginData = NVR.getLogin(); - - + fname = "zmNinja-eid-"+eid+".jpg"; $ionicLoading.show({ template: $translate.instant('kSavingSnapshot') + "...", noBackdrop: true, @@ -770,7 +772,7 @@ angular.module('zmApp.controllers') function (entry) { NVR.debug("local download complete: " + entry.toURL()); NVR.debug("Now trying to move it to album"); - var pluginName = (fname == "zmNinja.mp4" ? "saveVideo" : "saveImage"); + var pluginName = ((fname.indexOf('.mp4') != -1) ? "saveVideo" : "saveImage"); cordova.plugins.photoLibrary[pluginName](entry.toURL(), album, @@ -824,12 +826,39 @@ angular.module('zmApp.controllers') //desktop $ionicLoading.hide(); + $ionicLoading.show({ + template: $translate.instant('kPleaseWait') + "...", + noBackdrop: true + }); - $rootScope.zmPopup = SecuredPopups.show('alert', { - title: $translate.instant('kNote'), - template: $translate.instant('kDownloadVideoImage') + "

" + " " + $translate.instant('kDownload') + "
", - okText: $translate.instant('kDismiss'), - okType: 'button-stable' + fname = "zmninja-eid-"+eid+".jpg"; + fetch(url).then(function (resp) { + return resp.blob(); + }).then(function (blob) { + $ionicLoading.hide(); + var url = window.URL.createObjectURL(blob); + $rootScope.zmPopup = SecuredPopups.show('alert', { + title: $translate.instant('kNote'), + template: $translate.instant('kDownloadVideoImage') + "

" + " " + $translate.instant('kDownload') + "
", + okText: $translate.instant('kDismiss'), + okType: 'button-stable' + }); + + $rootScope.zmPopup.then (function (res) { + //console.log ('DONE RELEASE'); + NVR.debug ('download successful'); + window.URL.revokeObjectURL(url); + $ionicLoading.hide(); + + + }); + }).catch(function () { + $ionicLoading.hide(); + $ionicLoading.show({ + template: $translate.instant('kErrorSave'), + noBackdrop: true, + duration: 2000 + }); }); @@ -1080,7 +1109,7 @@ angular.module('zmApp.controllers') }; $scope.showImage = function (p, f, fid, e, imode, id, parray, ndx) { - var img; + var eid = e; // console.log ("P="+p+" F="+f+" E="+e+" imode="+imode+" id="+id+" parray="+JSON.stringify(parray)+" ndx="+ndx); @@ -1140,7 +1169,7 @@ angular.module('zmApp.controllers') type: 'button-assertive button-small ion-camera', onTap: function (e) { e.preventDefault(); - saveNow($scope.imgsrc); + saveNow($scope.imgsrc,eid); } }, @@ -3193,6 +3222,7 @@ angular.module('zmApp.controllers') if (now - loadMoreTime > 1500) { NVR.debug("$scope.loadMore > loadMore() ... delta: " + (now - loadMoreTime)); loadMore(); + loadMoreTime = Date.now(); $scope.$broadcast('scroll.infiniteScrollComplete'); } else { -- cgit v1.2.3