diff --git a/apps/portal/.env.local.example b/apps/portal/.env.local.example deleted file mode 100644 index 58d98e9b..00000000 --- a/apps/portal/.env.local.example +++ /dev/null @@ -1,3 +0,0 @@ -# Supabase -NEXT_PUBLIC_SUPABASE_URL= -NEXT_PUBLIC_SUPABASE_ANON_KEY= diff --git a/apps/portal/src/pages/api/file-storage.ts b/apps/portal/src/pages/api/file-storage.ts index 36750cfe..96e5d59a 100644 --- a/apps/portal/src/pages/api/file-storage.ts +++ b/apps/portal/src/pages/api/file-storage.ts @@ -1,4 +1,3 @@ -import axios from 'axios'; import formidable from 'formidable'; import * as fs from 'fs'; import type { NextApiRequest, NextApiResponse } from 'next'; @@ -6,8 +5,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { env } from '~/env/server.mjs'; import { supabase } from '~/utils/supabase'; -const BASE_URL = `${env.SUPABASE_URL}/storage/v1/object`; -const BASE_FILE_URL = `${BASE_URL}/public`; +const BASE_URL = `${env.SUPABASE_URL}/storage/v1/object/public`; export const config = { api: { @@ -35,10 +33,16 @@ export default async function handler( const filePath = `${Date.now()}-${parsedFile.originalFilename}`; const convertedFile = fs.readFileSync(parsedFile.filepath); - supabase.storage.from(key as string).upload(filePath, convertedFile); + const { error } = await supabase.storage + .from(key as string) + .upload(filePath, convertedFile); + + if (error) { + throw error; + } return res.status(200).json({ - url: `${BASE_FILE_URL}/${key}/${filePath}`, + url: `${BASE_URL}/${key}/${filePath}`, }); }); } catch (error: unknown) { @@ -46,9 +50,18 @@ export default async function handler( } } + // See if we need this if (req.method === 'GET') { const { key, filePath } = req.query; - const data = await axios.get(`${BASE_URL}/public/${key}/${filePath}`); - res.status(200).json(data); + + const { data, error } = await supabase.storage + .from(key as string) + .download(filePath as string); + + if (error) { + throw error; + } + + res.status(200).write(data); } } diff --git a/apps/portal/src/pages/resumes/submit.tsx b/apps/portal/src/pages/resumes/submit.tsx index dd22c7da..530e2414 100644 --- a/apps/portal/src/pages/resumes/submit.tsx +++ b/apps/portal/src/pages/resumes/submit.tsx @@ -58,13 +58,11 @@ export default function SubmitResumeForm() { formData.append('key', 'resumes'); formData.append('file', resumeFile); - // Prefix with uuid so that it is always unique const res = await axios.post('/api/file-storage', formData, { headers: { 'Content-Type': 'multipart/form-data', }, }); - const { url } = res.data; await resumeCreateMutation.mutate({ @@ -72,7 +70,6 @@ export default function SubmitResumeForm() { url, }); router.push('/resumes'); - reset(); }; const onUploadFile = (event: React.ChangeEvent) => {