]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/utils.ts
Add ability to delete a specific video file
[github/Chocobozzz/PeerTube.git] / server / helpers / utils.ts
index ad3b7949e586d6baeba36569b9f40a0faf9c9c72..6b9333b533a6282d83343d22696a69ec89251ac6 100644 (file)
@@ -1,13 +1,13 @@
-import { ResultList } from '../../shared'
-import { execPromise, execPromise2, randomBytesPromise, sha256 } from './core-utils'
-import { logger } from './logger'
-import { join } from 'path'
-import { Instance as ParseTorrent } from 'parse-torrent'
 import { remove } from 'fs-extra'
+import { Instance as ParseTorrent } from 'parse-torrent'
+import { join } from 'path'
+import { sha256 } from '@shared/extra-utils'
+import { ResultList } from '@shared/models'
 import { CONFIG } from '../initializers/config'
-import { isVideoFileExtnameValid } from './custom-validators/videos'
+import { execPromise, execPromise2, randomBytesPromise } from './core-utils'
+import { logger } from './logger'
 
-function deleteFileAsync (path: string) {
+function deleteFileAndCatch (path: string) {
   remove(path)
     .catch(err => logger.error('Cannot delete the file %s asynchronously.', path, { err }))
 }
@@ -31,16 +31,11 @@ function getFormattedObjects<U, V, T extends FormattableToJSON<U, V>> (objects:
   } as ResultList<V>
 }
 
-function generateVideoImportTmpPath (target: string | ParseTorrent, extensionArg?: string) {
+function generateVideoImportTmpPath (target: string | ParseTorrent, extension = '.mp4') {
   const id = typeof target === 'string'
     ? target
     : target.infoHash
 
-  let extension = '.mp4'
-  if (extensionArg && isVideoFileExtnameValid(extensionArg)) {
-    extension = extensionArg
-  }
-
   const hash = sha256(id)
   return join(CONFIG.STORAGE.TMP_DIR, `${hash}-import${extension}`)
 }
@@ -89,7 +84,7 @@ function getUUIDFromFilename (filename: string) {
 // ---------------------------------------------------------------------------
 
 export {
-  deleteFileAsync,
+  deleteFileAndCatch,
   generateRandomString,
   getFormattedObjects,
   getSecureTorrentName,