Files
supabase/apps/studio/lib/upload.ts
Joshen Lim 7f5865872a Enforce noUnusedLocals and noUnusedParameters in tsconfig.json + fix all related issues (#45264)
## Context

Enforce `noUnusedLocals` and `noUnusedParameters` in tsconfig.json + fix
all related issues
2026-04-27 17:42:34 +08:00

46 lines
1.2 KiB
TypeScript

import { createClient } from '@supabase/supabase-js'
const SUPPORT_API_URL = process.env.NEXT_PUBLIC_SUPPORT_API_URL || ''
const SUPPORT_API_KEY = process.env.NEXT_PUBLIC_SUPPORT_ANON_KEY || ''
// [Joshen TODO] Feedback form and support attachments should use this
export const uploadAttachment = async (
bucket: string,
fileName: string,
image: File,
getUrl: boolean = true
) => {
const supabaseClient = createClient(SUPPORT_API_URL, SUPPORT_API_KEY, {
auth: {
persistSession: false,
autoRefreshToken: false,
// @ts-ignore
multiTab: false,
detectSessionInUrl: false,
localStorage: {
getItem: (_key: string) => undefined,
setItem: (_key: string, _value: string) => {},
removeItem: (_key: string) => {},
},
},
})
const options = { cacheControl: '3600' }
const { data: file, error } = await supabaseClient.storage
.from(bucket)
.upload(fileName, image, options)
if (error) {
console.error('Failed to upload:', error)
return undefined
}
if (file && getUrl) {
const { data } = await supabaseClient.storage.from(bucket).getPublicUrl(file.path)
return data?.publicUrl
}
return undefined
}