release: v1.3.0 — 整站备份恢复、跨后端同步与任务中心
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
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
This commit is contained in:
1 parent
b05d572221
commit
f17d79b236
72 files changed
+4312
-559
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import { requireAdminAuth } from '../../../../../utils/access'
|
||||
import { createApiError } from '../../../../../utils/api-error'
|
||||
import { serializeBackupJob } from '../../../../../utils/backup/api'
|
||||
import { getBackupJob } from '../../../../../utils/backup/jobs'
|
||||
import { cancelBackupJob } from '../../../../../utils/backup/runner'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await requireAdminAuth(event)
|
||||
const id = getRouterParam(event, 'id')
|
||||
if (!id) {
|
||||
createApiError(event, 'INVALID_REQUEST', '缺少任务 ID', 400)
|
||||
}
|
||||
|
||||
if (!cancelBackupJob(id)) {
|
||||
createApiError(event, 'INVALID_REQUEST', '只能取消进行中的任务', 400)
|
||||
}
|
||||
|
||||
const job = getBackupJob(id)
|
||||
return { job: job ? serializeBackupJob(job) : null }
|
||||
})
|
||||
@@ -0,0 +1,29 @@
|
||||
import { createReadStream } from 'node:fs'
|
||||
import { basename } from 'node:path'
|
||||
import { requireAdminAuth } from '../../../../../utils/access'
|
||||
import { createApiError } from '../../../../../utils/api-error'
|
||||
import { getBackupJob } from '../../../../../utils/backup/jobs'
|
||||
import { BACKUP_ARCHIVE_EXT } from '../../../../../utils/backup/paths'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await requireAdminAuth(event)
|
||||
const id = getRouterParam(event, 'id')
|
||||
if (!id) {
|
||||
createApiError(event, 'INVALID_REQUEST', '缺少任务 ID', 400)
|
||||
}
|
||||
|
||||
const job = getBackupJob(id)
|
||||
if (!job || job.type !== 'full_export' || job.status !== 'done' || !job.outputPath) {
|
||||
createApiError(event, 'INVALID_REQUEST', '可下载的备份不存在', 404)
|
||||
}
|
||||
|
||||
const filename = basename(job.outputPath)
|
||||
if (!filename.endsWith(BACKUP_ARCHIVE_EXT)) {
|
||||
createApiError(event, 'INVALID_REQUEST', '备份文件无效', 404)
|
||||
}
|
||||
|
||||
setResponseHeader(event, 'Content-Type', 'application/gzip')
|
||||
setResponseHeader(event, 'Content-Disposition', `attachment; filename="${filename}"`)
|
||||
|
||||
return sendStream(event, createReadStream(job.outputPath))
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
import { requireAdminAuth } from '../../../../../utils/access'
|
||||
import { createApiError } from '../../../../../utils/api-error'
|
||||
import { retryFailedBackendSync } from '../../../../../utils/backup/backend-sync'
|
||||
import { serializeBackupJob } from '../../../../../utils/backup/api'
|
||||
import { getBackupJob } from '../../../../../utils/backup/jobs'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await requireAdminAuth(event)
|
||||
const id = getRouterParam(event, 'id')
|
||||
if (!id) {
|
||||
createApiError(event, 'INVALID_REQUEST', '缺少任务 ID', 400)
|
||||
}
|
||||
|
||||
const job = getBackupJob(id)
|
||||
if (!job || job.type !== 'backend_sync') {
|
||||
createApiError(event, 'INVALID_REQUEST', '任务不存在', 404)
|
||||
}
|
||||
|
||||
try {
|
||||
await retryFailedBackendSync(id)
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : '重试失败'
|
||||
createApiError(event, 'INVALID_REQUEST', message, 400)
|
||||
}
|
||||
|
||||
const updated = getBackupJob(id)
|
||||
return { job: updated ? serializeBackupJob(updated) : null }
|
||||
})
|
||||
Reference in new issue
Block a user