mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Add hooks support for video download
This commit is contained in:
parent
c0ab041c2c
commit
4bc45da342
7 changed files with 198 additions and 20 deletions
|
@ -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 <string> {
|
||||
|
||||
|
@ -22,7 +23,11 @@ class VideosTorrentCache extends AbstractVideoStaticFileCache <string> {
|
|||
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)
|
||||
}
|
||||
|
@ -43,10 +48,14 @@ class VideosTorrentCache extends AbstractVideoStaticFileCache <string> {
|
|||
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue