The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Refactor uploadAttachment util to lib/upload
Joshen Limc37d88158238
diff --git a/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsx b/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsxindex cc0673a62c8..a0c92fed61b 100644--- a/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsx+++ b/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsx@@ -1,17 +1,15 @@+import { useState } from 'react'+import { useParams } from 'common'import Table from 'components/to-be-cleaned/Table'+import AlertError from 'components/ui/AlertError'+import ShimmeringLoader from 'components/ui/ShimmeringLoader'+import { OAuthAppCreateResponse } from 'data/oauth/oauth-app-create-mutation'import { OAuthApp, useOAuthAppsQuery } from 'data/oauth/oauth-apps-query'-import { useState } from 'react'-import { Alert, Button, IconClipboard, IconEdit, IconTrash, IconX, Input } from 'ui'-import PublishAppModal from './PublishAppModal'+import { Alert, Button, IconX, Input } from 'ui'import DeleteAppModal from './DeleteAppModal'-import ShimmeringLoader from 'components/ui/ShimmeringLoader'-import AlertError from 'components/ui/AlertError'-import { copyToClipboard } from 'lib/helpers'import OAuthAppRow from './OAuthAppRow'-import { OAuthAppCreateResponse } from 'data/oauth/oauth-app-create-mutation'--// [Joshen] Just FYI need to relook at the copy writing at the end+import PublishAppModal from './PublishAppModal'const OAuthApps = () => {const { slug } = useParams()diff --git a/studio/components/interfaces/Organization/OAuthApps/PublishAppModal.tsx b/studio/components/interfaces/Organization/OAuthApps/PublishAppModal.tsxindex 7b035b411f0..9031e3646f6 100644--- a/studio/components/interfaces/Organization/OAuthApps/PublishAppModal.tsx+++ b/studio/components/interfaces/Organization/OAuthApps/PublishAppModal.tsx@@ -11,7 +11,7 @@ import { OAuthApp } from 'data/oauth/oauth-apps-query'import { useStore } from 'hooks'import { isValidHttpUrl, uuidv4 } from 'lib/helpers'import { Badge, Button, Dropdown, Form, IconEdit, IconUpload, Input, Modal } from 'ui'-import { uploadAttachment } from './OAuthApps.utils'+import { uploadAttachment } from 'lib/upload'import AuthorizeRequesterDetails from './AuthorizeRequesterDetails'export interface PublishAppModalProps {@@ -102,7 +102,9 @@ const PublishAppModal = ({const { name, website } = valuesconst uploadedIconUrl =- iconFile !== undefined ? await uploadAttachment(slug, iconFile) : iconUrl+ iconFile !== undefined+ ? await uploadAttachment('oauth-app-icons', `${slug}/${uuidv4()}.png`, iconFile)+ : iconUrlif (selectedApp === undefined) {// Create applicationdiff --git a/studio/lib/upload.ts b/studio/lib/upload.tsnew file mode 100644index 00000000000..5f141374099--- /dev/null+++ b/studio/lib/upload.ts@@ -0,0 +1,45 @@+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+}