]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/utils.ts
Prevent video import on non unicast ips
[github/Chocobozzz/PeerTube.git] / server / helpers / utils.ts
index ad3b7949e586d6baeba36569b9f40a0faf9c9c72..6c95a43b62afea04ac21c4636ce6eaecd572ff14 100644 (file)
@@ -1,13 +1,12 @@
+import { remove } from 'fs-extra'
+import { Instance as ParseTorrent } from 'parse-torrent'
+import { join } from 'path'
 import { ResultList } from '../../shared'
+import { CONFIG } from '../initializers/config'
 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 { CONFIG } from '../initializers/config'
-import { isVideoFileExtnameValid } from './custom-validators/videos'
 
-function deleteFileAsync (path: string) {
+function deleteFileAndCatch (path: string) {
   remove(path)
     .catch(err => logger.error('Cannot delete the file %s asynchronously.', path, { err }))
 }
@@ -31,16 +30,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 +83,7 @@ function getUUIDFromFilename (filename: string) {
 // ---------------------------------------------------------------------------
 
 export {
-  deleteFileAsync,
+  deleteFileAndCatch,
   generateRandomString,
   getFormattedObjects,
   getSecureTorrentName,