enzostvs's picture
enzostvs HF staff
replace share with a post reauest
7398577
raw
history blame
923 Bytes
import { json, type RequestEvent } from '@sveltejs/kit';
import { tokenIsAvailable } from '$lib/utils';
import prisma from '$lib/prisma';
/** @type {import('./$types').RequestHandler} */
export async function POST({ cookies, params } : RequestEvent) {
const id = params.id
const gallery = await prisma.gallery.findFirst({
where: {
id,
},
})
if (!gallery) {
return json({
error: "Image not found",
}, { status: 404 })
}
const token = cookies.get('hf_access_token')
if (!token) {
return json({
error: "You must be logged",
}, { status: 401 })
}
const is_token_available = await tokenIsAvailable(token)
if (!is_token_available) {
return json({
error: "Invalid token",
}, { status: 401 })
}
await prisma.gallery.update({
where: {
id,
},
data: {
isPublic: true,
}
})
return json({
success: true,
})
}