diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 00000000..60d9a15d --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,8 @@ +module.exports = { + printWidth: 100, + tabWidth: 2, + semi: true, + singleQuote: true, + trailingComma: 'all', //所有场景都会自动加逗号 + arrowParens: 'avoid', //如果只有一个参数,可以不要括号 +}; diff --git a/app/components/services/oss2.js b/app/components/services/oss2.js index 5e116448..4553b8ba 100644 --- a/app/components/services/oss2.js +++ b/app/components/services/oss2.js @@ -1473,7 +1473,7 @@ angular.module('web').factory('ossSvs2', [ ['catch'](handleError); } - function restoreFile(region, bucket, key, days) { + function restoreFile(region, bucket, key, days, tier) { return new Promise(function(a, b) { var client = getClient({ region: region, @@ -1483,9 +1483,14 @@ angular.module('web').factory('ossSvs2', [ Bucket: bucket, Key: key, RestoreRequest: { - Days: days || 7 + Days: days || 7, } }; + if (tier) { + opt.RestoreRequest.JobParameters = { + Tier: tier + }; + } client.restoreObject(opt, function(err, data) { if (err) { @@ -1555,7 +1560,7 @@ angular.module('web').factory('ossSvs2', [ c++; - if (!item.isFile || item.storageClass != 'Archive') { + if (!item.isFile || !['Archive', 'ColdArchive', 'DeepColdArchive'].includes(item.storageClass)) { _dig(); return; diff --git a/app/components/services/util.js b/app/components/services/util.js index 3ea2d4ae..d23317f5 100644 --- a/app/components/services/util.js +++ b/app/components/services/util.js @@ -1,8 +1,9 @@ angular.module('web').factory('utilSvs', [ '$timeout', - function($timeout) { + function ($timeout) { return { - leftTime: leftTime + leftTime: leftTime, + isArchiveRead: isArchiveRead, }; function leftTime(ms) { @@ -10,9 +11,13 @@ angular.module('web').factory('utilSvs', [ return ''; } - if (ms <= 0) { return 0; } + if (ms <= 0) { + return 0; + } - if (ms < 1000) { return ms + 'ms'; } + if (ms < 1000) { + return ms + 'ms'; + } // return moment.duration(ms).humanize(); var t = []; @@ -51,5 +56,18 @@ angular.module('web').factory('utilSvs', [ // } return t.join(' '); } - } + + //文件是否处于可读状态 + function isArchiveRead(items) { + for (const item of items) { + if ( + ['Archive', 'ColdArchive', 'DeepColdArchive'].includes(item.storageClass) && + item.storageStatus !== 3 + ) { + return false; + } + } + return true; + } + }, ]); diff --git a/app/main/files/_/batch-restore-modal.js b/app/main/files/_/batch-restore-modal.js index c6f683e7..87bd826e 100644 --- a/app/main/files/_/batch-restore-modal.js +++ b/app/main/files/_/batch-restore-modal.js @@ -8,63 +8,72 @@ angular.module('web').controller('batchRestoreModalCtrl', [ 'callback', 'Toast', 'safeApply', - function( - $scope, - $modalInstance, - $translate, - ossSvs2, - items, - currentInfo, - callback, - Toast, - safeApply + function ( + $scope, + $modalInstance, + $translate, + ossSvs2, + items, + currentInfo, + callback, + Toast, + safeApply, ) { + /* 多文件解冻 */ var T = $translate.instant; angular.extend($scope, { currentInfo: currentInfo, items: items, + classList: items.map(item => item.storageClass), info: { days: 1, - msg: null + msg: null, + coldDays: 1, + coldMode: 'Expedited', + deepColdDays: 1, + deepColdMode: 'Expedited', }, cancel: cancel, - onSubmit: onSubmit + onSubmit: onSubmit, }); init(); function init() { $scope.isLoading = true; - for (let i in items) { - ossSvs2 - .getFileInfo(currentInfo.region, currentInfo.bucket, items[i].path) - .then(function(data) { - if (data.Restore) { - var info = parseRestoreInfo(data.Restore); - - if (info['ongoing-request'] == 'true') { - $scope.info.type = 2; - } else { - $scope.info.type = 3; - $scope.inf.expiry_date = info['expiry-date']; - } - } else { - $scope.info.type = 1; - } - - $scope.isLoading = false; - safeApply($scope); - }); + const pros = []; + for (const i of items) { + const p = ossSvs2.getFileInfo(currentInfo.region, currentInfo.bucket, i.path); + pros.push(p); } + + Promise.all(pros).then(function (datas) { + const data = datas.find(item => !!item.Restore); //有解冻记录 + if (data && data.Restore) { + var info = parseRestoreInfo(data.Restore); + + if (info['ongoing-request'] == 'true') { + $scope.info.type = 2; + } else { + $scope.info.type = 3; + $scope.info.expiry_date = info['expiry-date']; + } + } else { + $scope.info.type = 1; + } + + $scope.isLoading = false; + safeApply($scope); + }); } function parseRestoreInfo(s) { - var arr = s.match(/([\w\-]+)=\"([^\"]+)\"/g); + var arr = s.match(/([\w-]+)="([^"]+)"/g); var m = {}; - angular.forEach(arr, function(n) { - var kv = n.match(/([\w\-]+)=\"([^\"]+)\"/); + angular.forEach(arr, function (n) { + var kv = n.match(/([\w-]+)="([^"]+)"/); m[kv[1]] = kv[2]; }); @@ -77,27 +86,47 @@ angular.module('web').controller('batchRestoreModalCtrl', [ } function onSubmit(form1) { - if (!form1.$valid) { return; } + if (!form1.$valid) { + return; + } var days = $scope.info.days; + var coldDays = $scope.info.coldDays; + var coldMode = $scope.info.coldMode; + var deepColdDays = $scope.info.deepColdDays; + var deepColdMode = $scope.info.deepColdMode; Toast.info(T('restore.on')); // '提交中...' - for (let i in items) { - ossSvs2 - .restoreFile( - currentInfo.region, - currentInfo.bucket, - items[i].path, - days - ) - .then(function() { - callback(); - cancel(); - }); + const ps = []; + for (let item of items) { + const { storageClass, path } = item; + + if (storageClass === 'Archive') + ps.push(ossSvs2.restoreFile(currentInfo.region, currentInfo.bucket, path, days)); + if (storageClass === 'ColdArchive') { + ps.push( + ossSvs2.restoreFile(currentInfo.region, currentInfo.bucket, path, coldDays, coldMode), + ); + } + if (storageClass === 'DeepColdArchive') { + ps.push( + ossSvs2.restoreFile( + currentInfo.region, + currentInfo.bucket, + path, + deepColdDays, + deepColdMode, + ), + ); + } } + Promise.all(ps).then(function () { + callback(); + cancel(); + }); - Toast.success(T('restore.success')); // '恢复请求已经提交' + Toast.success(T('restore.success'), 4000); // '恢复请求已经提交' } - } + }, ]); diff --git a/app/main/files/_/file-list.html b/app/main/files/_/file-list.html index 4b1b70f0..d64ff15a 100644 --- a/app/main/files/_/file-list.html +++ b/app/main/files/_/file-list.html @@ -25,6 +25,10 @@ {{'type'|translate}} / {{'size'|translate}} + + + {{'storageClassesType'|translate}} + {{'lastModifyTime'|translate}} @@ -83,9 +87,7 @@ tooltip-popup-delay="500" tooltip-append-to-body="true" > - {{item.name|sub:50}} + {{item.name|sub:50}} {{item.size|sizeFormat}} + + {{'storageClassesType.'+item.storageClass.toLowerCase()|translate}} + {{item.lastModified|timeFormat}} | - - + {{'download'|translate}} | - - - + + {{'restore'|translate}} | - + + + + {{'restoring'|translate}} + + | + {{'delete'|translate}} diff --git a/app/main/files/_/file-toolbar.html b/app/main/files/_/file-toolbar.html index 7f305c12..799f45bb 100644 --- a/app/main/files/_/file-toolbar.html +++ b/app/main/files/_/file-toolbar.html @@ -83,7 +83,7 @@