refactor(#89): Address PR comments

This commit is contained in:
Josh Creek
2026-01-24 17:18:57 +00:00
parent ab82f75dc6
commit 8141bd624b
6 changed files with 54 additions and 13 deletions
@@ -26,6 +26,9 @@ export const PUT = async (event: RequestEvent) => {
const patch: Record<string, unknown> = {};
if (body.folderId !== undefined) patch.folderId = body.folderId;
if (body.path !== undefined) patch.path = body.path;
if (Object.keys(patch).length === 0) {
return json({ error: 'No fields to update' }, { status: 400 });
}
const { data, error } = await event.locals.supabase
.from('pokedex_export_integrations')
@@ -31,7 +31,10 @@ export const GET = async (event: RequestEvent) => {
const env = getEnv();
const clientId = env.DROPBOX_OAUTH_CLIENT_ID;
if (!clientId) {
throw redirect(302, `/pokedex/${pokedexId}?export=dropbox-missing-client`);
const missingClientRedirect = pokedexId
? `/pokedex/${pokedexId}?export=dropbox-missing-client`
: '/pokedex?export=dropbox-missing-client';
throw redirect(302, missingClientRedirect);
}
const state = createOAuthState();
@@ -89,16 +89,21 @@ export const GET = async (event: RequestEvent) => {
const fileName = oauthState.fileName?.trim() ? oauthState.fileName : null;
const folderId = oauthState.folderId?.trim() ? oauthState.folderId : null;
await repo.upsert({
provider: 'google_drive',
enabled: true,
fileName,
folderId,
accessToken: tokenData.access_token,
refreshToken: tokenData.refresh_token ?? null,
accessTokenExpiresAt: expiresAt,
metadata: tokenData.scope ? { scope: tokenData.scope } : null
});
try {
await repo.upsert({
provider: 'google_drive',
enabled: true,
fileName,
folderId,
accessToken: tokenData.access_token,
refreshToken: tokenData.refresh_token ?? null,
accessTokenExpiresAt: expiresAt,
metadata: tokenData.scope ? { scope: tokenData.scope } : null
});
} catch (saveError) {
console.error('Google Drive integration save failed:', saveError);
throw redirect(302, `${returnTo}-error`);
}
throw redirect(302, `${returnTo}-connected`);
} catch (err) {
@@ -31,7 +31,10 @@ export const GET = async (event: RequestEvent) => {
const env = getEnv();
const clientId = env.GOOGLE_OAUTH_CLIENT_ID;
if (!clientId) {
throw redirect(302, `/pokedex/${pokedexId}?export=google-missing-client`);
const missingClientRedirect = pokedexId
? `/pokedex/${pokedexId}?export=google-missing-client`
: '/pokedex?export=google-missing-client';
throw redirect(302, missingClientRedirect);
}
const state = createOAuthState();