Skip to content

Commit

Permalink
chore: type for file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Aug 11, 2023
1 parent 51b57bb commit 8256020
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/routes/api/files.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type APIEvent, json } from "solid-start"
import { supabase, getUserProfile } from "@/supabase/server";
import type { UserProfile } from "@/types/api";
import type { UploadedFile, UserProfile } from "@/types/api";

export const GET = async ({ request }: APIEvent): Promise<Response> => {
let api_token = request.headers.get("authorization");
Expand Down Expand Up @@ -62,7 +62,7 @@ export const PUT = async ({ request }: APIEvent): Promise<Response> => {
const isPrivate = parseInt((formData.get("private") as string | null) ?? "1");

// TODO: type this shit.
const newUploadsInDatabase: any[] = [];
const newUploadsInDatabase: UploadedFile[] = [];

for (const file of formDataFiles) {
const file_extension = file.name.substring(file.name.lastIndexOf(".") + 1);
Expand All @@ -79,12 +79,12 @@ export const PUT = async ({ request }: APIEvent): Promise<Response> => {
})
.select();

const upload_id = data![0].id;
newUploadsInDatabase.push(data![0]);
const upload = (data as [UploadedFile])[0];
newUploadsInDatabase.push(upload);

await supabase.storage
.from('uploads')
.upload(`${user_profile?.user_id ?? "anon"}/${upload_id}.${file_extension}`, file, {
.upload(`${user_profile?.user_id ?? "anon"}/${upload.id}.${file_extension}`, file, {
cacheControl: '3600',
upsert: true
});
Expand Down

0 comments on commit 8256020

Please sign in to comment.