Skip to content

feat: cold archive and deep cold archive support restore #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
printWidth: 100,
tabWidth: 2,
semi: true,
singleQuote: true,
trailingComma: 'all', //所有场景都会自动加逗号
arrowParens: 'avoid', //如果只有一个参数,可以不要括号
};
11 changes: 8 additions & 3 deletions app/components/services/oss2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 23 additions & 5 deletions app/components/services/util.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
angular.module('web').factory('utilSvs', [
'$timeout',
function($timeout) {
function ($timeout) {
return {
leftTime: leftTime
leftTime: leftTime,
isArchiveRead: isArchiveRead,
};

function leftTime(ms) {
if (isNaN(ms)) {
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 = [];
Expand Down Expand Up @@ -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;
}
},
]);
129 changes: 79 additions & 50 deletions app/main/files/_/batch-restore-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
});
Expand All @@ -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); // '恢复请求已经提交'
}
}
},
]);
33 changes: 22 additions & 11 deletions app/main/files/_/file-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<!-- 大小 -->
{{'type'|translate}} / {{'size'|translate}}
</th>
<th>
<!-- 存储类型 -->
{{'storageClassesType'|translate}}
</th>
<th>
<!-- 最后修改时间 -->
{{'lastModifyTime'|translate}}
Expand Down Expand Up @@ -83,9 +87,7 @@
tooltip-popup-delay="500"
tooltip-append-to-body="true"
>
<span ng-class="{'text-muted': item.status=='uploading'}"
>{{item.name|sub:50}}</span
>
<span ng-class="{'text-muted': item.status=='uploading'}">{{item.name|sub:50}}</span>
</a>
<span>
<object
Expand All @@ -111,13 +113,16 @@
</span>
<span ng-if="item.isFolder!=true">{{item.size|sizeFormat}}</span>
</td>
<td>
<span ng-if="item.isFolder!=true">{{'storageClassesType.'+item.storageClass.toLowerCase()|translate}}</span>
</td>
<td>{{item.lastModified|timeFormat}}</td>
<td align="right">
<!-- <a href="" ng-if="item.isFolder!=true" ng-click="showPreview(item);$event.stopPropagation()">预览</a> -->
<!-- <a href="" ng-if="item.isFolder==true" ng-click="goIn(currentBucket,item.path);$event.stopPropagation()">进入</a>
| -->
<span
ng-if="!item.isFolder && (item.storageClass!='Archive' || item.storageStatus==3)"
ng-if="!item.isFolder && (!['Archive','ColdArchive','DeepColdArchive'].includes(item.storageClass) || item.storageStatus==3)"
>
<a
href=""
Expand All @@ -129,25 +134,31 @@
</a>
|
</span>

<span ng-if="item.storageClass!='Archive' || item.storageStatus==3">
<span ng-if="!['Archive','ColdArchive','DeepColdArchive'].includes(item.storageClass) || item.storageStatus==3">
<a href="" ng-click="showDownload(item);$event.stopPropagation()">
<!-- 下载 -->
{{'download'|translate}}
</a>
|
</span>

<span
ng-if="!item.isFolder && (item.storageClass=='Archive' && item.storageStatus!=3)"
ng-if="!item.isFolder && (['Archive','ColdArchive','DeepColdArchive'].includes(item.storageClass) && item.storageStatus!=3 && item.storageStatus!=2)"
>
<a href="" ng-click="showRestore(item);$event.stopPropagation()">
<!-- 恢复 -->
<a href="" ng-click="showSelrestores([item]);$event.stopPropagation()">
<!-- 解冻 -->
{{'restore'|translate}}
</a>
|
</span>

<span
ng-if="!item.isFolder && (['Archive','ColdArchive','DeepColdArchive'].includes(item.storageClass) && item.storageStatus==2)"
>
<a href="" ng-click="$event.stopPropagation()">
<!-- 解冻中 -->
{{'restoring'|translate}}
</a>
|
</span>
<a href="" ng-click="showDeleteFiles([item])" class="text-danger">
<!-- 删除 -->
{{'delete'|translate}}
Expand Down
Loading