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

View file

@ -34,15 +34,22 @@ const handler = async (data: InputType): Promise<ReturnType> => {
const { title, image } = data;
const [imageId, imageThumbUrl, imageFullUrl, imageLinkHTML, imageUserName] =
image.split('|');
const [
imageId,
imageThumbUrl,
imageFullUrl,
imageLinkHTML,
imageUserName,
imageDownloadUrl,
] = image.split('|');
if (
!imageId ||
!imageThumbUrl ||
!imageFullUrl ||
!imageUserName ||
!imageLinkHTML
!imageLinkHTML ||
!imageDownloadUrl
) {
return {
error: 'Missing fields. Failed to create board.',
@ -52,6 +59,13 @@ const handler = async (data: InputType): Promise<ReturnType> => {
let board;
try {
await fetch(imageDownloadUrl, {
method: 'GET',
headers: {
Authorization: `Client-ID ${process.env.UNSPLASH_ACCESS_KEY}`,
},
});
board = await db.board.create({
data: {
title,