Files
classroomio/apps/dashboard/src/lib/features/ui/upload-widget/utils.ts
T

23 lines
559 B
TypeScript
Raw Normal View History

2026-03-09 11:18:22 +01:00
import { classroomio } from '$lib/utils/services/api';
2023-10-05 09:22:39 +00:00
export async function queryUnsplash(searchQuery: string) {
try {
2026-03-09 11:18:22 +01:00
const response = await classroomio.unsplash.$post({
json: { searchQuery }
2023-10-05 09:22:39 +00:00
});
2026-03-09 11:18:22 +01:00
2023-10-05 09:22:39 +00:00
const result = await response.json();
2026-03-09 11:18:22 +01:00
if (result.success && result.photos) {
return result.photos;
}
const error = 'error' in result ? result.error : 'Failed to fetch photos from Unsplash';
throw new Error(error);
2023-10-05 09:22:39 +00:00
} catch (error) {
console.error('Error sending fetch request', error);
2026-03-09 11:18:22 +01:00
throw error;
2023-10-05 09:22:39 +00:00
}
2023-11-25 21:56:02 +00:00
}