From 3075ff15e088c4d86977d44ab0d1f2342c66b275 Mon Sep 17 00:00:00 2001 From: vastsa Date: Wed, 16 Sep 2026 18:30:47 +0800 Subject: [PATCH] feat: add admin local share page for NAS files Browse data/local including subfolders and mint extract codes without re-uploading. --- src/composables/index.ts | 1 + src/composables/useLocalShare.ts | 162 +++++++++++++++++ src/constants/index.ts | 2 + src/i18n/locales/en-US.ts | 30 ++++ src/i18n/locales/zh-CN.ts | 30 ++++ src/layout/AdminLayout/AdminLayout.vue | 7 + src/router/index.ts | 9 + src/services/file.ts | 20 +++ src/types/file.ts | 23 +++ src/views/manage/LocalShareView.vue | 229 +++++++++++++++++++++++++ 10 files changed, 513 insertions(+) create mode 100644 src/composables/useLocalShare.ts create mode 100644 src/views/manage/LocalShareView.vue diff --git a/src/composables/index.ts b/src/composables/index.ts index c894854..93aa939 100644 --- a/src/composables/index.ts +++ b/src/composables/index.ts @@ -9,5 +9,6 @@ export { usePublicConfigBootstrap } from './usePublicConfigBootstrap' export { useRetrieveFlow } from './useRetrieveFlow' export { useRouteLoading } from './useRouteLoading' export { useSendFlow } from './useSendFlow' +export { useLocalShare } from './useLocalShare' export { useSystemConfig } from './useSystemConfig' export { useTheme } from './useTheme' diff --git a/src/composables/useLocalShare.ts b/src/composables/useLocalShare.ts new file mode 100644 index 0000000..bb8053c --- /dev/null +++ b/src/composables/useLocalShare.ts @@ -0,0 +1,162 @@ +import { computed, ref } from 'vue' +import { useI18n } from 'vue-i18n' +import { FileService } from '@/services' +import { useAlertStore } from '@/stores/alertStore' +import { useConfigStore } from '@/stores/configStore' +import type { LocalShareItem, LocalShareResult } from '@/types' +import { copyToClipboard } from '@/utils/clipboard' +import { getErrorMessage } from '@/utils/common' +import { buildRetrieveUrl } from '@/utils/share-url' + +export function useLocalShare() { + const { t } = useI18n() + const alertStore = useAlertStore() + const configStore = useConfigStore() + + const currentPath = ref('') + const items = ref([]) + const truncated = ref(false) + const isLoading = ref(false) + const isSharing = ref(false) + const deletingPath = ref('') + const showShareModal = ref(false) + const sharingItem = ref(null) + const shareResult = ref(null) + const expireStyle = ref('day') + const expireValue = ref(1) + + const expireOptions = computed(() => { + const styles = configStore.config.expire_style?.length + ? configStore.config.expire_style + : ['day', 'hour', 'minute', 'forever', 'count'] + return styles.map((value) => ({ + value, + label: t(`send.time.${value}`) + })) + }) + + const breadcrumbs = computed(() => { + if (!currentPath.value) return [] + const parts = currentPath.value.split('/').filter(Boolean) + return parts.map((name, index) => ({ + name, + path: parts.slice(0, index + 1).join('/') + })) + }) + + const shareModalTitle = computed(() => + shareResult.value ? t('admin.localShare.resultTitle') : t('admin.localShare.shareTitle') + ) + + const loadDirectory = async (path: string) => { + isLoading.value = true + try { + const response = await FileService.listLocalFiles(path) + if (response.code !== 200 || !response.detail) { + throw new Error(t('admin.localShare.loadFailed')) + } + currentPath.value = response.detail.path || '' + items.value = response.detail.items || [] + truncated.value = Boolean(response.detail.truncated) + } catch (error) { + alertStore.showAlert(getErrorMessage(error, t('admin.localShare.loadFailed')), 'error') + } finally { + isLoading.value = false + } + } + + const openShare = (item: LocalShareItem) => { + sharingItem.value = item + shareResult.value = null + expireStyle.value = expireOptions.value[0]?.value || 'day' + expireValue.value = 1 + showShareModal.value = true + } + + const closeShareModal = () => { + showShareModal.value = false + sharingItem.value = null + shareResult.value = null + } + + const confirmShare = async () => { + if (!sharingItem.value) return + isSharing.value = true + try { + const response = await FileService.shareLocalFile({ + filename: sharingItem.value.path, + expire_value: expireStyle.value === 'forever' ? 1 : Math.max(1, Number(expireValue.value) || 1), + expire_style: expireStyle.value + }) + if (response.code !== 200 || !response.detail?.code) { + throw new Error(t('admin.localShare.shareFailed')) + } + shareResult.value = response.detail + alertStore.showAlert( + t('admin.localShare.shareSuccess', { code: response.detail.code }), + 'success' + ) + } catch (error) { + alertStore.showAlert(getErrorMessage(error, t('admin.localShare.shareFailed')), 'error') + } finally { + isSharing.value = false + } + } + + const copyCode = async () => { + if (!shareResult.value) return + await copyToClipboard(shareResult.value.code, { + notify: (message, type) => alertStore.showAlert(message, type) + }) + } + + const copyLink = async () => { + if (!shareResult.value) return + await copyToClipboard(buildRetrieveUrl(shareResult.value.code), { + notify: (message, type) => alertStore.showAlert(message, type) + }) + } + + const removeFile = async (item: LocalShareItem) => { + if (!window.confirm(t('admin.localShare.deleteConfirm', { name: item.path }))) { + return + } + deletingPath.value = item.path + try { + const response = await FileService.deleteLocalFile(item.path) + if (response.code !== 200) { + throw new Error(t('admin.localShare.deleteFailed')) + } + alertStore.showAlert(t('admin.localShare.deleteSuccess'), 'success') + await loadDirectory(currentPath.value) + } catch (error) { + alertStore.showAlert(getErrorMessage(error, t('admin.localShare.deleteFailed')), 'error') + } finally { + deletingPath.value = '' + } + } + + return { + breadcrumbs, + currentPath, + deletingPath, + expireOptions, + expireStyle, + expireValue, + isLoading, + isSharing, + items, + shareModalTitle, + shareResult, + sharingItem, + showShareModal, + truncated, + closeShareModal, + confirmShare, + copyCode, + copyLink, + loadDirectory, + openShare, + removeFile + } +} diff --git a/src/constants/index.ts b/src/constants/index.ts index 5dc6351..967458d 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -70,6 +70,7 @@ export const ROUTES = { LOGIN: '/login', DASHBOARD: '/admin/dashboard', FILE_MANAGE: '/admin/files', + LOCAL_SHARE: '/admin/local', SETTINGS: '/admin/settings' } as const @@ -80,6 +81,7 @@ export const ROUTE_NAMES = { LOGIN: 'Login', DASHBOARD: 'Dashboard', FILE_MANAGE: 'FileManage', + LOCAL_SHARE: 'LocalShare', SETTINGS: 'Settings' } as const diff --git a/src/i18n/locales/en-US.ts b/src/i18n/locales/en-US.ts index b7dcbef..2c0facd 100644 --- a/src/i18n/locales/en-US.ts +++ b/src/i18n/locales/en-US.ts @@ -120,6 +120,36 @@ export default { fileManage: { title: 'File Management' }, + localShare: { + title: 'Local Share', + subtitle: 'Browse NAS files in data/local and mint extract codes without copying them into FileCodeBox storage.', + mountHint: 'Mount your NAS folder to /app/data/local. Example: -v /volume1/share:/app/data/local:ro', + refresh: 'Refresh', + root: 'Root', + empty: 'No files or folders in this directory', + truncated: 'Too many entries; showing the first {count}', + name: 'Name', + size: 'Size', + ctime: 'Time', + typeDir: 'Folder', + typeFile: 'File', + share: 'Create code', + delete: 'Delete', + deleteConfirm: 'Delete local file “{name}”? This removes the original file under data/local.', + shareTitle: 'Share local file', + shareHint: 'The original file stays on the NAS. Expiring or deleting the code will not delete it.', + expire: 'Expiration', + expireValue: 'Value', + resultTitle: 'Extract code created', + copyCode: 'Copy code', + copyLink: 'Copy retrieve link', + openFiles: 'Open share records', + loadFailed: 'Failed to load local directory', + shareFailed: 'Failed to create extract code', + shareSuccess: 'Created extract code {code}', + deleteSuccess: 'Local file deleted', + deleteFailed: 'Delete failed' + }, settings: { title: 'System Settings', basicSettings: 'General', diff --git a/src/i18n/locales/zh-CN.ts b/src/i18n/locales/zh-CN.ts index bbbdfc6..9cec3ba 100644 --- a/src/i18n/locales/zh-CN.ts +++ b/src/i18n/locales/zh-CN.ts @@ -120,6 +120,36 @@ export default { fileManage: { title: '文件管理' }, + localShare: { + title: '本地分享', + subtitle: '浏览 data/local 里的 NAS 文件,直接生成提取码,不会复制或占用快递柜存储。', + mountHint: '把 NAS 目录挂到容器的 /app/data/local 即可在此浏览。例如:-v /volume1/share:/app/data/local:ro', + refresh: '刷新', + root: '根目录', + empty: '当前目录没有可分享的文件或文件夹', + truncated: '条目过多,仅显示前 {count} 项', + name: '名称', + size: '大小', + ctime: '时间', + typeDir: '文件夹', + typeFile: '文件', + share: '生成提取码', + delete: '删除', + deleteConfirm: '确定删除本地文件“{name}”?这会删除 data/local 中的原文件。', + shareTitle: '分享本地文件', + shareHint: '分享后原文件仍留在 NAS 目录。提取码过期或删除不会删除原文件。', + expire: '有效期', + expireValue: '数值', + resultTitle: '提取码已生成', + copyCode: '复制提取码', + copyLink: '复制取件链接', + openFiles: '查看分享记录', + loadFailed: '本地目录加载失败', + shareFailed: '生成提取码失败', + shareSuccess: '已生成提取码 {code}', + deleteSuccess: '已删除本地文件', + deleteFailed: '删除失败' + }, settings: { title: '系统设置', basicSettings: '基本设置', diff --git a/src/layout/AdminLayout/AdminLayout.vue b/src/layout/AdminLayout/AdminLayout.vue index 85df4ee..be502a2 100644 --- a/src/layout/AdminLayout/AdminLayout.vue +++ b/src/layout/AdminLayout/AdminLayout.vue @@ -90,6 +90,7 @@ import { MenuIcon, XIcon, FolderIcon, + HardDriveIcon, CogIcon, LayoutDashboardIcon, LogOutIcon @@ -123,6 +124,12 @@ const menuItems: MenuItem[] = [ icon: FolderIcon, redirect: ROUTES.FILE_MANAGE }, + { + id: ROUTE_NAMES.LOCAL_SHARE, + name: t('admin.localShare.title'), + icon: HardDriveIcon, + redirect: ROUTES.LOCAL_SHARE + }, { id: ROUTE_NAMES.SETTINGS, name: t('admin.settings.title'), diff --git a/src/router/index.ts b/src/router/index.ts index e51a3bf..d6a4a98 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -59,6 +59,15 @@ const routes: RouteRecordRaw[] = [ title: 'files' } }, + { + path: 'local', + name: ROUTE_NAMES.LOCAL_SHARE, + component: () => import('@/views/manage/LocalShareView.vue'), + meta: { + ...adminPageMeta, + title: 'local' + } + }, { path: 'settings', name: ROUTE_NAMES.SETTINGS, diff --git a/src/services/file.ts b/src/services/file.ts index 8f13131..40f937d 100644 --- a/src/services/file.ts +++ b/src/services/file.ts @@ -24,6 +24,8 @@ import type { FileInfo, FileListResponse, FileUploadResponse, + LocalShareListResponse, + LocalShareResult, ShareMetadataResponse, ShareSelectResponse, TextSendResponse, @@ -269,4 +271,22 @@ export class FileService { } }) } + + static async listLocalFiles(path = ''): Promise> { + return api.get('/admin/local/lists', { params: { path } }) + } + + static async shareLocalFile(payload: { + filename: string + expire_value: number + expire_style: string + }): Promise> { + return api.post('/admin/local/share', payload) + } + + static async deleteLocalFile(filename: string): Promise> { + return api.delete('/admin/local/delete', { + data: { filename } + }) + } } diff --git a/src/types/file.ts b/src/types/file.ts index 5f129c8..955aee7 100644 --- a/src/types/file.ts +++ b/src/types/file.ts @@ -459,3 +459,26 @@ export interface ChunkUploadCompleteRequest { } export type ChunkUploadResponse = null + +export interface LocalShareItem { + file: string + name: string + path: string + type: 'file' | 'dir' + ctime: string | null + size: number | null +} + +export interface LocalShareListResponse { + path: string + parent: string + truncated: boolean + items: LocalShareItem[] +} + +export interface LocalShareResult { + code: string + name: string + path?: string + id?: number +} diff --git a/src/views/manage/LocalShareView.vue b/src/views/manage/LocalShareView.vue new file mode 100644 index 0000000..dabad0e --- /dev/null +++ b/src/views/manage/LocalShareView.vue @@ -0,0 +1,229 @@ + + +