X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-file.ts;h=22cf638046afb6e3fb1ee0bf2e33285cc5484859;hb=e5dbd5084e7ae91ce118c0bccd5b84c47b88c55f;hp=5a37062590a0aa9b9e481c9ba101a53566d91d88;hpb=d9a2a03196275065c28f4a0b7d4d7bc9992d77a1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index 5a3706259..22cf63804 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts @@ -25,6 +25,7 @@ import { logger } from '@server/helpers/logger' import { extractVideo } from '@server/helpers/video' import { getTorrentFilePath } from '@server/lib/video-paths' import { MStreamingPlaylistVideo, MVideo, MVideoWithHost } from '@server/types/models' +import { AttributesOnly } from '@shared/core-utils' import { isVideoFileExtnameValid, isVideoFileInfoHashValid, @@ -149,7 +150,7 @@ export enum ScopeNames { } ] }) -export class VideoFileModel extends Model { +export class VideoFileModel extends Model>> { @CreatedAt createdAt: Date @@ -401,6 +402,10 @@ export class VideoFileModel extends Model { return VideoFileModel.destroy(options) } + hasTorrent () { + return this.infoHash && this.torrentFilename + } + getVideoOrStreamingPlaylist (this: MVideoFileVideo | MVideoFileStreamingPlaylistVideo): MVideo | MStreamingPlaylistVideo { if (this.videoId) return (this as MVideoFileVideo).Video @@ -423,7 +428,7 @@ export class VideoFileModel extends Model { return !!this.videoStreamingPlaylistId } - getFileUrl (video: MVideoWithHost) { + getFileUrl (video: MVideo) { if (!this.Video) this.Video = video as VideoModel if (video.isOwned()) return WEBSERVER.URL + this.getFileStaticPath(video) @@ -449,7 +454,7 @@ export class VideoFileModel extends Model { return buildRemoteVideoBaseUrl(video, path) } - getRemoteTorrentUrl (video: MVideoWithHost) { + getRemoteTorrentUrl (video: MVideo) { if (video.isOwned()) throw new Error(`Video ${video.url} is not a remote video`) return this.torrentUrl @@ -457,18 +462,26 @@ export class VideoFileModel extends Model { // We proxify torrent requests so use a local URL getTorrentUrl () { + if (!this.torrentFilename) return null + return WEBSERVER.URL + this.getTorrentStaticPath() } getTorrentStaticPath () { + if (!this.torrentFilename) return null + return join(LAZY_STATIC_PATHS.TORRENTS, this.torrentFilename) } getTorrentDownloadUrl () { + if (!this.torrentFilename) return null + return WEBSERVER.URL + join(STATIC_DOWNLOAD_PATHS.TORRENTS, this.torrentFilename) } removeTorrent () { + if (!this.torrentFilename) return null + const torrentPath = getTorrentFilePath(this) return remove(torrentPath) .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err }))