feat(#89): Add backup functionality for google drive and dropbox

This commit is contained in:
Josh Creek
2026-01-24 13:32:10 +00:00
parent 3f5c14a8bc
commit ab82f75dc6
22 changed files with 1582 additions and 7 deletions
@@ -0,0 +1,38 @@
import { json } from '@sveltejs/kit';
import type { RequestEvent } from '@sveltejs/kit';
import PokedexExportIntegrationRepository from '$lib/repositories/PokedexExportIntegrationRepository';
import { requireAuth } from '$lib/utils/auth';
export const GET = async (event: RequestEvent) => {
try {
const userId = await requireAuth(event);
const { session } = await event.locals.safeGetSession();
if (session) {
await event.locals.supabase.auth.setSession(session);
}
const repo = new PokedexExportIntegrationRepository(event.locals.supabase, userId, null);
const integrations = await repo.listAll();
const safe = integrations.map((integration) => ({
id: integration._id,
provider: integration.provider,
enabled: integration.enabled,
fileName: integration.fileName,
folderId: integration.folderId,
path: integration.path,
metadata: integration.metadata,
lastExportedAt: integration.lastExportedAt,
lastError: integration.lastError
}));
return json(safe);
} catch (err) {
console.error(err);
if (err && typeof err === 'object' && 'status' in err) {
throw err;
}
return json({ error: 'Internal Server Error' }, { status: 500 });
}
};
@@ -0,0 +1,51 @@
import { json } from '@sveltejs/kit';
import type { RequestEvent } from '@sveltejs/kit';
import { requireAuth } from '$lib/utils/auth';
const ALLOWED_PROVIDERS = new Set(['google_drive', 'dropbox']);
export const PUT = async (event: RequestEvent) => {
try {
const userId = await requireAuth(event);
const { provider } = event.params;
if (!provider || !ALLOWED_PROVIDERS.has(provider)) {
return json({ error: 'Invalid provider' }, { status: 400 });
}
const { session } = await event.locals.safeGetSession();
if (session) {
await event.locals.supabase.auth.setSession(session);
}
const body = (await event.request.json()) as {
folderId?: string | null;
path?: string | null;
};
const patch: Record<string, unknown> = {};
if (body.folderId !== undefined) patch.folderId = body.folderId;
if (body.path !== undefined) patch.path = body.path;
const { data, error } = await event.locals.supabase
.from('pokedex_export_integrations')
.update(patch)
.eq('userId', userId)
.is('pokedexId', null)
.eq('provider', provider)
.select('id, provider, enabled, fileName, folderId, path, metadata, lastExportedAt, lastError')
.single();
if (error || !data) {
return json({ error: 'Integration not found' }, { status: 404 });
}
return json(data);
} catch (err) {
console.error(err);
if (err && typeof err === 'object' && 'status' in err) {
throw err;
}
return json({ error: 'Internal Server Error' }, { status: 500 });
}
};