Files
FileCodeBoxFronted2026/src/utils/local-share.ts
T

19 lines
1.1 KiB
TypeScript

const labels: Record<string, string> = { day: '按天', hour: '按小时', minute: '按分钟', count: '按取件次数(最长 1 天)', forever: '永久有效' }
export function expirationChoices(styles: string[]) {
return [...new Set(styles)].filter(style => Object.prototype.hasOwnProperty.call(labels, style)).map(value => ({ value, label: labels[value] }))
}
export function localBreadcrumbs(path: string) {
const parts = path ? path.split('/') : []
return [{ name: '本地文件', path: '' }, ...parts.map((name, index) => ({ name, path: parts.slice(0, index + 1).join('/') }))]
}
export function buildLocalShareRequest(filename: string, style: string, value: string, allowed: string[]) {
if (!filename) throw new Error('请先选择文件')
if (!allowed.includes(style) || !Object.prototype.hasOwnProperty.call(labels, style)) throw new Error('请选择允许的有效期方式')
const amount = style === 'forever' ? 1 : Number(value)
if (!Number.isSafeInteger(amount) || amount < 1 || amount > 1_000_000) throw new Error('请输入 1 到 1000000 的整数')
return { filename, expire_style: style, expire_value: amount }
}