From b1770a0af464ad6350d156245b1abcc1395e142e Mon Sep 17 00:00:00 2001 From: Kim <1877318+kimsible@users.noreply.github.com> Date: Mon, 20 Apr 2020 10:28:38 +0200 Subject: Add thumbnail / preview generation from url on the fly (#2646) * Add thumbnails generation on the fly to URL import * Display generated preview to import first edit * Use ternary to get type inference * Move preview/thumbnail test just after import Co-authored-by: kimsible --- .../video-import-url.component.ts | 37 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'client/src/app/videos') diff --git a/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.ts b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.ts index a17d73683..213c42333 100644 --- a/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.ts +++ b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.ts @@ -11,7 +11,7 @@ import { VideoEdit } from '@app/shared/video/video-edit.model' import { FormValidatorService } from '@app/shared' import { VideoCaptionService } from '@app/shared/video-caption' import { VideoImportService } from '@app/shared/video-import' -import { scrollToTop } from '@app/shared/misc/utils' +import { scrollToTop, getAbsoluteAPIUrl } from '@app/shared/misc/utils' import { switchMap, map } from 'rxjs/operators' @Component({ @@ -95,12 +95,22 @@ export class VideoImportUrlComponent extends VideoSend implements OnInit, CanCom this.isImportingVideo = false this.hasImportedVideo = true + const absoluteAPIUrl = getAbsoluteAPIUrl() + + const thumbnailUrl = video.thumbnailPath + ? absoluteAPIUrl + video.thumbnailPath + : null + + const previewUrl = video.previewPath + ? absoluteAPIUrl + video.previewPath + : null + this.video = new VideoEdit(Object.assign(video, { commentsEnabled: videoUpdate.commentsEnabled, downloadEnabled: videoUpdate.downloadEnabled, support: null, - thumbnailUrl: null, - previewUrl: null + thumbnailUrl, + previewUrl })) this.videoCaptions = videoCaptions @@ -147,5 +157,26 @@ export class VideoImportUrlComponent extends VideoSend implements OnInit, CanCom private hydrateFormFromVideo () { this.form.patchValue(this.video.toFormPatch()) + + const objects = [ + { + url: 'thumbnailUrl', + name: 'thumbnailfile' + }, + { + url: 'previewUrl', + name: 'previewfile' + } + ] + + for (const obj of objects) { + fetch(this.video[obj.url]) + .then(response => response.blob()) + .then(data => { + this.form.patchValue({ + [ obj.name ]: data + }) + }) + } } } -- cgit v1.2.3