console.log('Failed to optimize %s, restoring original', basename(currentFile))
await move(backupFile, currentFile, { overwrite: true })
- await createTorrentAndSetInfoHash(video, video, file)
+ await createTorrentAndSetInfoHash(video, file)
await file.save()
}
}
for (const file of video.VideoFiles) {
console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid)
- await createTorrentAndSetInfoHash(video, video, file)
+ await createTorrentAndSetInfoHash(video, file)
}
for (const playlist of video.VideoStreamingPlaylists) {
})
// Create the torrent file
- await createTorrentAndSetInfoHash(video, video, videoFile)
+ await createTorrentAndSetInfoHash(video, videoFile)
const { videoCreated } = await sequelizeTypescript.transaction(async t => {
const sequelizeOptions = { transaction: t }
const result = await VideosTorrentCache.Instance.getFilePath(req.params.filename)
if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
+ // Torrents still use the old naming convention (video uuid + .torrent)
return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER })
}
import { isArray } from '@server/helpers/custom-validators/misc'
import { WEBSERVER } from '@server/initializers/constants'
import { generateTorrentFileName, getVideoFilePath } from '@server/lib/video-paths'
-import { MVideo, MVideoWithHost } from '@server/types/models/video/video'
+import { MVideo } from '@server/types/models/video/video'
import { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/video/video-file'
import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist'
import { CONFIG } from '../initializers/config'
import { promisify2 } from './core-utils'
import { logger } from './logger'
import { generateVideoImportTmpPath } from './utils'
+import { extractVideo } from './video'
const createTorrentPromise = promisify2<string, any, any>(createTorrent)
})
}
-// FIXME: refactor/merge videoOrPlaylist and video arguments
async function createTorrentAndSetInfoHash (
videoOrPlaylist: MVideo | MStreamingPlaylistVideo,
- video: MVideoWithHost,
videoFile: MVideoFile
) {
+ const video = extractVideo(videoOrPlaylist)
+
const options = {
// Keep the extname, it's used by the client to stream the file inside a web browser
name: `${video.name} ${videoFile.resolution}p${videoFile.extname}`,
}
function generateMagnetUri (
- video: MVideoWithHost,
+ video: MVideo,
videoFile: MVideoFileRedundanciesOpt,
trackerUrls: string[]
) {
const trackers = object.url.filter(u => isAPVideoTrackerUrlObject(u))
.map((u: ActivityTrackerUrlObject) => {
- if (u.rel.includes('websocket')) wsFound = true
+ if (isArray(u.rel) && u.rel.includes('websocket')) wsFound = true
return u.href
})
await copy(inputFilePath, outputPath)
video.VideoFiles.push(newVideoFile)
- await createTorrentAndSetInfoHash(video, video, newVideoFile)
+ await createTorrentAndSetInfoHash(video, newVideoFile)
await newVideoFile.save()
}
}
// Create torrent
- await createTorrentAndSetInfoHash(videoImportWithFiles.Video, videoImportWithFiles.Video, videoFile)
+ await createTorrentAndSetInfoHash(videoImportWithFiles.Video, videoFile)
const videoFileSave = videoFile.toJSON()
videoFile.fps = fps
videoFile.metadata = metadata
- await createTorrentAndSetInfoHash(video, video, videoFile)
+ await createTorrentAndSetInfoHash(video, videoFile)
await VideoFileModel.customUpsert(videoFile, 'video', undefined)
video.VideoFiles = await video.$get('VideoFiles')
newVideoFile.fps = await getVideoFileFPS(videoFilePath)
newVideoFile.metadata = await getMetadataFromFile(videoFilePath)
- await createTorrentAndSetInfoHash(videoStreamingPlaylist, video, newVideoFile)
+ await createTorrentAndSetInfoHash(videoStreamingPlaylist, newVideoFile)
await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined)
videoStreamingPlaylist.VideoFiles = await videoStreamingPlaylist.$get('VideoFiles')
UpdatedAt
} from 'sequelize-typescript'
import { afterCommitIfTransaction } from '@server/helpers/database-utils'
-import { MThumbnail, MThumbnailVideo, MVideoWithHost } from '@server/types/models'
+import { MThumbnail, MThumbnailVideo, MVideo } from '@server/types/models'
import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
import { logger } from '../../helpers/logger'
import { CONFIG } from '../../initializers/config'
return join(directory, filename)
}
- getFileUrl (video: MVideoWithHost) {
+ getFileUrl (video: MVideo) {
const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename
if (video.isOwned()) return WEBSERVER.URL + staticPath
UpdatedAt
} from 'sequelize-typescript'
import { v4 as uuidv4 } from 'uuid'
-import { MVideoCaption, MVideoCaptionFormattable, MVideoCaptionVideo, MVideoWithHost } from '@server/types/models'
+import { MVideo, MVideoCaption, MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/types/models'
import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model'
import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions'
import { logger } from '../../helpers/logger'
return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.filename)
}
- getFileUrl (video: MVideoWithHost) {
+ getFileUrl (video: MVideo) {
if (!this.Video) this.Video = video as VideoModel
if (video.isOwned()) return WEBSERVER.URL + this.getCaptionStaticPath()
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
} from '../../lib/activitypub/url'
import {
MStreamingPlaylistRedundanciesOpt,
+ MVideo,
MVideoAP,
MVideoFile,
MVideoFormattable,
- MVideoFormattableDetails,
- MVideoWithHost
+ MVideoFormattableDetails
} from '../../types/models'
import { MVideoFileRedundanciesOpt } from '../../types/models/video/video-file'
import { VideoModel } from './video'
function addVideoFilesInAPAcc (
acc: ActivityUrlObject[] | ActivityTagObject[],
- video: MVideoWithHost,
+ video: MVideo,
files: MVideoFile[]
) {
const trackerUrls = video.getTrackerUrls()