From 12dc3a942a13c7f1489822dae052da197ef15905 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 19 Jul 2023 16:02:49 +0200 Subject: Implement replace file in server side --- shared/server-commands/videos/videos-command.ts | 71 ++++++++++++++++++++----- 1 file changed, 58 insertions(+), 13 deletions(-) (limited to 'shared/server-commands/videos') diff --git a/shared/server-commands/videos/videos-command.ts b/shared/server-commands/videos/videos-command.ts index 9602fa7da..6c38fa7ef 100644 --- a/shared/server-commands/videos/videos-command.ts +++ b/shared/server-commands/videos/videos-command.ts @@ -32,6 +32,7 @@ export type VideoEdit = Partial { - const { attributes, expectedStatus } = options + const { path, attributes, expectedStatus } = options let size = 0 let videoFilePath: string @@ -478,7 +480,15 @@ export class VideosCommand extends AbstractCommand { } // Do not check status automatically, we'll check it manually - const initializeSessionRes = await this.prepareResumableUpload({ ...options, expectedStatus: null, attributes, size, mimetype }) + const initializeSessionRes = await this.prepareResumableUpload({ + ...options, + + path, + expectedStatus: null, + attributes, + size, + mimetype + }) const initStatus = initializeSessionRes.status if (videoFilePath && initStatus === HttpStatusCode.CREATED_201) { @@ -487,10 +497,23 @@ export class VideosCommand extends AbstractCommand { const pathUploadId = locationHeader.split('?')[1] - const result = await this.sendResumableChunks({ ...options, pathUploadId, videoFilePath, size }) + const result = await this.sendResumableChunks({ + ...options, + + path, + pathUploadId, + videoFilePath, + size + }) if (result.statusCode === HttpStatusCode.OK_200) { - await this.endResumableUpload({ ...options, expectedStatus: HttpStatusCode.NO_CONTENT_204, pathUploadId }) + await this.endResumableUpload({ + ...options, + + expectedStatus: HttpStatusCode.NO_CONTENT_204, + path, + pathUploadId + }) } return result.body?.video || result.body as any @@ -506,18 +529,19 @@ export class VideosCommand extends AbstractCommand { } async prepareResumableUpload (options: OverrideCommandOptions & { - attributes: VideoEdit + path: string + attributes: { fixture?: string } & { [id: string]: any } size: number mimetype: string originalName?: string lastModified?: number }) { - const { attributes, originalName, lastModified, size, mimetype } = options + const { path, attributes, originalName, lastModified, size, mimetype } = options - const path = '/api/v1/videos/upload-resumable' + const attaches = this.buildUploadAttaches(omit(options.attributes, [ 'fixture' ])) - return this.postUploadRequest({ + const uploadOptions = { ...options, path, @@ -538,11 +562,16 @@ export class VideosCommand extends AbstractCommand { implicitToken: true, defaultExpectedStatus: null - }) + } + + if (Object.keys(attaches).length === 0) return this.postBodyRequest(uploadOptions) + + return this.postUploadRequest(uploadOptions) } sendResumableChunks (options: OverrideCommandOptions & { pathUploadId: string + path: string videoFilePath: string size: number contentLength?: number @@ -550,6 +579,7 @@ export class VideosCommand extends AbstractCommand { digestBuilder?: (chunk: any) => string }) { const { + path, pathUploadId, videoFilePath, size, @@ -559,7 +589,6 @@ export class VideosCommand extends AbstractCommand { expectedStatus = HttpStatusCode.OK_200 } = options - const path = '/api/v1/videos/upload-resumable' let start = 0 const token = this.buildCommonRequestToken({ ...options, implicitToken: true }) @@ -610,12 +639,13 @@ export class VideosCommand extends AbstractCommand { } endResumableUpload (options: OverrideCommandOptions & { + path: string pathUploadId: string }) { return this.deleteRequest({ ...options, - path: '/api/v1/videos/upload-resumable', + path: options.path, rawQuery: options.pathUploadId, implicitToken: true, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 @@ -657,6 +687,21 @@ export class VideosCommand extends AbstractCommand { // --------------------------------------------------------------------------- + replaceSourceFile (options: OverrideCommandOptions & { + videoId: number | string + fixture: string + }) { + return this.buildResumeUpload({ + ...options, + + path: '/api/v1/videos/' + options.videoId + '/source/replace-resumable', + attributes: { fixture: options.fixture }, + expectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + // --------------------------------------------------------------------------- + removeHLSPlaylist (options: OverrideCommandOptions & { videoId: number | string }) { -- cgit v1.2.3