mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 09:20:21 -04:00
7f5865872a
## Context Enforce `noUnusedLocals` and `noUnusedParameters` in tsconfig.json + fix all related issues
46 lines
1.2 KiB
TypeScript
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
|
|
}
|