Added search to sheets
This commit is contained in:
30
src/routes/private/api/google/sheets/search/+server.ts
Normal file
30
src/routes/private/api/google/sheets/search/+server.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { error, json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { googleSheetsServer } from '$lib/google/sheets/server.js';
|
||||
|
||||
export const GET: RequestHandler = async ({ url, request }) => {
|
||||
try {
|
||||
// Get search query from URL
|
||||
const query = url.searchParams.get('query');
|
||||
|
||||
if (!query) {
|
||||
throw error(400, 'Search query is required');
|
||||
}
|
||||
|
||||
// Get authorization token from request headers
|
||||
const authHeader = request.headers.get('Authorization');
|
||||
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
||||
throw error(401, 'Missing or invalid Authorization header');
|
||||
}
|
||||
const refreshToken = authHeader.substring(7); // Remove "Bearer " prefix
|
||||
|
||||
// Search for sheets using the query
|
||||
const sheets = await googleSheetsServer.searchSheets(refreshToken, query);
|
||||
|
||||
// Return the search results
|
||||
return json(sheets);
|
||||
} catch (err) {
|
||||
console.error('Error searching Google Sheets:', err);
|
||||
throw error(500, 'Failed to search Google Sheets');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user