Updated how Images are Handeled to Comply With Unsplash API Guidelines

This commit is contained in:
Ahmad 2024-02-17 19:21:19 -05:00
parent d99f17c9d1
commit 01bebf0d83
No known key found for this signature in database
GPG key ID: 8FD8A93530D182BF
3 changed files with 42 additions and 13 deletions

20
app/api/unsplash/route.ts Normal file
View file

@ -0,0 +1,20 @@
import { unsplash } from '@/lib/unsplash';
import { NextResponse } from 'next/server';
export async function GET() {
try {
const result = await unsplash.photos.getRandom({
collectionIds: ['317099'],
count: 9,
});
if (result?.response) {
const newImages = result.response as Array<Record<string, any>>;
return new NextResponse(JSON.stringify(newImages), { status: 200 });
} else {
return new NextResponse('Failed to get images', { status: 500 });
}
} catch (error) {
return new NextResponse(JSON.stringify(error), { status: 500 });
}
}