-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/devsoc-unsw/trainee-fool-24t3
- Loading branch information
Showing
31 changed files
with
944 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
backend/prisma/migrations/20241213143101_20241213074516/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[text]` on the table `Keyword` will be added. If there are existing duplicate values, this will fail. | ||
*/ | ||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Keyword_text_key" ON "Keyword"("text"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { StorageClient } from '@supabase/storage-js'; | ||
import { decode } from 'base64-arraybuffer'; | ||
|
||
const STORAGE_URL = process.env['STORAGE_URL']; | ||
const SERVICE_KEY = process.env['SERVICE_ROLE']; | ||
|
||
if (process.env['NODE_ENV'] !== 'test' && !STORAGE_URL) { | ||
throw new Error('Storage URL not found.'); | ||
} | ||
if (process.env['NODE_ENV'] !== 'test' && !SERVICE_KEY) { | ||
throw new Error('Service key not found.'); | ||
} | ||
|
||
export let storageClient: StorageClient | null = null; | ||
if (STORAGE_URL && SERVICE_KEY) { | ||
storageClient = new StorageClient(STORAGE_URL, { | ||
apikey: SERVICE_KEY, | ||
Authorization: `Bearer ${SERVICE_KEY}`, | ||
}); | ||
} | ||
|
||
export const uploadFile = async ( | ||
file: string, | ||
fileType: string, | ||
societyId: number, | ||
eventName: string | ||
) => { | ||
if (!storageClient) { | ||
throw new Error('Storage client not initialised.'); | ||
} | ||
const { data, error } = await storageClient | ||
.from('images') | ||
.upload( | ||
`${societyId}/${eventName}/banner.${fileType.split('/')[1]}`, | ||
decode(file), | ||
{ | ||
contentType: fileType, | ||
upsert: true, | ||
} | ||
); | ||
if (error) { | ||
throw new Error(error.message); | ||
} | ||
console.log(data); | ||
return data.path; | ||
}; | ||
|
||
export const getFile = async (path: string) => { | ||
if (!storageClient) { | ||
throw new Error('Storage client not initialised.'); | ||
} | ||
const { data, error } = await storageClient.from('images').download(path); | ||
if (error) { | ||
throw new Error(error.message); | ||
} | ||
|
||
return data; | ||
}; | ||
|
||
export const getFileUrl = async (path: string) => { | ||
if (!storageClient) { | ||
throw new Error('Storage client not initialised.'); | ||
} | ||
|
||
const { data } = await storageClient.from('images').getPublicUrl(path); | ||
|
||
return data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.