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, adminFormFile, safeFileExtension } from "../../utils/admin-form"
|
||||
import { saveUploadFile } from "../../utils/upload-files"
|
||||
import { putObjects, tryDeleteObject } from "../../utils/object-storage"
|
||||
import { defineAuthenticatedEventHandler, requireAuthenticatedUser } from "../../utils/auth"
|
||||
import { Artist } from "../../models/artist"
|
||||
|
||||
@@ -18,8 +18,14 @@ export default defineAuthenticatedEventHandler(async (event) => {
|
||||
}
|
||||
|
||||
const filePath = `artists/${crypto.randomUUID()}.${safeFileExtension(file.name)}`
|
||||
await saveUploadFile(event, filePath, file.data)
|
||||
const artist = await Artist.create({ name, file: filePath })
|
||||
await putObjects(event, [{ key: filePath, body: file.data, contentType: file.type }])
|
||||
let artist
|
||||
try {
|
||||
artist = await Artist.create({ name, file: filePath })
|
||||
} catch (error) {
|
||||
await tryDeleteObject(event, filePath)
|
||||
throw error
|
||||
}
|
||||
setResponseStatus(event, 201)
|
||||
return artist
|
||||
})
|
||||
Reference in new issue
Block a user