This commit is contained in:
Chocobozzz 2021-02-18 11:28:00 +01:00 committed by Chocobozzz
parent f66db4d5c8
commit 8efc27bf14
13 changed files with 23 additions and 21 deletions

View File

@ -72,7 +72,7 @@ async function run () {
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()
}
}

View File

@ -127,7 +127,7 @@ async function run () {
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) {

View File

@ -222,7 +222,7 @@ async function addVideo (req: express.Request, res: express.Response) {
})
// Create the torrent file
await createTorrentAndSetInfoHash(video, video, videoFile)
await createTorrentAndSetInfoHash(video, videoFile)
const { videoCreated } = await sequelizeTypescript.transaction(async t => {
const sequelizeOptions = { transaction: t }

View File

@ -94,5 +94,6 @@ async function getTorrent (req: express.Request, res: express.Response) {
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 })
}

View File

@ -7,13 +7,14 @@ import * as WebTorrent from 'webtorrent'
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)
@ -77,12 +78,12 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName
})
}
// 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}`,
@ -108,7 +109,7 @@ async function createTorrentAndSetInfoHash (
}
function generateMagnetUri (
video: MVideoWithHost,
video: MVideo,
videoFile: MVideoFileRedundanciesOpt,
trackerUrls: string[]
) {

View File

@ -912,7 +912,7 @@ function getTrackerUrls (object: VideoObject, video: MVideoWithHost) {
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
})

View File

@ -82,7 +82,7 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) {
await copy(inputFilePath, outputPath)
video.VideoFiles.push(newVideoFile)
await createTorrentAndSetInfoHash(video, video, newVideoFile)
await createTorrentAndSetInfoHash(video, newVideoFile)
await newVideoFile.save()
}

View File

@ -185,7 +185,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: MVid
}
// Create torrent
await createTorrentAndSetInfoHash(videoImportWithFiles.Video, videoImportWithFiles.Video, videoFile)
await createTorrentAndSetInfoHash(videoImportWithFiles.Video, videoFile)
const videoFileSave = videoFile.toJSON()

View File

@ -254,7 +254,7 @@ async function onWebTorrentVideoFileTranscoding (
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')
@ -350,7 +350,7 @@ async function generateHlsPlaylistCommon (options: {
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')

View File

@ -16,7 +16,7 @@ import {
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'
@ -163,7 +163,7 @@ export class ThumbnailModel extends Model {
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

View File

@ -16,7 +16,7 @@ import {
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'
@ -203,7 +203,7 @@ export class VideoCaptionModel extends Model {
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()

View File

@ -423,7 +423,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 +449,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

View File

@ -14,11 +14,11 @@ import {
} 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'
@ -225,7 +225,7 @@ function videoFilesModelToFormattedJSON (
function addVideoFilesInAPAcc (
acc: ActivityUrlObject[] | ActivityTagObject[],
video: MVideoWithHost,
video: MVideo,
files: MVideoFile[]
) {
const trackerUrls = video.getTrackerUrls()