]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/download.ts
Add channel server hooks
[github/Chocobozzz/PeerTube.git] / server / controllers / download.ts
index ffe40d57e3ce699f40978f67874c2d813ed1d8ba..a270180c0228e6b3250779e1705160e1b296be4d 100644 (file)
@@ -1,5 +1,5 @@
-import * as cors from 'cors'
-import * as express from 'express'
+import cors from 'cors'
+import express from 'express'
 import { logger } from '@server/helpers/logger'
 import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache'
 import { Hooks } from '@server/lib/plugins/hooks'
@@ -85,8 +85,10 @@ async function downloadVideoFile (req: express.Request, res: express.Response) {
     return res.redirect(videoFile.getObjectStorageUrl())
   }
 
-  await VideoPathManager.Instance.makeAvailableVideoFile(video, videoFile, path => {
-    const filename = `${video.name}-${videoFile.resolution}p${videoFile.extname}`
+  await VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(video), path => {
+    // Express uses basename on filename parameter
+    const videoName = video.name.replace(/[/\\]/g, '_')
+    const filename = `${videoName}-${videoFile.resolution}p${videoFile.extname}`
 
     return res.download(path, filename)
   })
@@ -119,7 +121,7 @@ async function downloadHLSVideoFile (req: express.Request, res: express.Response
     return res.redirect(videoFile.getObjectStorageUrl())
   }
 
-  await VideoPathManager.Instance.makeAvailableVideoFile(streamingPlaylist, videoFile, path => {
+  await VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(streamingPlaylist), path => {
     const filename = `${video.name}-${videoFile.resolution}p-${streamingPlaylist.getStringType()}${videoFile.extname}`
 
     return res.download(path, filename)