站点同步
This commit is contained in:
1 parent
a64be50b73
commit
9cb8552a99
28 files changed
+1683
-18
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import { requireSiteSyncAuth } from '../../utils/access'
|
||||
import { createApiError } from '../../utils/api-error'
|
||||
import { validateStorageKey } from '../../utils/image-key'
|
||||
import { applySiteSyncMedia } from '../../utils/site-sync/apply'
|
||||
import type { SiteSyncMediaTransfer } from '../../utils/site-sync/protocol'
|
||||
|
||||
interface Body {
|
||||
media?: SiteSyncMediaTransfer
|
||||
conflictMode?: 'skip' | 'overwrite'
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const admin = await requireSiteSyncAuth(event)
|
||||
const body = await readBody<Body>(event).catch(() => null)
|
||||
const media = body?.media
|
||||
if (!media || !validateStorageKey(media.key)) {
|
||||
createApiError(event, 'INVALID_REQUEST', '媒体同步参数无效', 400)
|
||||
}
|
||||
const conflictMode = body?.conflictMode === 'skip' ? 'skip' : 'overwrite'
|
||||
try {
|
||||
return await applySiteSyncMedia(media, conflictMode, admin.id)
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : '媒体同步失败'
|
||||
createApiError(event, 'INVALID_REQUEST', message, 400)
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user