Files
O96u f17d79b236
ci / ci (22, ubuntu-latest) (push) Canceled after 0s
GitHub Release / release (push) Canceled after 0s
Publish Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Canceled after 0s
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Canceled after 0s
Publish Docker image / merge (push) Canceled after 0s
release: v1.3.0 — 整站备份恢复、跨后端同步与任务中心
2026-09-07 17:05:12 +08:00

41 lines
1.2 KiB
TypeScript

import { requireAdminAuth } from '../../../utils/access'
import { getBackupExportEstimate } from '../../../utils/backup/stats'
import { getBackupsDir, isSafeBackupFilename } from '../../../utils/backup/paths'
import { promises as fs } from 'node:fs'
import { join } from 'node:path'
export default defineEventHandler(async (event) => {
await requireAdminAuth(event)
const estimate = await getBackupExportEstimate()
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))
.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
}
})