38 lines
1.3 KiB
TypeScript
Raw Normal View History

import { NextResponse } from "next/server";
import { createClient } from "@/utils/supabase/server";
import path from 'path';
export async function GET(request: Request) {
const supabase = createClient();
let { data: galleries, error } = await supabase
.from('galleries')
.select('*');
return NextResponse.json(galleries);
}
2024-06-02 23:14:30 -04:00
export async function POST(request: Request) {
const supabase = createClient();
2024-06-02 23:14:30 -04:00
const formData = await request.formData();
const files = formData.getAll('files');
2024-06-03 02:00:05 -04:00
const tags = JSON.parse(formData.getAll('tags').toString()) as string[];
2024-06-02 23:14:30 -04:00
const name = formData.get('name');
const nsfw = formData.get('nsfw');
const tier = formData.get('tier');
2024-06-03 02:00:05 -04:00
const thumbnail = formData.get('thumbnail');
2024-06-02 23:14:30 -04:00
for (let i = 0; i < files.length; i++) {
2024-06-02 23:14:30 -04:00
const file = files[i] as File; // Cast 'file' to 'File' type
supabase.storage.from('galleries').upload(`${name}/${file.name}`, file);
}
2024-06-03 02:00:05 -04:00
const { data: gallery, error } = await supabase.from('galleries').insert({ name, tags, nsfw, thumbnail_file:thumbnail, tier, column_number: 3 }).single();
2024-06-02 23:14:30 -04:00
2024-06-03 02:00:05 -04:00
let { data: galleries, error: galleriesError } = await supabase
2024-06-02 23:14:30 -04:00
.from('galleries')
.select('*');
return NextResponse.json({ success: true, galleries });
}
2024-06-02 23:14:30 -04:00