feat: add admin local share page for NAS files

Browse data/local including subfolders and mint extract codes without re-uploading.
This commit is contained in:
vastsa committed 2026-09-16 18:30:47 +08:00
1 parent c32466a20a
commit 3075ff15e0
10 files changed
+513

No files matched your search

+1
View File
@@ -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'
+162
View File
@@ -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<LocalShareItem[]>([])
const truncated = ref(false)
const isLoading = ref(false)
const isSharing = ref(false)
const deletingPath = ref('')
const showShareModal = ref(false)
const sharingItem = ref<LocalShareItem | null>(null)
const shareResult = ref<LocalShareResult | null>(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
}
}
+2
View File
@@ -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
+30
View File
@@ -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',
+30
View File
@@ -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: '基本设置',
+7
View File
@@ -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'),
+9
View File
@@ -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,
+20
View File
@@ -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<ApiResponse<LocalShareListResponse>> {
return api.get('/admin/local/lists', { params: { path } })
}
static async shareLocalFile(payload: {
filename: string
expire_value: number
expire_style: string
}): Promise<ApiResponse<LocalShareResult>> {
return api.post('/admin/local/share', payload)
}
static async deleteLocalFile(filename: string): Promise<ApiResponse<string>> {
return api.delete('/admin/local/delete', {
data: { filename }
})
}
}
+23
View File
@@ -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
}
+229
View File
@@ -0,0 +1,229 @@
<template>
<div class="p-6">
<div class="mb-6 flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between">
<div>
<h2 class="text-2xl font-bold" :class="[primaryTextClass]">
{{ t('admin.localShare.title') }}
</h2>
<p class="mt-1 text-sm" :class="[mutedTextClass]">
{{ t('admin.localShare.subtitle') }}
</p>
</div>
<BaseButton variant="secondary" :loading="isLoading" @click="loadDirectory(currentPath)">
<template #icon>
<RefreshCwIcon class="mr-2 h-4 w-4" />
</template>
{{ t('admin.localShare.refresh') }}
</BaseButton>
</div>
<p class="mb-4 rounded-lg border px-4 py-3 text-sm" :class="[hintClass]">
{{ t('admin.localShare.mountHint') }}
</p>
<nav class="mb-4 flex flex-wrap items-center gap-1 text-sm" :class="[mutedTextClass]">
<button type="button" class="rounded-md px-2 py-1 hover:underline" @click="loadDirectory('')">
{{ t('admin.localShare.root') }}
</button>
<template v-for="crumb in breadcrumbs" :key="crumb.path">
<ChevronRightIcon class="h-4 w-4 shrink-0" />
<button
type="button"
class="rounded-md px-2 py-1 hover:underline"
@click="loadDirectory(crumb.path)"
>
{{ crumb.name }}
</button>
</template>
</nav>
<p
v-if="truncated"
class="mb-4 rounded-lg border px-4 py-2 text-sm"
:class="[warnClass]"
>
{{ t('admin.localShare.truncated', { count: 500 }) }}
</p>
<section class="overflow-hidden rounded-lg border" :class="[panelClass]">
<div v-if="isLoading" class="px-6 py-16 text-center text-sm" :class="[mutedTextClass]">
{{ t('common.loading') }}
</div>
<div
v-else-if="items.length === 0"
class="px-6 py-16 text-center text-sm"
:class="[mutedTextClass]"
>
{{ t('admin.localShare.empty') }}
</div>
<ul v-else class="divide-y" :class="[dividerClass]">
<li
v-for="item in items"
:key="item.path"
class="flex flex-col gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between"
>
<button
v-if="item.type === 'dir'"
type="button"
class="flex min-w-0 items-center gap-3 text-left"
@click="loadDirectory(item.path)"
>
<FolderIcon class="h-5 w-5 shrink-0" :class="[mutedTextClass]" />
<span>
<span class="block truncate text-sm font-medium" :class="[primaryTextClass]">
{{ item.name }}
</span>
<span class="mt-0.5 block text-xs" :class="[mutedTextClass]">
{{ t('admin.localShare.typeDir') }}
<template v-if="item.ctime"> · {{ item.ctime }}</template>
</span>
</span>
</button>
<div v-else class="flex min-w-0 items-center gap-3">
<FileIcon class="h-5 w-5 shrink-0" :class="[mutedTextClass]" />
<span class="min-w-0">
<span class="block truncate text-sm font-medium" :class="[primaryTextClass]">
{{ item.name }}
</span>
<span class="mt-0.5 block text-xs" :class="[mutedTextClass]">
{{ formatFileSize(item.size || 0) }}
<template v-if="item.ctime"> · {{ item.ctime }}</template>
</span>
</span>
</div>
<div v-if="item.type === 'file'" class="flex flex-wrap gap-2">
<BaseButton size="sm" @click="openShare(item)">
{{ t('admin.localShare.share') }}
</BaseButton>
<BaseButton size="sm" variant="danger" :loading="deletingPath === item.path" @click="removeFile(item)">
{{ t('admin.localShare.delete') }}
</BaseButton>
</div>
</li>
</ul>
</section>
<BaseModal :show="showShareModal" :title="shareModalTitle" @close="closeShareModal">
<div v-if="shareResult" class="space-y-4">
<p class="text-sm" :class="[mutedTextClass]">{{ t('admin.localShare.shareHint') }}</p>
<p class="break-all text-2xl font-semibold tracking-widest" :class="[primaryTextClass]">
{{ shareResult.code }}
</p>
<p class="text-sm" :class="[mutedTextClass]">{{ shareResult.name }}</p>
</div>
<div v-else class="space-y-4">
<p class="break-all text-sm font-medium" :class="[primaryTextClass]">
{{ sharingItem?.path }}
</p>
<p class="text-sm" :class="[mutedTextClass]">{{ t('admin.localShare.shareHint') }}</p>
<label class="block space-y-1">
<span class="text-xs font-medium" :class="[mutedTextClass]">
{{ t('admin.localShare.expire') }}
</span>
<select v-model="expireStyle" class="w-full rounded-lg border px-3 py-2 text-sm" :class="[fieldClass]">
<option v-for="option in expireOptions" :key="option.value" :value="option.value">
{{ option.label }}
</option>
</select>
</label>
<label v-if="expireStyle !== 'forever'" class="block space-y-1">
<span class="text-xs font-medium" :class="[mutedTextClass]">
{{ t('admin.localShare.expireValue') }}
</span>
<input
v-model.number="expireValue"
type="number"
min="1"
class="w-full rounded-lg border px-3 py-2 text-sm"
:class="[fieldClass]"
/>
</label>
</div>
<template #footer>
<template v-if="shareResult">
<BaseButton variant="secondary" @click="copyCode">
{{ t('admin.localShare.copyCode') }}
</BaseButton>
<BaseButton variant="secondary" @click="copyLink">
{{ t('admin.localShare.copyLink') }}
</BaseButton>
<BaseButton @click="goToFiles">{{ t('admin.localShare.openFiles') }}</BaseButton>
</template>
<template v-else>
<BaseButton variant="outline" @click="closeShareModal">{{ t('common.cancel') }}</BaseButton>
<BaseButton :loading="isSharing" @click="confirmShare">{{ t('admin.localShare.share') }}</BaseButton>
</template>
</template>
</BaseModal>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router'
import { ChevronRightIcon, FileIcon, FolderIcon, RefreshCwIcon } from 'lucide-vue-next'
import BaseButton from '@/components/common/BaseButton.vue'
import BaseModal from '@/components/common/BaseModal.vue'
import { ROUTES } from '@/constants'
import { useInjectedDarkMode, useLocalShare } from '@/composables'
import { formatFileSize } from '@/utils/common'
const { t } = useI18n()
const router = useRouter()
const isDarkMode = useInjectedDarkMode()
const {
breadcrumbs,
currentPath,
deletingPath,
expireOptions,
expireStyle,
expireValue,
isLoading,
isSharing,
items,
shareModalTitle,
shareResult,
sharingItem,
showShareModal,
truncated,
closeShareModal,
confirmShare,
copyCode,
copyLink,
loadDirectory,
openShare,
removeFile
} = useLocalShare()
const primaryTextClass = computed(() => (isDarkMode.value ? 'text-white' : 'text-zinc-950'))
const mutedTextClass = computed(() => (isDarkMode.value ? 'text-zinc-400' : 'text-zinc-500'))
const panelClass = computed(() =>
isDarkMode.value
? 'border-white/10 bg-white/[0.06] shadow-[0_22px_54px_-36px_rgba(255,255,255,0.22)] backdrop-blur-xl'
: 'border-white/80 bg-white/70 shadow-[0_22px_54px_-36px_rgba(24,24,27,0.28)] backdrop-blur-xl'
)
const fieldClass = computed(() =>
isDarkMode.value
? 'border-white/10 bg-zinc-950/45 text-white'
: 'border-zinc-200/80 bg-white/80 text-zinc-950'
)
const hintClass = computed(() =>
isDarkMode.value
? 'border-white/10 bg-white/[0.04] text-zinc-300'
: 'border-zinc-200/80 bg-white/80 text-zinc-600'
)
const warnClass = computed(() =>
isDarkMode.value ? 'border-amber-500/20 bg-amber-500/10 text-amber-200' : 'border-amber-100 bg-amber-50 text-amber-800'
)
const dividerClass = computed(() => (isDarkMode.value ? 'divide-white/10' : 'divide-zinc-200/80'))
const goToFiles = () => {
closeShareModal()
void router.push(ROUTES.FILE_MANAGE)
}
onMounted(() => {
void loadDirectory('')
})
</script>