mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 11:24:43 +00:00
fix(webui,core): center breadcrumb menu on chevron and fix proxy download filename (#417)
This commit is contained in:
@@ -3116,7 +3116,53 @@ describe('AssetService — natural sort by name', () => {
|
||||
'files/01TESTULID000000000000000/test-720p.mp4',
|
||||
'GET',
|
||||
true,
|
||||
'test.mp4',
|
||||
'test-720p.mp4',
|
||||
)
|
||||
})
|
||||
|
||||
it('downloading video proxy for test.mov should use proxy filename with mp4 extension instead of test.mov', async () => {
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'test.mov',
|
||||
type: AssetType.file,
|
||||
status: AssetStatus.uploaded,
|
||||
storageKey: {
|
||||
create: { key: 'files/01TESTULID000000000000000/test.mov' },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await assetService.getDownloadUrl(asset.id, 'files/01TESTULID000000000000000/test-1080p.mp4')
|
||||
|
||||
expect(s3Service.presign).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
'files/01TESTULID000000000000000/test-1080p.mp4',
|
||||
'GET',
|
||||
true,
|
||||
'test-1080p.mp4',
|
||||
)
|
||||
})
|
||||
|
||||
it('downloading proxy for a renamed asset should preserve new stem with proxy resolution and extension', async () => {
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'awesome.mov',
|
||||
type: AssetType.file,
|
||||
status: AssetStatus.uploaded,
|
||||
storageKey: {
|
||||
create: { key: 'files/01TESTULID000000000000000/test.mov' },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await assetService.getDownloadUrl(asset.id, 'files/01TESTULID000000000000000/test-1080p.mp4')
|
||||
|
||||
expect(s3Service.presign).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
'files/01TESTULID000000000000000/test-1080p.mp4',
|
||||
'GET',
|
||||
true,
|
||||
'awesome-1080p.mp4',
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -46,6 +46,8 @@ import { getAgentRequiredLevel, getRoleLevel } from '@shumai/core/src/agent/perm
|
||||
import { resolveEffectiveRole } from '@shumai/core/src/authz/authz'
|
||||
import { metadataService } from '@shumai/core/src/metadata/metadata'
|
||||
import { uploadService } from '@shumai/core/src/upload/upload'
|
||||
import path from 'path'
|
||||
import { stemFromKey } from '@shumai/core/src/utils/filename'
|
||||
|
||||
export const assetInclude = {
|
||||
creator: true,
|
||||
@@ -2594,6 +2596,7 @@ export class AssetService {
|
||||
|
||||
let storageKey = asset.storageKey.key
|
||||
let assetDir = storageKey.substring(0, storageKey.lastIndexOf('/') + 1)
|
||||
let targetName = asset.name
|
||||
|
||||
if (!key.startsWith(assetDir) && asset.parentId) {
|
||||
// Check if requested key belongs to another version in the same version stack
|
||||
@@ -2603,11 +2606,14 @@ export class AssetService {
|
||||
isDeleted: false,
|
||||
storageKey: { key: { startsWith: key.substring(0, key.lastIndexOf('/') + 1) } },
|
||||
},
|
||||
select: { storageKey: { select: { key: true } } },
|
||||
select: { name: true, storageKey: { select: { key: true } } },
|
||||
})
|
||||
if (sibling?.storageKey?.key) {
|
||||
storageKey = sibling.storageKey.key
|
||||
assetDir = storageKey.substring(0, storageKey.lastIndexOf('/') + 1)
|
||||
if (sibling.name) {
|
||||
targetName = sibling.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2615,13 +2621,35 @@ export class AssetService {
|
||||
throw new Error('Key does not belong to this asset')
|
||||
}
|
||||
|
||||
return s3Service.presign(
|
||||
process.env.S3_BUCKET || 'shumai',
|
||||
key,
|
||||
'GET',
|
||||
true,
|
||||
asset.name ?? undefined,
|
||||
)
|
||||
let downloadFilename: string | undefined
|
||||
if (key === storageKey) {
|
||||
downloadFilename = targetName ?? undefined
|
||||
} else {
|
||||
const keyBasename = path.posix.basename(key)
|
||||
const originalStem = stemFromKey(storageKey)
|
||||
const assetStem = targetName ? stemFromKey(targetName) : originalStem
|
||||
|
||||
if (
|
||||
originalStem &&
|
||||
assetStem &&
|
||||
originalStem !== assetStem &&
|
||||
keyBasename.startsWith(originalStem + '-')
|
||||
) {
|
||||
downloadFilename = assetStem + keyBasename.slice(originalStem.length)
|
||||
} else if (
|
||||
originalStem &&
|
||||
assetStem &&
|
||||
originalStem !== assetStem &&
|
||||
keyBasename.startsWith('watermark-' + originalStem + '-')
|
||||
) {
|
||||
downloadFilename =
|
||||
'watermark-' + assetStem + keyBasename.slice(('watermark-' + originalStem).length)
|
||||
} else {
|
||||
downloadFilename = keyBasename
|
||||
}
|
||||
}
|
||||
|
||||
return s3Service.presign(process.env.S3_BUCKET || 'shumai', key, 'GET', true, downloadFilename)
|
||||
}
|
||||
|
||||
async toPreviewInfo(
|
||||
|
||||
Reference in New Issue
Block a user