X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Ffiles-cache%2Fvideos-torrent-cache.ts;h=23217f1403119acfdb1f5b943c51f73260eb0fd4;hb=daa0226b0a2ae1d19b342c2b7a54267d2fd8d30e;hp=ca0e1770daf2e5f340379e97b6b73cc68cfa00b0;hpb=90a8bd305de4153ec21137a73ff482dcc2e3e19b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/files-cache/videos-torrent-cache.ts b/server/lib/files-cache/videos-torrent-cache.ts index ca0e1770d..23217f140 100644 --- a/server/lib/files-cache/videos-torrent-cache.ts +++ b/server/lib/files-cache/videos-torrent-cache.ts @@ -5,6 +5,7 @@ import { CONFIG } from '../../initializers/config' import { FILES_CACHE } from '../../initializers/constants' import { VideoModel } from '../../models/video/video' import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' +import { MVideo, MVideoFile } from '@server/types/models' class VideosTorrentCache extends AbstractVideoStaticFileCache { @@ -22,7 +23,11 @@ class VideosTorrentCache extends AbstractVideoStaticFileCache { const file = await VideoFileModel.loadWithVideoOrPlaylistByTorrentFilename(filename) if (!file) return undefined - if (file.getVideo().isOwned()) return { isOwned: true, path: join(CONFIG.STORAGE.TORRENTS_DIR, file.torrentFilename) } + if (file.getVideo().isOwned()) { + const downloadName = this.buildDownloadName(file.getVideo(), file) + + return { isOwned: true, path: join(CONFIG.STORAGE.TORRENTS_DIR, file.torrentFilename), downloadName } + } return this.loadRemoteFile(filename) } @@ -41,12 +46,16 @@ class VideosTorrentCache extends AbstractVideoStaticFileCache { const remoteUrl = file.getRemoteTorrentUrl(video) const destPath = join(FILES_CACHE.TORRENTS.DIRECTORY, file.torrentFilename) - await doRequestAndSaveToFile({ uri: remoteUrl }, destPath) + await doRequestAndSaveToFile(remoteUrl, destPath) - const downloadName = `${video.name}-${file.resolution}p.torrent` + const downloadName = this.buildDownloadName(video, file) return { isOwned: false, path: destPath, downloadName } } + + private buildDownloadName (video: MVideo, file: MVideoFile) { + return `${video.name}-${file.resolution}p.torrent` + } } export {