Expose sync reset API
This commit is contained in:
@@ -8,6 +8,11 @@ import {
|
||||
SyncPushRequestError,
|
||||
syncPushDocument,
|
||||
} from "./sync_push.js";
|
||||
import {
|
||||
SyncResetPersistenceError,
|
||||
SyncResetRequestError,
|
||||
syncResetDocument,
|
||||
} from "./sync_reset.js";
|
||||
import {
|
||||
SyncSnapshotConflictError,
|
||||
SyncSnapshotNotFoundError,
|
||||
@@ -35,6 +40,9 @@ export async function handleSyncRoute(
|
||||
if (url.pathname === "/api/sync/status") {
|
||||
return handleSyncStatus(request, env);
|
||||
}
|
||||
if (url.pathname === "/api/sync/reset") {
|
||||
return handleSyncReset(request, env);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -180,3 +188,35 @@ function handleSyncStatus(request: Request, env: Env): Promise<Response> {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function handleSyncReset(request: Request, env: Env): Promise<Response> {
|
||||
return withApprovedDeviceApiControls(
|
||||
request,
|
||||
env,
|
||||
"sync.reset",
|
||||
["POST"],
|
||||
async (context) => {
|
||||
try {
|
||||
return jsonResponse(await syncResetDocument(request, env, context), 200, {
|
||||
"Cache-Control": "no-store",
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof SyncResetRequestError) {
|
||||
return jsonResponse(
|
||||
{ error: "invalid_sync_reset" },
|
||||
400,
|
||||
{ "Cache-Control": "no-store" },
|
||||
);
|
||||
}
|
||||
if (error instanceof SyncResetPersistenceError) {
|
||||
return jsonResponse(
|
||||
{ error: "sync_reset_failed" },
|
||||
500,
|
||||
{ "Cache-Control": "no-store" },
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user