21 lines
710 B
TypeScript
21 lines
710 B
TypeScript
import { json } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types';
|
|
import { sheets } from '$lib/google/index.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 spreadsheets = await sheets.getRecentSpreadsheets(refreshToken, 20);
|
|
|
|
return json(spreadsheets);
|
|
} catch (error) {
|
|
console.error('Error fetching recent spreadsheets:', error);
|
|
return json({ error: 'Failed to fetch spreadsheets' }, { status: 500 });
|
|
}
|
|
};
|