]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/image-utils.ts
Bumped to version v1.2.0
[github/Chocobozzz/PeerTube.git] / server / helpers / image-utils.ts
index 3eaa674ed98e4bf67fa0db0026045a36885a045f..e43ea3f1dad03c62cf65457e40fe461b22c98227 100644 (file)
@@ -1,13 +1,26 @@
 import 'multer'
 import * as sharp from 'sharp'
-import { remove } from 'fs-extra'
+import { readFile, remove } from 'fs-extra'
+import { logger } from './logger'
 
 async function processImage (
   physicalFile: { path: string },
   destination: string,
   newSize: { width: number, height: number }
 ) {
-  await sharp(physicalFile.path)
+  if (physicalFile.path === destination) {
+    throw new Error('Sharp needs an input path different that the output path.')
+  }
+
+  logger.debug('Processing image %s to %s.', physicalFile.path, destination)
+
+  // Avoid sharp cache
+  const buf = await readFile(physicalFile.path)
+  const sharpInstance = sharp(buf)
+
+  await remove(destination)
+
+  await sharpInstance
     .resize(newSize.width, newSize.height)
     .toFile(destination)