]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Cleanup
authorChocobozzz <me@florianbigard.com>
Thu, 18 Feb 2021 10:28:00 +0000 (11:28 +0100)
committerChocobozzz <chocobozzz@cpy.re>
Thu, 18 Feb 2021 12:38:09 +0000 (13:38 +0100)
13 files changed:
scripts/optimize-old-videos.ts
scripts/update-host.ts
server/controllers/api/videos/index.ts
server/controllers/lazy-static.ts
server/helpers/webtorrent.ts
server/lib/activitypub/videos.ts
server/lib/job-queue/handlers/video-file-import.ts
server/lib/job-queue/handlers/video-import.ts
server/lib/video-transcoding.ts
server/models/video/thumbnail.ts
server/models/video/video-caption.ts
server/models/video/video-file.ts
server/models/video/video-format-utils.ts

index 8e2e7fcf4b9b3b1f445f76875fdbdf36b3eb1213..01d30244fb62fe5f58bf73064f404791735ed35b 100644 (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()
       }
     }
index d0a1b03cce93cd1f83b46a50c92176955694f715..e497be4e2614b54d122d97c6d1452e54f9195e21 100755 (executable)
@@ -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) {
index dcd6194ae96f41b298b1480bd265d041e75ae14e..e89315930c9355542e69e7fb0f9eca42cb0d308d 100644 (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 }
index c2f5c7b568781ea51143e50fbb5a1ba3bcd74f58..4e553479b658f109947b7f5196e2d5a1f9a55611 100644 (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 })
 }
index 4e08c27c6735005c14f51af36d6b27d3431a10c8..d8220ba9c6583e3acb13e8ec7de8ba306a8fd983 100644 (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[]
 ) {
index 66330a9649beb40233b9a77cbdb4878ed85ecbd3..c38edad56dad3980d8fde2b15f5fb8147ce981a0 100644 (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
     })
index 8399163069e2c7b5dd2ef678223793afacd83354..71f2cafcd79003b7d223f6044ab3e3920b1be597 100644 (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()
 }
index 8fa024105839c198138dbb1c78e3f23333031e83..ed2c5eac0f861101a3e587de9fbc27d753a19317 100644 (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()
 
index e3cd18e2536690d45629956a425e1a5ebd6e5fe8..c949dca2ef035c4b7eb4b4db78624b14f1105242 100644 (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')
index 319e1175ae4da4cddca45fb119dfc6c8688f825c..f1187c8d65cab588cbcba6db7b9816ae7801db10 100644 (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
index 0bbe9b752895223ea64ca0e2ae6bcff3afaec01b..bfdec73e9849012947ab2af3ad88e19dbb43f80b 100644 (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()
index 5a37062590a0aa9b9e481c9ba101a53566d91d88..4df2c20bc4a3af908175cf886bcbf533147f6d2c 100644 (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
index 455597d22e1ffad314802047ce42805d5817f80e..a6a1a4f0d864bde3f87b1b58ba4b56df90f9b8eb 100644 (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()