fix: Create bucket if not exists
This commit is contained in:
parent
6cf6d7e7e4
commit
25d32d07b2
@ -7,7 +7,9 @@
|
|||||||
async function submit(e: SubmitEvent) {
|
async function submit(e: SubmitEvent) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (files.length === 0) return;
|
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>
|
</script>
|
||||||
|
|
||||||
|
@ -48,9 +48,9 @@ class MinioClient {
|
|||||||
async uploadProfile(stream: Readable, mime: string) {
|
async uploadProfile(stream: Readable, mime: string) {
|
||||||
try {
|
try {
|
||||||
const bucket = 'profile-photos';
|
const bucket = 'profile-photos';
|
||||||
if (await !this.client.bucketExists(bucket)) {
|
if (!(await this.client.bucketExists(bucket))) {
|
||||||
await this.client.makeBucket(bucket, 'us-east-1');
|
console.log(`Creating bucket '${bucket}', as it is required but does not exist.`);
|
||||||
console.log('Bucket "' + bucket + '" created in "us-east-1".');
|
this.client.makeBucket(bucket);
|
||||||
}
|
}
|
||||||
|
|
||||||
const objectId = `${v4()}${this.getFileExtension(mime)}`;
|
const objectId = `${v4()}${this.getFileExtension(mime)}`;
|
||||||
|
@ -24,9 +24,9 @@ export const POST = async ({ request }) => {
|
|||||||
const buffer = await file.arrayBuffer();
|
const buffer = await file.arrayBuffer();
|
||||||
const stream = Readable.from(Buffer.from(buffer));
|
const stream = Readable.from(Buffer.from(buffer));
|
||||||
|
|
||||||
console.log('Uploading profile photo');
|
|
||||||
const uploadResponse = await fsClient?.uploadProfile(stream, file.type);
|
const uploadResponse = await fsClient?.uploadProfile(stream, file.type);
|
||||||
authdb.setUserImage(session.user.id, `/api/images/${uploadResponse?.objectId}`);
|
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);
|
return json(uploadResponse);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user