同步功能更新
This commit is contained in:
1 parent
21f0dc2830
commit
1d2d16e710
11 files changed
+268
-2
No files matched your search
@@ -12,6 +12,8 @@ interface SiteSyncBody {
|
||||
token?: string
|
||||
conflictMode?: 'skip' | 'overwrite'
|
||||
direction?: 'push' | 'pull'
|
||||
scope?: 'all' | 'image' | 'video' | 'file'
|
||||
keys?: string[]
|
||||
resumeJobId?: string
|
||||
abandonJobId?: string
|
||||
}
|
||||
@@ -49,7 +51,13 @@ export default defineEventHandler(async (event) => {
|
||||
job = startSiteSyncJob({
|
||||
targetBaseUrl: targetUrl.toString(),
|
||||
conflictMode,
|
||||
direction
|
||||
direction,
|
||||
scope: body?.scope === 'image' || body?.scope === 'video' || body?.scope === 'file'
|
||||
? body.scope
|
||||
: 'all',
|
||||
...(Array.isArray(body?.keys) && body.keys.length
|
||||
? { keys: body.keys.filter(key => typeof key === 'string') }
|
||||
: {})
|
||||
}, token, user.id)
|
||||
}
|
||||
return { job: serializeBackupJob(job) }
|
||||
|
||||
@@ -58,8 +58,14 @@ export interface SiteSyncOptions {
|
||||
targetBaseUrl: string
|
||||
conflictMode: 'skip' | 'overwrite'
|
||||
direction: SiteSyncDirection
|
||||
/** 同步内容:全站或某一类媒体 */
|
||||
scope?: SiteSyncScope
|
||||
/** 指定资源(与 scope 互斥,限定同一类型) */
|
||||
keys?: string[]
|
||||
}
|
||||
|
||||
export type SiteSyncScope = 'all' | 'image' | 'video' | 'file'
|
||||
|
||||
const tokens = (globalThis as typeof globalThis & {
|
||||
__pichostSiteSyncTokens?: Map<string, string>
|
||||
}).__pichostSiteSyncTokens ?? new Map<string, string>()
|
||||
@@ -948,7 +954,13 @@ export async function runSiteSyncJob(
|
||||
const targetUsers = new Set(inventory.users)
|
||||
const targetMedia = new Set(inventory.mediaKeys)
|
||||
const targetObjects = new Map(inventory.objects.map(item => [item.key, item.size]))
|
||||
const rows = listAllImageIndexRows()
|
||||
const allRows = listAllImageIndexRows()
|
||||
const wantedKeys = new Set(options.keys ?? [])
|
||||
const rows = allRows.filter((row) => {
|
||||
if (wantedKeys.size) return wantedKeys.has(row.key)
|
||||
const scope = options.scope ?? 'all'
|
||||
return scope === 'all' || row.media_type === scope
|
||||
})
|
||||
const ownerMap = listUserIdUsernameMap()
|
||||
const job = getBackupJob(jobId)
|
||||
const checkpoint = job?.payload ?? {}
|
||||
|
||||
Reference in new issue
Block a user