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,
}
]
})
-export class VideoFileModel extends Model {
+export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel>>> {
@CreatedAt
createdAt: Date
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)
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
// 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 }))