feat: add durable asset synchronization worker

This commit is contained in:
jb
2026-09-19 22:15:23 -04:00
parent 2675ea8114
commit fe7d218195
36 changed files with 2218 additions and 189 deletions
+8 -3
View File
@@ -4,6 +4,8 @@ import { session, synchronize } from '$lib/server/application';
import { protectMutation } from '$lib/server/http';
import { capabilityDisabledReason, capabilityEnabled } from '$lib/server/release-gate';
import { configuration } from '$lib/server/config';
import { hashSecret } from '$lib/server/security';
import { SESSION_COOKIE } from '$lib/server/application';
export const POST: RequestHandler = async (event) => {
const config = configuration();
// Bound origin/session work by the existing anonymous IP bucket first. The
@@ -16,8 +18,11 @@ export const POST: RequestHandler = async (event) => {
if (current) protectMutation(event, `sync:${current.userId}`, 6);
if (!current) return json({ error: 'Connect an EVE character first.' }, { status: 401 });
try {
const result = await synchronize(current.userId);
if (result.failed.length) return json({ ...result, error: `${result.failed.length} character(s) could not synchronize. Previous complete snapshots were preserved; check Characters.` }, { status: 503 });
return json(result);
const cookie = event.cookies.get(SESSION_COOKIE);
if (!cookie) return json({ error: 'Connect an EVE character first.' }, { status: 401 });
const result = await synchronize(current.userId, hashSecret(cookie));
const failures = result.skipped.filter((entry) => entry.reason !== 'authorization_required');
const status = result.queued > 0 ? 202 : failures.some((entry) => entry.reason === 'queue_full') ? 429 : failures.length > 0 ? 503 : 200;
return json(result, { status });
} catch { return json({ error: 'Synchronization unavailable. Check backend configuration and try again.' }, { status: 503 }); }
};