mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 21:04:59 +00:00
feat(transcode): optimize video operations using ffmpeg http range requests (#393)
* feat(transcode): optimize video operations using ffmpeg http range requests * fix(transcode): preserve non-retryable errors and ensure mapConcurrent settles on rejection
This commit is contained in:
@@ -345,6 +345,15 @@ describe('S3Service implementations', () => {
|
||||
).rejects.toThrow('Abort multipart upload requires uploadId')
|
||||
})
|
||||
|
||||
it('should resolveInput using presign GET in S3StorageService', async () => {
|
||||
const s3 = new S3StorageService('http://localhost:9000', 'key', 'secret', 'test-bucket')
|
||||
const presignSpy = vi.spyOn(s3, 'presign').mockResolvedValue('https://presigned.s3.url')
|
||||
|
||||
const input = await s3.resolveInput('test-bucket', 'video.mp4')
|
||||
expect(input).toBe('https://presigned.s3.url')
|
||||
expect(presignSpy).toHaveBeenCalledWith('test-bucket', 'video.mp4', 'GET')
|
||||
})
|
||||
|
||||
it('should stream in uploadFileToKey', async () => {
|
||||
const s3 = new S3StorageService('http://localhost:9000', 'key', 'secret', 'test-bucket')
|
||||
s3SendSpy.mockClear()
|
||||
@@ -587,6 +596,17 @@ describe('S3Service implementations', () => {
|
||||
it('should throw an error for unsupported presign methods', async () => {
|
||||
await expect(localS3.presign('b', 'k', 'POST')).rejects.toThrow()
|
||||
})
|
||||
|
||||
it('should resolveInput to local file path if file exists on disk', async () => {
|
||||
await localS3.putObject('my-bucket', 'video.mp4', 'dummy content', 13)
|
||||
const input = await localS3.resolveInput('my-bucket', 'video.mp4')
|
||||
expect(input).toBe(path.join(TEST_BASE_PATH, 'my-bucket', 'video.mp4'))
|
||||
})
|
||||
|
||||
it('should resolveInput to presigned URL if file does not exist on disk', async () => {
|
||||
const input = await localS3.resolveInput('my-bucket', 'nonexistent.mp4')
|
||||
expect(input).toBe('http://localhost:3000/files/my-bucket/nonexistent.mp4')
|
||||
})
|
||||
})
|
||||
|
||||
describe('s3Service initialization', () => {
|
||||
|
||||
@@ -118,6 +118,7 @@ export interface S3Service {
|
||||
request: S3SignRequest,
|
||||
) => Promise<{ url: string }>
|
||||
abortMultipartUpload: (bucket: string, key: string, uploadId: string) => Promise<void>
|
||||
resolveInput: (bucket: string, key: string) => Promise<string>
|
||||
}
|
||||
|
||||
export class S3StorageService implements S3Service {
|
||||
@@ -459,6 +460,10 @@ export class S3StorageService implements S3Service {
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
async resolveInput(bucket: string, key: string): Promise<string> {
|
||||
return this.presign(bucket, key, 'GET')
|
||||
}
|
||||
}
|
||||
|
||||
export class LocalStorageService implements S3Service {
|
||||
@@ -717,6 +722,14 @@ export class LocalStorageService implements S3Service {
|
||||
): Promise<void> {
|
||||
await this.deleteObject(bucket, key)
|
||||
}
|
||||
|
||||
async resolveInput(bucket: string, key: string): Promise<string> {
|
||||
const filePath = this.getFilePath(bucket, key)
|
||||
if (fs.existsSync(filePath)) {
|
||||
return filePath
|
||||
}
|
||||
return this.presign(bucket, key, 'GET')
|
||||
}
|
||||
}
|
||||
|
||||
export function getStorageBackend(): 's3' | 'local' {
|
||||
|
||||
Reference in New Issue
Block a user