From 31a082eea2ab967babdf526f1aa1c765ecf764a0 Mon Sep 17 00:00:00 2001 From: keven1024 Date: Sun, 1 Jun 2025 17:58:03 +0800 Subject: [PATCH] feat(front): refactor sharing logic by introducing useAppShare composable for file and text sharing --- front/components/Result/FileShareResult.vue | 130 ++++++++++---------- front/components/Result/ResultIndexView.vue | 61 ++++----- front/components/Result/TextShareResult.vue | 123 +++++++++--------- front/composables/useShare.ts | 72 +++++++++++ 4 files changed, 236 insertions(+), 150 deletions(-) create mode 100644 front/composables/useShare.ts diff --git a/front/components/Result/FileShareResult.vue b/front/components/Result/FileShareResult.vue index 93ffad7..dea020f 100644 --- a/front/components/Result/FileShareResult.vue +++ b/front/components/Result/FileShareResult.vue @@ -1,75 +1,79 @@ \ No newline at end of file + + diff --git a/front/components/Result/ResultIndexView.vue b/front/components/Result/ResultIndexView.vue index f941813..1e525f9 100644 --- a/front/components/Result/ResultIndexView.vue +++ b/front/components/Result/ResultIndexView.vue @@ -1,44 +1,45 @@ \ No newline at end of file +
+ + +
+ diff --git a/front/components/Result/TextShareResult.vue b/front/components/Result/TextShareResult.vue index d84cf04..4fc78ca 100644 --- a/front/components/Result/TextShareResult.vue +++ b/front/components/Result/TextShareResult.vue @@ -1,70 +1,79 @@ \ No newline at end of file +
+
+ diff --git a/front/composables/useShare.ts b/front/composables/useShare.ts new file mode 100644 index 0000000..15577ff --- /dev/null +++ b/front/composables/useShare.ts @@ -0,0 +1,72 @@ +const downloadFile = async (share_id: string) => { + const data = await $fetch<{ + code: number; + data: { + token?: string; + }; + }>(`/api/download`, { + method: "POST", + body: { + share_id, + }, + }); + const { token } = data?.data || {}; + if (!token) { + return; + } + (window as any)?.open(`/api/download?token=${token}`); +}; + +const createShare = async (data: any) => { + return await $fetch<{ + code: number; + data: { + id?: string; + }; + }>(`/api/share`, { + method: "POST", + body: data, + }); +}; + +const createFileShare = async (data: { + file_id: string; + config: { + download_nums: number; + expire_time: number; + has_pickup_code?: boolean; + has_password?: boolean; + pickup_code?: string; + password?: string; + notify_email?: string; + }; + file_name: string; +}) => { + const { file_id, config, file_name } = data || {}; + return await createShare({ + type: "file", + data: file_id, + config, + file_name, + }); +}; + +const createTextShare = async (data: { text: string; config: any }) => { + const { text, config } = data || {}; + return await createShare({ + type: "text", + data: text, + config, + }); +}; + +const useAppShare = () => { + return { + downloadFile, + createShare, + createFileShare, + createTextShare, + }; +}; + +export default useAppShare;