Files
plugin-s3/console/src/views/S3Unlink.vue
longjuan 77c8b21248 feat: only delete halo attachment records without deleting files in object storage (#97)
/kind feature
```release-note
提供解除 S3 关联功能(仅删除 Halo 附件记录,而不再对象存储中实际删除)
```
在附件库中选择使用本插件上传或关联的文件的更多插件,会出现 解除 S3 关联 按钮。
![image](https://github.com/halo-dev/plugin-s3/assets/28662535/6bfd109e-3be5-4fdc-afb0-bbf841dfc8e8)
对于其他附件,不会出现该按钮
![image](https://github.com/halo-dev/plugin-s3/assets/28662535/bc90166d-68c5-4599-b00a-5d2ddd868314)
本功能已支持权限管理。
2023-11-27 13:50:09 +00:00

38 lines
1.2 KiB
Vue

<script setup lang="ts">
import {deleteApisS3OsHaloRunV1Alpha1AttachmentsByName} from "@/controller";
import type {Attachment} from "@halo-dev/api-client";
import {Dialog, Toast, VDropdownDivider, VDropdownItem} from "@halo-dev/components";
import {useQueryClient} from "@tanstack/vue-query";
const props = defineProps<{
attachment: Attachment;
}>();
const queryClient = useQueryClient();
const handleUnlink = () => {
Dialog.warning({
title: "解除 S3 关联",
description: "解除关联后,附件中的记录将会被删除,而对象存储中的文件仍然保留,若需重新关联请使用“关联 S3 文件”功能。",
confirmType: "danger",
confirmText: "确定",
cancelText: "取消",
onConfirm: async () => {
try {
await deleteApisS3OsHaloRunV1Alpha1AttachmentsByName({name: props.attachment.metadata.name});
Toast.success("解除关联成功");
} catch (e) {
console.error("Failed to delete attachment", e);
} finally {
queryClient.invalidateQueries({queryKey: ["attachments"]});
}
},
});
}
</script>
<template>
<div>
<VDropdownDivider/>
<VDropdownItem type="danger" @click="handleUnlink">解除 S3 关联</VDropdownItem>
</div>
</template>