]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/worker/workers/image-downloader.ts
Process images in a dedicated worker
[github/Chocobozzz/PeerTube.git] / server / lib / worker / workers / image-downloader.ts
CommitLineData
c53853ca
C
1import { remove } from 'fs-extra'
2import { join } from 'path'
3import { processImage } from '@server/helpers/image-utils'
4import { doRequestAndSaveToFile } from '@server/helpers/requests'
5import { CONFIG } from '@server/initializers/config'
6
7async function downloadImage (options: {
8 url: string
9 destDir: string
10 destName: string
11 size: { width: number, height: number }
12}) {
13 const { url, destDir, destName, size } = options
14
15 const tmpPath = join(CONFIG.STORAGE.TMP_DIR, 'pending-' + destName)
16 await doRequestAndSaveToFile(url, tmpPath)
17
18 const destPath = join(destDir, destName)
19
20 try {
3a54605d 21 await processImage({ path: tmpPath, destination: destPath, newSize: size })
c53853ca
C
22 } catch (err) {
23 await remove(tmpPath)
24
25 throw err
26 }
27}
28
29module.exports = downloadImage
30
31export {
32 downloadImage
33}