Files
FileHost/server/api/admin/backup/estimate.get.ts
tianmo a64be50b73 feat: 完善媒体管理与备份迁移流程
- 视频上传生成缩略图并提供占位封面和失败原因展示
- 支持 HLS 按需重新封装 MP4,并限制临时文件生命周期与访问权限
- 完善视频、文件 API 文档、搜索、批量删除和单次转码质量参数
- 修复备份恢复与跨后端迁移遗漏缩略图、HLS 清单和分片的问题
- 将备份任务、归档和下载权限按用户隔离
- 增加仅清理当前用户数据的高危存储清空流程和二次文字确认
- 修复 S3 中文文件名元数据及 CLI 数据库连接问题
- 补充备份恢复、用户隔离、媒体资源和转码相关测试
2026-10-17 13:46:02 +08:00

53 lines
1.7 KiB
TypeScript

import { requireAdminAuth } from '../../../utils/access'
import { getBackupExportEstimate } from '../../../utils/backup/stats'
import { getBackupsDir, isSafeBackupFilename } from '../../../utils/backup/paths'
import { listAllBackupJobsForUser } from '../../../utils/backup/jobs'
import { basename, join } from 'node:path'
import { promises as fs } from 'node:fs'
export default defineEventHandler(async (event) => {
const user = await requireAdminAuth(event)
const estimate = await getBackupExportEstimate()
const allowedArchives = new Set(
listAllBackupJobsForUser(user.id).flatMap((job) => {
const names: string[] = []
if (job.outputPath) names.push(basename(job.outputPath))
if (typeof job.payload.archivePath === 'string') {
names.push(basename(job.payload.archivePath))
}
return names
})
)
const packages = await (async () => {
try {
await fs.mkdir(getBackupsDir(), { recursive: true })
const entries = await fs.readdir(getBackupsDir(), { withFileTypes: true })
const items = await Promise.all(
entries
.filter(entry => entry.isFile() && isSafeBackupFilename(entry.name))
.filter(entry => allowedArchives.has(entry.name))
.map(async (entry) => {
const full = join(getBackupsDir(), entry.name)
const fileStat = await fs.stat(full)
return {
name: entry.name,
bytes: fileStat.size,
modifiedAt: fileStat.mtime.toISOString()
}
})
)
items.sort((a, b) => b.modifiedAt.localeCompare(a.modifiedAt))
return items
} catch {
return []
}
})()
return {
estimate,
backupsDir: getBackupsDir(),
packages
}
})