mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 05:14:25 +00:00
Merge pull request #176 from shumaiOne/fix/upload-mime-type
fix(upload): resolve empty and generic MIME types in confirmFileUpload
This commit is contained in:
@@ -262,6 +262,72 @@ describe('UploadService', () => {
|
|||||||
expect(workflowTask).toBeNull()
|
expect(workflowTask).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should confirm file upload and resolve empty mediaType using Bun resolver for audio', async () => {
|
||||||
|
const task = await prisma.task.create({
|
||||||
|
data: { creatorId: userId, total: 1, uploaded: 0, type: 'upload' },
|
||||||
|
})
|
||||||
|
const asset = await prisma.asset.create({
|
||||||
|
data: {
|
||||||
|
name: 'audio.mp3',
|
||||||
|
type: AssetType.file,
|
||||||
|
project: { connect: { id: projectId } },
|
||||||
|
parent: { connect: { id: parentId } },
|
||||||
|
status: AssetStatus.uploading,
|
||||||
|
storageKey: {
|
||||||
|
connectOrCreate: {
|
||||||
|
where: { key: 'test-key-audio-empty' },
|
||||||
|
create: { key: 'test-key-audio-empty' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
mediaType: '',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await uploadService.confirmFileUpload(userId, task.id, { fileId: asset.id })
|
||||||
|
|
||||||
|
const updatedAsset = await prisma.asset.findUnique({ where: { id: asset.id } })
|
||||||
|
expect(updatedAsset?.mediaType).toBe('audio/mpeg')
|
||||||
|
expect(updatedAsset?.status).toBe(AssetStatus.uploaded)
|
||||||
|
|
||||||
|
const workflowTask = await prisma.workflowTask.findFirst({
|
||||||
|
where: { assetId: asset.id, type: WorkflowTaskType.transcode },
|
||||||
|
})
|
||||||
|
expect(workflowTask).toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should confirm file upload and resolve application/octet-stream mediaType using Bun resolver for audio', async () => {
|
||||||
|
const task = await prisma.task.create({
|
||||||
|
data: { creatorId: userId, total: 1, uploaded: 0, type: 'upload' },
|
||||||
|
})
|
||||||
|
const asset = await prisma.asset.create({
|
||||||
|
data: {
|
||||||
|
name: 'song.wav',
|
||||||
|
type: AssetType.file,
|
||||||
|
project: { connect: { id: projectId } },
|
||||||
|
parent: { connect: { id: parentId } },
|
||||||
|
status: AssetStatus.uploading,
|
||||||
|
storageKey: {
|
||||||
|
connectOrCreate: {
|
||||||
|
where: { key: 'test-key-audio-octet' },
|
||||||
|
create: { key: 'test-key-audio-octet' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
mediaType: 'application/octet-stream',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await uploadService.confirmFileUpload(userId, task.id, { fileId: asset.id })
|
||||||
|
|
||||||
|
const updatedAsset = await prisma.asset.findUnique({ where: { id: asset.id } })
|
||||||
|
expect(updatedAsset?.mediaType).toBe('audio/x-wav')
|
||||||
|
expect(updatedAsset?.status).toBe(AssetStatus.uploaded)
|
||||||
|
|
||||||
|
const workflowTask = await prisma.workflowTask.findFirst({
|
||||||
|
where: { assetId: asset.id, type: WorkflowTaskType.transcode },
|
||||||
|
})
|
||||||
|
expect(workflowTask).toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
it('should create a version stack when parentId is a file', async () => {
|
it('should create a version stack when parentId is a file', async () => {
|
||||||
// Create an existing file
|
// Create an existing file
|
||||||
const fileA = await prisma.asset.create({
|
const fileA = await prisma.asset.create({
|
||||||
|
|||||||
@@ -230,12 +230,18 @@ export class UploadService {
|
|||||||
const project = asset.project
|
const project = asset.project
|
||||||
|
|
||||||
await this.prismaClient.$transaction(async (tx) => {
|
await this.prismaClient.$transaction(async (tx) => {
|
||||||
|
let resolvedMediaType = asset.mediaType
|
||||||
|
if (!resolvedMediaType || resolvedMediaType === 'application/octet-stream') {
|
||||||
|
resolvedMediaType = Bun.file(asset.name).type || 'application/octet-stream'
|
||||||
|
}
|
||||||
|
|
||||||
// Update asset
|
// Update asset
|
||||||
const updatedAsset = await tx.asset.update({
|
const updatedAsset = await tx.asset.update({
|
||||||
where: { id: asset.id },
|
where: { id: asset.id },
|
||||||
data: {
|
data: {
|
||||||
status: AssetStatus.uploaded,
|
status: AssetStatus.uploaded,
|
||||||
sizeByte: size,
|
sizeByte: size,
|
||||||
|
mediaType: resolvedMediaType,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user