API reformatting
This commit is contained in:
20
src/routes/private/api/google/sheets/recent/+server.ts
Normal file
20
src/routes/private/api/google/sheets/recent/+server.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { getRecentSpreadsheets } from '$lib/sheets.js';
|
||||
|
||||
export const GET: RequestHandler = async ({ request }) => {
|
||||
try {
|
||||
const authHeader = request.headers.get('authorization');
|
||||
if (!authHeader?.startsWith('Bearer ')) {
|
||||
return json({ error: 'Missing or invalid authorization header' }, { status: 401 });
|
||||
}
|
||||
|
||||
const refreshToken = authHeader.slice(7);
|
||||
const sheets = await getRecentSpreadsheets(refreshToken, 20);
|
||||
|
||||
return json(sheets);
|
||||
} catch (error) {
|
||||
console.error('Error fetching recent spreadsheets:', error);
|
||||
return json({ error: 'Failed to fetch spreadsheets' }, { status: 500 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user