Skip to content
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

feat(web): delete folder in storage (#1047) #1048

Merged
merged 1 commit into from
Apr 19, 2023
Merged
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
1 change: 1 addition & 0 deletions web/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
"All": "Total Capacity",
"DeleteConfirm": "The current operation will permanently delete the cloud storage",
"DeleteFileTip": "Are you sure you want to delete the file?",
"DeleteFolderTip": "Are you sure you want to delete the whole folder? Notice that it will be a bit slower when a large number of files exist.",
"Drag": "Drag and drop here or",
"EmptyText": "No Bucket data yet ,",
"File": "File",
Expand Down
1 change: 1 addition & 0 deletions web/public/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
"All": "总容量",
"DeleteConfirm": "当前操作将会永久删除云存储",
"DeleteFileTip": "确认要删除文件吗?",
"DeleteFolderTip": "确认要删除整个文件夹吗?请注意当有大量文件存在时会稍许有一点慢哦",
"Drag": "拖放到此处或者",
"EmptyText": "暂无 Bucket 数据,",
"File": "文件",
Expand Down
1 change: 1 addition & 0 deletions web/public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
"All": "总容量",
"DeleteConfirm": "当前操作将会永久删除云存储",
"DeleteFileTip": "确认要删除文件吗?",
"DeleteFolderTip": "确认要删除整个文件夹吗?请注意当有大量文件存在时会稍许有一点慢哦",
"Drag": "拖放到此处或者",
"EmptyText": "暂无 Bucket 数据,",
"File": "文件",
Expand Down
22 changes: 21 additions & 1 deletion web/src/hooks/useAwsS3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,27 @@ function useAwsS3() {
};

const deleteFile = async (bucket: string, key: string) => {
const res = await s3.deleteObject({ Bucket: bucket, Key: key }).promise();
const { Versions } = await s3
.listObjectVersions({
Bucket: bucket,
Prefix: key,
})
.promise();
const res = await s3
.deleteObjects({
Bucket: bucket,
Delete: {
Objects: Versions.map(({ Key, VersionId }: { Key: string; VersionId: string }) => ({
Key,
VersionId,
})),
Quiet: true,
},
})
.promise();
if (res?.Errors?.length === 0 && Versions.length >= 1000) {
await deleteFile(bucket, key);
}
return res;
};

Expand Down
15 changes: 14 additions & 1 deletion web/src/pages/app/storages/mods/FileList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,20 @@ export default function FileList() {
<DeleteIcon fontSize={14} />
</IconWrap>
</ConfirmButton>
) : null}
) : (
<ConfirmButton
onSuccessAction={async () => {
await deleteFile(bucketName!, file.Prefix as string);
query.refetch();
}}
headerText={String(t("Delete"))}
bodyText={t("StoragePanel.DeleteFolderTip")}
>
<IconWrap tooltip={String(t("Delete"))}>
<DeleteIcon fontSize={14} />
</IconWrap>
</ConfirmButton>
)}
</Td>
</Tr>
);
Expand Down