mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 08:47:38 +00:00
refactor(storage): use original filenames and fix download UX
- Store uploaded files as files/{ulid}/{original-name} instead of files/{ulid}/raw
- Store transcoded videos as {stem}-{resolution}.mp4 (e.g. foo-720p.mp4)
- Store transcoded images as {stem}-{width}p.webp (e.g. foo-1920p.webp)
- Add download?: boolean param to presign - only sets Content-Disposition: attachment when true
- Local storage handler only sets Content-Disposition when ?download=1 query param is present
- Add POST /api/files/download-url endpoint for key-based single file downloads
- Uses ResourceType.Asset for permission check
- Validates key belongs to the asset's storage directory
- Fix existing download-links API to pass download: true to presign
- Fix breadcrumb navbar download: video shows resolution submenu, others download directly
- Fix video player download: calls download-url API, shows correct file type label
- Remove filename query param hack from presign URLs
- Add sanitizeFilename() and stemFromKey() utility helpers
- Add key field to VideoTranscode DTO interface
This commit is contained in:
@@ -2,6 +2,7 @@ import { prisma, WorkflowTaskType, WorkflowTaskStatus } from '@shumai/db'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import { transcodeService } from '@shumai/core'
|
||||
import { metadataService } from '@shumai/core/src/metadata/metadata'
|
||||
import { stemFromKey } from '@shumai/core/src/utils/filename'
|
||||
import { ApplicationFailure } from '@temporalio/activity'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
@@ -162,7 +163,9 @@ export async function transcodeVideoActivity(
|
||||
params: VideoActivityParams,
|
||||
): Promise<PrismaJson.VideoTranscode> {
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
const key = path.join(path.dirname(params.assetKey), `video-${params.videoSpec.height}p.mp4`)
|
||||
const stem = stemFromKey(params.assetKey)
|
||||
const res = params.videoSpec.resolution || `${params.videoSpec.height}p`
|
||||
const key = path.posix.join(path.posix.dirname(params.assetKey), `${stem}-${res}.mp4`)
|
||||
|
||||
try {
|
||||
await s3Service.headObject(bucket, key)
|
||||
@@ -172,7 +175,7 @@ export async function transcodeVideoActivity(
|
||||
}
|
||||
|
||||
const tmpDir = path.dirname(params.filePath)
|
||||
const outputFile = path.join(tmpDir, `video-${params.videoSpec.height}p.mp4`)
|
||||
const outputFile = path.join(tmpDir, `${stem}-${res}.mp4`)
|
||||
|
||||
try {
|
||||
let targetFps: number | string = params.originalFps || 30
|
||||
@@ -237,7 +240,11 @@ export async function transcodeImageActivity(
|
||||
params: ImageActivityParams,
|
||||
): Promise<PrismaJson.ImageTranscode> {
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
const key = path.join(path.dirname(params.assetKey), `image-${params.imageSpec.width}p.webp`)
|
||||
const stem = stemFromKey(params.assetKey)
|
||||
const key = path.posix.join(
|
||||
path.posix.dirname(params.assetKey),
|
||||
`${stem}-${params.imageSpec.width}p.webp`,
|
||||
)
|
||||
|
||||
try {
|
||||
await s3Service.headObject(bucket, key)
|
||||
@@ -247,7 +254,7 @@ export async function transcodeImageActivity(
|
||||
}
|
||||
|
||||
const tmpDir = path.dirname(params.filePath)
|
||||
const outputFile = path.join(tmpDir, `image-${params.imageSpec.width}p.webp`)
|
||||
const outputFile = path.join(tmpDir, `${stem}-${params.imageSpec.width}p.webp`)
|
||||
|
||||
try {
|
||||
await transcodeService.transcodeImage(
|
||||
|
||||
Reference in New Issue
Block a user