diff options
author | Chocobozzz <me@florianbigard.com> | 2022-06-24 16:31:32 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-06-24 16:31:48 +0200 |
commit | c53853ca1b8e32aea5259d436d3d284b9d178919 (patch) | |
tree | dfb081e7fb471ca4b75fd67eabd3216cc6b33129 /server/lib/thumbnail.ts | |
parent | 2873f00bd89d8f1b5f88614415f8142a5c2065c3 (diff) | |
download | PeerTube-c53853ca1b8e32aea5259d436d3d284b9d178919.tar.gz PeerTube-c53853ca1b8e32aea5259d436d3d284b9d178919.tar.zst PeerTube-c53853ca1b8e32aea5259d436d3d284b9d178919.zip |
Introduce worker threads to process remote images
Diffstat (limited to 'server/lib/thumbnail.ts')
-rw-r--r-- | server/lib/thumbnail.ts | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index aa2d7a813..f00c87623 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts | |||
@@ -1,13 +1,13 @@ | |||
1 | import { join } from 'path' | 1 | import { join } from 'path' |
2 | import { ThumbnailType } from '@shared/models' | 2 | import { ThumbnailType } from '@shared/models' |
3 | import { generateImageFilename, generateImageFromVideoFile, processImage } from '../helpers/image-utils' | 3 | import { generateImageFilename, generateImageFromVideoFile, processImage } from '../helpers/image-utils' |
4 | import { downloadImage } from '../helpers/requests' | ||
5 | import { CONFIG } from '../initializers/config' | 4 | import { CONFIG } from '../initializers/config' |
6 | import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants' | 5 | import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants' |
7 | import { ThumbnailModel } from '../models/video/thumbnail' | 6 | import { ThumbnailModel } from '../models/video/thumbnail' |
8 | import { MVideoFile, MVideoThumbnail, MVideoUUID } from '../types/models' | 7 | import { MVideoFile, MVideoThumbnail, MVideoUUID } from '../types/models' |
9 | import { MThumbnail } from '../types/models/video/thumbnail' | 8 | import { MThumbnail } from '../types/models/video/thumbnail' |
10 | import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist' | 9 | import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist' |
10 | import { downloadImageFromWorker } from './local-actor' | ||
11 | import { VideoPathManager } from './video-path-manager' | 11 | import { VideoPathManager } from './video-path-manager' |
12 | 12 | ||
13 | type ImageSize = { height?: number, width?: number } | 13 | type ImageSize = { height?: number, width?: number } |
@@ -49,7 +49,10 @@ function updatePlaylistMiniatureFromUrl (options: { | |||
49 | ? null | 49 | ? null |
50 | : downloadUrl | 50 | : downloadUrl |
51 | 51 | ||
52 | const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height }) | 52 | const thumbnailCreator = () => { |
53 | return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } }) | ||
54 | } | ||
55 | |||
53 | return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) | 56 | return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) |
54 | } | 57 | } |
55 | 58 | ||
@@ -75,7 +78,9 @@ function updateVideoMiniatureFromUrl (options: { | |||
75 | : existingThumbnail.filename | 78 | : existingThumbnail.filename |
76 | 79 | ||
77 | const thumbnailCreator = () => { | 80 | const thumbnailCreator = () => { |
78 | if (thumbnailUrlChanged) return downloadImage(downloadUrl, basePath, filename, { width, height }) | 81 | if (thumbnailUrlChanged) { |
82 | return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } }) | ||
83 | } | ||
79 | 84 | ||
80 | return Promise.resolve() | 85 | return Promise.resolve() |
81 | } | 86 | } |