From f9e37cb43942b7a605dc9aff4cbb0c9f674d7d88 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 11 Mar 2024 15:45:31 +0800 Subject: [PATCH] feat: add download feature for attachment Signed-off-by: Ryan Wang --- .../components/AttachmentListItem.vue | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ui/console-src/modules/contents/attachments/components/AttachmentListItem.vue b/ui/console-src/modules/contents/attachments/components/AttachmentListItem.vue index 9542716929..4dcb1ad41d 100644 --- a/ui/console-src/modules/contents/attachments/components/AttachmentListItem.vue +++ b/ui/console-src/modules/contents/attachments/components/AttachmentListItem.vue @@ -7,6 +7,7 @@ import { Toast, VDropdownItem, Dialog, + VDropdownDivider, } from "@halo-dev/components"; import { computed, ref } from "vue"; import type { Attachment } from "@halo-dev/api-client"; @@ -101,6 +102,29 @@ const { operationItems } = useOperationItemExtensionPoint( { priority: 20, component: markRaw(VDropdownItem), + label: t("core.common.buttons.download"), + action: () => { + const { permalink } = attachment.value.status || {}; + + if (!permalink) { + throw new Error("Attachment has no permalink"); + } + + const a = document.createElement("a"); + a.href = permalink; + a.download = attachment.value.spec.displayName || "unknown"; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + }, + }, + { + priority: 30, + component: markRaw(VDropdownDivider), + }, + { + priority: 40, + component: markRaw(VDropdownItem), props: { type: "danger", },