aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/thumbnail.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-24 16:31:32 +0200
committerChocobozzz <me@florianbigard.com>2022-06-24 16:31:48 +0200
commitc53853ca1b8e32aea5259d436d3d284b9d178919 (patch)
treedfb081e7fb471ca4b75fd67eabd3216cc6b33129 /server/lib/thumbnail.ts
parent2873f00bd89d8f1b5f88614415f8142a5c2065c3 (diff)
downloadPeerTube-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.ts11
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 @@
1import { join } from 'path' 1import { join } from 'path'
2import { ThumbnailType } from '@shared/models' 2import { ThumbnailType } from '@shared/models'
3import { generateImageFilename, generateImageFromVideoFile, processImage } from '../helpers/image-utils' 3import { generateImageFilename, generateImageFromVideoFile, processImage } from '../helpers/image-utils'
4import { downloadImage } from '../helpers/requests'
5import { CONFIG } from '../initializers/config' 4import { CONFIG } from '../initializers/config'
6import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants' 5import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants'
7import { ThumbnailModel } from '../models/video/thumbnail' 6import { ThumbnailModel } from '../models/video/thumbnail'
8import { MVideoFile, MVideoThumbnail, MVideoUUID } from '../types/models' 7import { MVideoFile, MVideoThumbnail, MVideoUUID } from '../types/models'
9import { MThumbnail } from '../types/models/video/thumbnail' 8import { MThumbnail } from '../types/models/video/thumbnail'
10import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist' 9import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist'
10import { downloadImageFromWorker } from './local-actor'
11import { VideoPathManager } from './video-path-manager' 11import { VideoPathManager } from './video-path-manager'
12 12
13type ImageSize = { height?: number, width?: number } 13type 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 }