From bafaba0bcda0c9fb553b9eebef3764994bb4ff60 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jun 2023 08:53:14 +0200 Subject: Support lazy download of remote video miniatures --- .../lib/files-cache/avatar-permanent-file-cache.ts | 4 ++-- server/lib/files-cache/index.ts | 1 + .../video-miniature-permanent-file-cache.ts | 28 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 server/lib/files-cache/video-miniature-permanent-file-cache.ts (limited to 'server/lib/files-cache') diff --git a/server/lib/files-cache/avatar-permanent-file-cache.ts b/server/lib/files-cache/avatar-permanent-file-cache.ts index 89228c5a5..1d77c5bc1 100644 --- a/server/lib/files-cache/avatar-permanent-file-cache.ts +++ b/server/lib/files-cache/avatar-permanent-file-cache.ts @@ -1,10 +1,10 @@ +import { CONFIG } from '@server/initializers/config' import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' import { ActorImageModel } from '@server/models/actor/actor-image' import { MActorImage } from '@server/types/models' import { AbstractPermanentFileCache } from './shared' -import { CONFIG } from '@server/initializers/config' -export class AvatarPermanentFileCache extends AbstractPermanentFileCache { +export class AvatarPermanentFileCache extends AbstractPermanentFileCache { constructor () { super(CONFIG.STORAGE.ACTOR_IMAGES) diff --git a/server/lib/files-cache/index.ts b/server/lib/files-cache/index.ts index cc11d5385..5630a9b80 100644 --- a/server/lib/files-cache/index.ts +++ b/server/lib/files-cache/index.ts @@ -1,4 +1,5 @@ export * from './avatar-permanent-file-cache' +export * from './video-miniature-permanent-file-cache' export * from './video-captions-simple-file-cache' export * from './video-previews-simple-file-cache' export * from './video-storyboards-simple-file-cache' diff --git a/server/lib/files-cache/video-miniature-permanent-file-cache.ts b/server/lib/files-cache/video-miniature-permanent-file-cache.ts new file mode 100644 index 000000000..35d9466f7 --- /dev/null +++ b/server/lib/files-cache/video-miniature-permanent-file-cache.ts @@ -0,0 +1,28 @@ +import { CONFIG } from '@server/initializers/config' +import { THUMBNAILS_SIZE } from '@server/initializers/constants' +import { ThumbnailModel } from '@server/models/video/thumbnail' +import { MThumbnail } from '@server/types/models' +import { ThumbnailType } from '@shared/models' +import { AbstractPermanentFileCache } from './shared' + +export class VideoMiniaturePermanentFileCache extends AbstractPermanentFileCache { + + constructor () { + super(CONFIG.STORAGE.THUMBNAILS_DIR) + } + + protected loadModel (filename: string) { + return ThumbnailModel.loadByFilename(filename, ThumbnailType.MINIATURE) + } + + protected getImageSize (image: MThumbnail): { width: number, height: number } { + if (image.width && image.height) { + return { + height: image.height, + width: image.width + } + } + + return THUMBNAILS_SIZE + } +} -- cgit v1.2.3