]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/utils.ts
Do not support subscriptions to accounts
[github/Chocobozzz/PeerTube.git] / server / helpers / utils.ts
index ba07eaaf342c450410f323982b48c5c217729aa1..11c11829285954db39224a0e53c7945d87119acd 100644 (file)
@@ -1,12 +1,13 @@
 import { ResultList } from '../../shared'
 import { ApplicationModel } from '../models/application/application'
-import { execPromise, execPromise2, pseudoRandomBytesPromise, sha256 } from './core-utils'
+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 * as memoizee from 'memoizee'
 import { CONFIG } from '../initializers/config'
+import { isVideoFileExtnameValid } from './custom-validators/videos'
 
 function deleteFileAsync (path: string) {
   remove(path)
@@ -14,7 +15,7 @@ function deleteFileAsync (path: string) {
 }
 
 async function generateRandomString (size: number) {
-  const raw = await pseudoRandomBytesPromise(size)
+  const raw = await randomBytesPromise(size)
 
   return raw.toString('hex')
 }
@@ -40,13 +41,20 @@ const getServerActor = memoizee(async function () {
   actor.Account = application.Account
 
   return actor
-})
+}, { promise: true })
 
-function generateVideoImportTmpPath (target: string | ParseTorrent) {
-  const id = typeof target === 'string' ? target : target.infoHash
+function generateVideoImportTmpPath (target: string | ParseTorrent, extensionArg?: string) {
+  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.mp4')
+  return join(CONFIG.STORAGE.TMP_DIR, `${hash}-import${extension}`)
 }
 
 function getSecureTorrentName (originalName: string) {