Store artist and album artwork in S3
This commit is contained in:
1 parent
c2dcec2c31
commit
0d09198e57
6 files changed
+63
-19
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { readAdminForm, adminFormText, adminFormTexts, adminFormFile, safeFileExtension, splitIds } from "../../utils/admin-form"
|
||||
import { saveUploadFile } from "../../utils/upload-files"
|
||||
import { putObjects, tryDeleteObject } from "../../utils/object-storage"
|
||||
import { defineAuthenticatedEventHandler, requireAuthenticatedUser } from "../../utils/auth"
|
||||
import { Album } from "../../models/album"
|
||||
import mongoose from "mongoose"
|
||||
@@ -30,8 +30,14 @@ export default defineAuthenticatedEventHandler(async (event) => {
|
||||
}
|
||||
|
||||
const filePath = `album/${crypto.randomUUID()}.${safeFileExtension(file.name)}`
|
||||
await saveUploadFile(event, filePath, file.data)
|
||||
const album = await Album.create({ name, artists, file: filePath, genre })
|
||||
await putObjects(event, [{ key: filePath, body: file.data, contentType: file.type }])
|
||||
let album
|
||||
try {
|
||||
album = await Album.create({ name, artists, file: filePath, genre })
|
||||
} catch (error) {
|
||||
await tryDeleteObject(event, filePath)
|
||||
throw error
|
||||
}
|
||||
setResponseStatus(event, 201)
|
||||
return album
|
||||
})
|
||||
Reference in new issue
Block a user