fix: Create bucket if not exists

This commit is contained in:
April Hall 2025-02-22 15:25:43 -05:00
parent 6cf6d7e7e4
commit 25d32d07b2
No known key found for this signature in database
GPG Key ID: A49AC35CB186266C
3 changed files with 7 additions and 5 deletions

View File

@ -7,7 +7,9 @@
async function submit(e: SubmitEvent) {
e.preventDefault();
if (files.length === 0) return;
await generateStream(files[0]).then(() => window.location.reload());
await generateStream(files[0]).then((res) => {
if (res.ok) window.location.reload();
});
}
</script>

View File

@ -48,9 +48,9 @@ class MinioClient {
async uploadProfile(stream: Readable, mime: string) {
try {
const bucket = 'profile-photos';
if (await !this.client.bucketExists(bucket)) {
await this.client.makeBucket(bucket, 'us-east-1');
console.log('Bucket "' + bucket + '" created in "us-east-1".');
if (!(await this.client.bucketExists(bucket))) {
console.log(`Creating bucket '${bucket}', as it is required but does not exist.`);
this.client.makeBucket(bucket);
}
const objectId = `${v4()}${this.getFileExtension(mime)}`;

View File

@ -24,9 +24,9 @@ export const POST = async ({ request }) => {
const buffer = await file.arrayBuffer();
const stream = Readable.from(Buffer.from(buffer));
console.log('Uploading profile photo');
const uploadResponse = await fsClient?.uploadProfile(stream, file.type);
authdb.setUserImage(session.user.id, `/api/images/${uploadResponse?.objectId}`);
console.log(`\x1b[35m[S3]\x1b[0m Uploaded ${file.name} as ${uploadResponse?.objectId}`);
return json(uploadResponse);
} catch (e) {