Cleanup
This commit is contained in:
parent
f66db4d5c8
commit
8efc27bf14
|
@ -72,7 +72,7 @@ async function run () {
|
||||||
|
|
||||||
console.log('Failed to optimize %s, restoring original', basename(currentFile))
|
console.log('Failed to optimize %s, restoring original', basename(currentFile))
|
||||||
await move(backupFile, currentFile, { overwrite: true })
|
await move(backupFile, currentFile, { overwrite: true })
|
||||||
await createTorrentAndSetInfoHash(video, video, file)
|
await createTorrentAndSetInfoHash(video, file)
|
||||||
await file.save()
|
await file.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ async function run () {
|
||||||
|
|
||||||
for (const file of video.VideoFiles) {
|
for (const file of video.VideoFiles) {
|
||||||
console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid)
|
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) {
|
for (const playlist of video.VideoStreamingPlaylists) {
|
||||||
|
|
|
@ -222,7 +222,7 @@ async function addVideo (req: express.Request, res: express.Response) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create the torrent file
|
// Create the torrent file
|
||||||
await createTorrentAndSetInfoHash(video, video, videoFile)
|
await createTorrentAndSetInfoHash(video, videoFile)
|
||||||
|
|
||||||
const { videoCreated } = await sequelizeTypescript.transaction(async t => {
|
const { videoCreated } = await sequelizeTypescript.transaction(async t => {
|
||||||
const sequelizeOptions = { transaction: t }
|
const sequelizeOptions = { transaction: t }
|
||||||
|
|
|
@ -94,5 +94,6 @@ async function getTorrent (req: express.Request, res: express.Response) {
|
||||||
const result = await VideosTorrentCache.Instance.getFilePath(req.params.filename)
|
const result = await VideosTorrentCache.Instance.getFilePath(req.params.filename)
|
||||||
if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
|
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 })
|
return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER })
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,14 @@ import * as WebTorrent from 'webtorrent'
|
||||||
import { isArray } from '@server/helpers/custom-validators/misc'
|
import { isArray } from '@server/helpers/custom-validators/misc'
|
||||||
import { WEBSERVER } from '@server/initializers/constants'
|
import { WEBSERVER } from '@server/initializers/constants'
|
||||||
import { generateTorrentFileName, getVideoFilePath } from '@server/lib/video-paths'
|
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 { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/video/video-file'
|
||||||
import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist'
|
import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist'
|
||||||
import { CONFIG } from '../initializers/config'
|
import { CONFIG } from '../initializers/config'
|
||||||
import { promisify2 } from './core-utils'
|
import { promisify2 } from './core-utils'
|
||||||
import { logger } from './logger'
|
import { logger } from './logger'
|
||||||
import { generateVideoImportTmpPath } from './utils'
|
import { generateVideoImportTmpPath } from './utils'
|
||||||
|
import { extractVideo } from './video'
|
||||||
|
|
||||||
const createTorrentPromise = promisify2<string, any, any>(createTorrent)
|
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 (
|
async function createTorrentAndSetInfoHash (
|
||||||
videoOrPlaylist: MVideo | MStreamingPlaylistVideo,
|
videoOrPlaylist: MVideo | MStreamingPlaylistVideo,
|
||||||
video: MVideoWithHost,
|
|
||||||
videoFile: MVideoFile
|
videoFile: MVideoFile
|
||||||
) {
|
) {
|
||||||
|
const video = extractVideo(videoOrPlaylist)
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
// Keep the extname, it's used by the client to stream the file inside a web browser
|
// 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}`,
|
name: `${video.name} ${videoFile.resolution}p${videoFile.extname}`,
|
||||||
|
@ -108,7 +109,7 @@ async function createTorrentAndSetInfoHash (
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateMagnetUri (
|
function generateMagnetUri (
|
||||||
video: MVideoWithHost,
|
video: MVideo,
|
||||||
videoFile: MVideoFileRedundanciesOpt,
|
videoFile: MVideoFileRedundanciesOpt,
|
||||||
trackerUrls: string[]
|
trackerUrls: string[]
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -912,7 +912,7 @@ function getTrackerUrls (object: VideoObject, video: MVideoWithHost) {
|
||||||
|
|
||||||
const trackers = object.url.filter(u => isAPVideoTrackerUrlObject(u))
|
const trackers = object.url.filter(u => isAPVideoTrackerUrlObject(u))
|
||||||
.map((u: ActivityTrackerUrlObject) => {
|
.map((u: ActivityTrackerUrlObject) => {
|
||||||
if (u.rel.includes('websocket')) wsFound = true
|
if (isArray(u.rel) && u.rel.includes('websocket')) wsFound = true
|
||||||
|
|
||||||
return u.href
|
return u.href
|
||||||
})
|
})
|
||||||
|
|
|
@ -82,7 +82,7 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) {
|
||||||
await copy(inputFilePath, outputPath)
|
await copy(inputFilePath, outputPath)
|
||||||
|
|
||||||
video.VideoFiles.push(newVideoFile)
|
video.VideoFiles.push(newVideoFile)
|
||||||
await createTorrentAndSetInfoHash(video, video, newVideoFile)
|
await createTorrentAndSetInfoHash(video, newVideoFile)
|
||||||
|
|
||||||
await newVideoFile.save()
|
await newVideoFile.save()
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: MVid
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create torrent
|
// Create torrent
|
||||||
await createTorrentAndSetInfoHash(videoImportWithFiles.Video, videoImportWithFiles.Video, videoFile)
|
await createTorrentAndSetInfoHash(videoImportWithFiles.Video, videoFile)
|
||||||
|
|
||||||
const videoFileSave = videoFile.toJSON()
|
const videoFileSave = videoFile.toJSON()
|
||||||
|
|
||||||
|
|
|
@ -254,7 +254,7 @@ async function onWebTorrentVideoFileTranscoding (
|
||||||
videoFile.fps = fps
|
videoFile.fps = fps
|
||||||
videoFile.metadata = metadata
|
videoFile.metadata = metadata
|
||||||
|
|
||||||
await createTorrentAndSetInfoHash(video, video, videoFile)
|
await createTorrentAndSetInfoHash(video, videoFile)
|
||||||
|
|
||||||
await VideoFileModel.customUpsert(videoFile, 'video', undefined)
|
await VideoFileModel.customUpsert(videoFile, 'video', undefined)
|
||||||
video.VideoFiles = await video.$get('VideoFiles')
|
video.VideoFiles = await video.$get('VideoFiles')
|
||||||
|
@ -350,7 +350,7 @@ async function generateHlsPlaylistCommon (options: {
|
||||||
newVideoFile.fps = await getVideoFileFPS(videoFilePath)
|
newVideoFile.fps = await getVideoFileFPS(videoFilePath)
|
||||||
newVideoFile.metadata = await getMetadataFromFile(videoFilePath)
|
newVideoFile.metadata = await getMetadataFromFile(videoFilePath)
|
||||||
|
|
||||||
await createTorrentAndSetInfoHash(videoStreamingPlaylist, video, newVideoFile)
|
await createTorrentAndSetInfoHash(videoStreamingPlaylist, newVideoFile)
|
||||||
|
|
||||||
await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined)
|
await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined)
|
||||||
videoStreamingPlaylist.VideoFiles = await videoStreamingPlaylist.$get('VideoFiles')
|
videoStreamingPlaylist.VideoFiles = await videoStreamingPlaylist.$get('VideoFiles')
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {
|
||||||
UpdatedAt
|
UpdatedAt
|
||||||
} from 'sequelize-typescript'
|
} from 'sequelize-typescript'
|
||||||
import { afterCommitIfTransaction } from '@server/helpers/database-utils'
|
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 { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { CONFIG } from '../../initializers/config'
|
import { CONFIG } from '../../initializers/config'
|
||||||
|
@ -163,7 +163,7 @@ export class ThumbnailModel extends Model {
|
||||||
return join(directory, filename)
|
return join(directory, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
getFileUrl (video: MVideoWithHost) {
|
getFileUrl (video: MVideo) {
|
||||||
const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename
|
const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename
|
||||||
|
|
||||||
if (video.isOwned()) return WEBSERVER.URL + staticPath
|
if (video.isOwned()) return WEBSERVER.URL + staticPath
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {
|
||||||
UpdatedAt
|
UpdatedAt
|
||||||
} from 'sequelize-typescript'
|
} from 'sequelize-typescript'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
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 { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model'
|
||||||
import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions'
|
import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
|
@ -203,7 +203,7 @@ export class VideoCaptionModel extends Model {
|
||||||
return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.filename)
|
return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
getFileUrl (video: MVideoWithHost) {
|
getFileUrl (video: MVideo) {
|
||||||
if (!this.Video) this.Video = video as VideoModel
|
if (!this.Video) this.Video = video as VideoModel
|
||||||
|
|
||||||
if (video.isOwned()) return WEBSERVER.URL + this.getCaptionStaticPath()
|
if (video.isOwned()) return WEBSERVER.URL + this.getCaptionStaticPath()
|
||||||
|
|
|
@ -423,7 +423,7 @@ export class VideoFileModel extends Model {
|
||||||
return !!this.videoStreamingPlaylistId
|
return !!this.videoStreamingPlaylistId
|
||||||
}
|
}
|
||||||
|
|
||||||
getFileUrl (video: MVideoWithHost) {
|
getFileUrl (video: MVideo) {
|
||||||
if (!this.Video) this.Video = video as VideoModel
|
if (!this.Video) this.Video = video as VideoModel
|
||||||
|
|
||||||
if (video.isOwned()) return WEBSERVER.URL + this.getFileStaticPath(video)
|
if (video.isOwned()) return WEBSERVER.URL + this.getFileStaticPath(video)
|
||||||
|
@ -449,7 +449,7 @@ export class VideoFileModel extends Model {
|
||||||
return buildRemoteVideoBaseUrl(video, path)
|
return buildRemoteVideoBaseUrl(video, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
getRemoteTorrentUrl (video: MVideoWithHost) {
|
getRemoteTorrentUrl (video: MVideo) {
|
||||||
if (video.isOwned()) throw new Error(`Video ${video.url} is not a remote video`)
|
if (video.isOwned()) throw new Error(`Video ${video.url} is not a remote video`)
|
||||||
|
|
||||||
return this.torrentUrl
|
return this.torrentUrl
|
||||||
|
|
|
@ -14,11 +14,11 @@ import {
|
||||||
} from '../../lib/activitypub/url'
|
} from '../../lib/activitypub/url'
|
||||||
import {
|
import {
|
||||||
MStreamingPlaylistRedundanciesOpt,
|
MStreamingPlaylistRedundanciesOpt,
|
||||||
|
MVideo,
|
||||||
MVideoAP,
|
MVideoAP,
|
||||||
MVideoFile,
|
MVideoFile,
|
||||||
MVideoFormattable,
|
MVideoFormattable,
|
||||||
MVideoFormattableDetails,
|
MVideoFormattableDetails
|
||||||
MVideoWithHost
|
|
||||||
} from '../../types/models'
|
} from '../../types/models'
|
||||||
import { MVideoFileRedundanciesOpt } from '../../types/models/video/video-file'
|
import { MVideoFileRedundanciesOpt } from '../../types/models/video/video-file'
|
||||||
import { VideoModel } from './video'
|
import { VideoModel } from './video'
|
||||||
|
@ -225,7 +225,7 @@ function videoFilesModelToFormattedJSON (
|
||||||
|
|
||||||
function addVideoFilesInAPAcc (
|
function addVideoFilesInAPAcc (
|
||||||
acc: ActivityUrlObject[] | ActivityTagObject[],
|
acc: ActivityUrlObject[] | ActivityTagObject[],
|
||||||
video: MVideoWithHost,
|
video: MVideo,
|
||||||
files: MVideoFile[]
|
files: MVideoFile[]
|
||||||
) {
|
) {
|
||||||
const trackerUrls = video.getTrackerUrls()
|
const trackerUrls = video.getTrackerUrls()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user