aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-18 11:28:00 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-02-18 13:38:09 +0100
commit8efc27bf14f1fe3ed23cd8a6d2de1f0918a7f769 (patch)
tree863daf231cf4a66d9e5abf1cfe4fbe2b742cd856 /server
parentf66db4d5c851fe87bb71cccee96926000f59a15b (diff)
downloadPeerTube-8efc27bf14f1fe3ed23cd8a6d2de1f0918a7f769.tar.gz
PeerTube-8efc27bf14f1fe3ed23cd8a6d2de1f0918a7f769.tar.zst
PeerTube-8efc27bf14f1fe3ed23cd8a6d2de1f0918a7f769.zip
Cleanup
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/index.ts2
-rw-r--r--server/controllers/lazy-static.ts1
-rw-r--r--server/helpers/webtorrent.ts9
-rw-r--r--server/lib/activitypub/videos.ts2
-rw-r--r--server/lib/job-queue/handlers/video-file-import.ts2
-rw-r--r--server/lib/job-queue/handlers/video-import.ts2
-rw-r--r--server/lib/video-transcoding.ts4
-rw-r--r--server/models/video/thumbnail.ts4
-rw-r--r--server/models/video/video-caption.ts4
-rw-r--r--server/models/video/video-file.ts4
-rw-r--r--server/models/video/video-format-utils.ts6
11 files changed, 21 insertions, 19 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index dcd6194ae..e89315930 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -222,7 +222,7 @@ async function addVideo (req: express.Request, res: express.Response) {
222 }) 222 })
223 223
224 // Create the torrent file 224 // Create the torrent file
225 await createTorrentAndSetInfoHash(video, video, videoFile) 225 await createTorrentAndSetInfoHash(video, videoFile)
226 226
227 const { videoCreated } = await sequelizeTypescript.transaction(async t => { 227 const { videoCreated } = await sequelizeTypescript.transaction(async t => {
228 const sequelizeOptions = { transaction: t } 228 const sequelizeOptions = { transaction: t }
diff --git a/server/controllers/lazy-static.ts b/server/controllers/lazy-static.ts
index c2f5c7b56..4e553479b 100644
--- a/server/controllers/lazy-static.ts
+++ b/server/controllers/lazy-static.ts
@@ -94,5 +94,6 @@ async function getTorrent (req: express.Request, res: express.Response) {
94 const result = await VideosTorrentCache.Instance.getFilePath(req.params.filename) 94 const result = await VideosTorrentCache.Instance.getFilePath(req.params.filename)
95 if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404) 95 if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
96 96
97 // Torrents still use the old naming convention (video uuid + .torrent)
97 return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER }) 98 return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER })
98} 99}
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts
index 4e08c27c6..d8220ba9c 100644
--- a/server/helpers/webtorrent.ts
+++ b/server/helpers/webtorrent.ts
@@ -7,13 +7,14 @@ import * as WebTorrent from 'webtorrent'
7import { isArray } from '@server/helpers/custom-validators/misc' 7import { isArray } from '@server/helpers/custom-validators/misc'
8import { WEBSERVER } from '@server/initializers/constants' 8import { WEBSERVER } from '@server/initializers/constants'
9import { generateTorrentFileName, getVideoFilePath } from '@server/lib/video-paths' 9import { generateTorrentFileName, getVideoFilePath } from '@server/lib/video-paths'
10import { MVideo, MVideoWithHost } from '@server/types/models/video/video' 10import { MVideo } from '@server/types/models/video/video'
11import { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/video/video-file' 11import { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/video/video-file'
12import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist' 12import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist'
13import { CONFIG } from '../initializers/config' 13import { CONFIG } from '../initializers/config'
14import { promisify2 } from './core-utils' 14import { promisify2 } from './core-utils'
15import { logger } from './logger' 15import { logger } from './logger'
16import { generateVideoImportTmpPath } from './utils' 16import { generateVideoImportTmpPath } from './utils'
17import { extractVideo } from './video'
17 18
18const createTorrentPromise = promisify2<string, any, any>(createTorrent) 19const createTorrentPromise = promisify2<string, any, any>(createTorrent)
19 20
@@ -77,12 +78,12 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName
77 }) 78 })
78} 79}
79 80
80// FIXME: refactor/merge videoOrPlaylist and video arguments
81async function createTorrentAndSetInfoHash ( 81async function createTorrentAndSetInfoHash (
82 videoOrPlaylist: MVideo | MStreamingPlaylistVideo, 82 videoOrPlaylist: MVideo | MStreamingPlaylistVideo,
83 video: MVideoWithHost,
84 videoFile: MVideoFile 83 videoFile: MVideoFile
85) { 84) {
85 const video = extractVideo(videoOrPlaylist)
86
86 const options = { 87 const options = {
87 // Keep the extname, it's used by the client to stream the file inside a web browser 88 // Keep the extname, it's used by the client to stream the file inside a web browser
88 name: `${video.name} ${videoFile.resolution}p${videoFile.extname}`, 89 name: `${video.name} ${videoFile.resolution}p${videoFile.extname}`,
@@ -108,7 +109,7 @@ async function createTorrentAndSetInfoHash (
108} 109}
109 110
110function generateMagnetUri ( 111function generateMagnetUri (
111 video: MVideoWithHost, 112 video: MVideo,
112 videoFile: MVideoFileRedundanciesOpt, 113 videoFile: MVideoFileRedundanciesOpt,
113 trackerUrls: string[] 114 trackerUrls: string[]
114) { 115) {
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 66330a964..c38edad56 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -912,7 +912,7 @@ function getTrackerUrls (object: VideoObject, video: MVideoWithHost) {
912 912
913 const trackers = object.url.filter(u => isAPVideoTrackerUrlObject(u)) 913 const trackers = object.url.filter(u => isAPVideoTrackerUrlObject(u))
914 .map((u: ActivityTrackerUrlObject) => { 914 .map((u: ActivityTrackerUrlObject) => {
915 if (u.rel.includes('websocket')) wsFound = true 915 if (isArray(u.rel) && u.rel.includes('websocket')) wsFound = true
916 916
917 return u.href 917 return u.href
918 }) 918 })
diff --git a/server/lib/job-queue/handlers/video-file-import.ts b/server/lib/job-queue/handlers/video-file-import.ts
index 839916306..71f2cafcd 100644
--- a/server/lib/job-queue/handlers/video-file-import.ts
+++ b/server/lib/job-queue/handlers/video-file-import.ts
@@ -82,7 +82,7 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) {
82 await copy(inputFilePath, outputPath) 82 await copy(inputFilePath, outputPath)
83 83
84 video.VideoFiles.push(newVideoFile) 84 video.VideoFiles.push(newVideoFile)
85 await createTorrentAndSetInfoHash(video, video, newVideoFile) 85 await createTorrentAndSetInfoHash(video, newVideoFile)
86 86
87 await newVideoFile.save() 87 await newVideoFile.save()
88} 88}
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index 8fa024105..ed2c5eac0 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -185,7 +185,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: MVid
185 } 185 }
186 186
187 // Create torrent 187 // Create torrent
188 await createTorrentAndSetInfoHash(videoImportWithFiles.Video, videoImportWithFiles.Video, videoFile) 188 await createTorrentAndSetInfoHash(videoImportWithFiles.Video, videoFile)
189 189
190 const videoFileSave = videoFile.toJSON() 190 const videoFileSave = videoFile.toJSON()
191 191
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts
index e3cd18e25..c949dca2e 100644
--- a/server/lib/video-transcoding.ts
+++ b/server/lib/video-transcoding.ts
@@ -254,7 +254,7 @@ async function onWebTorrentVideoFileTranscoding (
254 videoFile.fps = fps 254 videoFile.fps = fps
255 videoFile.metadata = metadata 255 videoFile.metadata = metadata
256 256
257 await createTorrentAndSetInfoHash(video, video, videoFile) 257 await createTorrentAndSetInfoHash(video, videoFile)
258 258
259 await VideoFileModel.customUpsert(videoFile, 'video', undefined) 259 await VideoFileModel.customUpsert(videoFile, 'video', undefined)
260 video.VideoFiles = await video.$get('VideoFiles') 260 video.VideoFiles = await video.$get('VideoFiles')
@@ -350,7 +350,7 @@ async function generateHlsPlaylistCommon (options: {
350 newVideoFile.fps = await getVideoFileFPS(videoFilePath) 350 newVideoFile.fps = await getVideoFileFPS(videoFilePath)
351 newVideoFile.metadata = await getMetadataFromFile(videoFilePath) 351 newVideoFile.metadata = await getMetadataFromFile(videoFilePath)
352 352
353 await createTorrentAndSetInfoHash(videoStreamingPlaylist, video, newVideoFile) 353 await createTorrentAndSetInfoHash(videoStreamingPlaylist, newVideoFile)
354 354
355 await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined) 355 await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined)
356 videoStreamingPlaylist.VideoFiles = await videoStreamingPlaylist.$get('VideoFiles') 356 videoStreamingPlaylist.VideoFiles = await videoStreamingPlaylist.$get('VideoFiles')
diff --git a/server/models/video/thumbnail.ts b/server/models/video/thumbnail.ts
index 319e1175a..f1187c8d6 100644
--- a/server/models/video/thumbnail.ts
+++ b/server/models/video/thumbnail.ts
@@ -16,7 +16,7 @@ import {
16 UpdatedAt 16 UpdatedAt
17} from 'sequelize-typescript' 17} from 'sequelize-typescript'
18import { afterCommitIfTransaction } from '@server/helpers/database-utils' 18import { afterCommitIfTransaction } from '@server/helpers/database-utils'
19import { MThumbnail, MThumbnailVideo, MVideoWithHost } from '@server/types/models' 19import { MThumbnail, MThumbnailVideo, MVideo } from '@server/types/models'
20import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' 20import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
21import { logger } from '../../helpers/logger' 21import { logger } from '../../helpers/logger'
22import { CONFIG } from '../../initializers/config' 22import { CONFIG } from '../../initializers/config'
@@ -163,7 +163,7 @@ export class ThumbnailModel extends Model {
163 return join(directory, filename) 163 return join(directory, filename)
164 } 164 }
165 165
166 getFileUrl (video: MVideoWithHost) { 166 getFileUrl (video: MVideo) {
167 const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename 167 const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename
168 168
169 if (video.isOwned()) return WEBSERVER.URL + staticPath 169 if (video.isOwned()) return WEBSERVER.URL + staticPath
diff --git a/server/models/video/video-caption.ts b/server/models/video/video-caption.ts
index 0bbe9b752..bfdec73e9 100644
--- a/server/models/video/video-caption.ts
+++ b/server/models/video/video-caption.ts
@@ -16,7 +16,7 @@ import {
16 UpdatedAt 16 UpdatedAt
17} from 'sequelize-typescript' 17} from 'sequelize-typescript'
18import { v4 as uuidv4 } from 'uuid' 18import { v4 as uuidv4 } from 'uuid'
19import { MVideoCaption, MVideoCaptionFormattable, MVideoCaptionVideo, MVideoWithHost } from '@server/types/models' 19import { MVideo, MVideoCaption, MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/types/models'
20import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model' 20import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model'
21import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions' 21import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions'
22import { logger } from '../../helpers/logger' 22import { logger } from '../../helpers/logger'
@@ -203,7 +203,7 @@ export class VideoCaptionModel extends Model {
203 return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.filename) 203 return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.filename)
204 } 204 }
205 205
206 getFileUrl (video: MVideoWithHost) { 206 getFileUrl (video: MVideo) {
207 if (!this.Video) this.Video = video as VideoModel 207 if (!this.Video) this.Video = video as VideoModel
208 208
209 if (video.isOwned()) return WEBSERVER.URL + this.getCaptionStaticPath() 209 if (video.isOwned()) return WEBSERVER.URL + this.getCaptionStaticPath()
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
index 5a3706259..4df2c20bc 100644
--- a/server/models/video/video-file.ts
+++ b/server/models/video/video-file.ts
@@ -423,7 +423,7 @@ export class VideoFileModel extends Model {
423 return !!this.videoStreamingPlaylistId 423 return !!this.videoStreamingPlaylistId
424 } 424 }
425 425
426 getFileUrl (video: MVideoWithHost) { 426 getFileUrl (video: MVideo) {
427 if (!this.Video) this.Video = video as VideoModel 427 if (!this.Video) this.Video = video as VideoModel
428 428
429 if (video.isOwned()) return WEBSERVER.URL + this.getFileStaticPath(video) 429 if (video.isOwned()) return WEBSERVER.URL + this.getFileStaticPath(video)
@@ -449,7 +449,7 @@ export class VideoFileModel extends Model {
449 return buildRemoteVideoBaseUrl(video, path) 449 return buildRemoteVideoBaseUrl(video, path)
450 } 450 }
451 451
452 getRemoteTorrentUrl (video: MVideoWithHost) { 452 getRemoteTorrentUrl (video: MVideo) {
453 if (video.isOwned()) throw new Error(`Video ${video.url} is not a remote video`) 453 if (video.isOwned()) throw new Error(`Video ${video.url} is not a remote video`)
454 454
455 return this.torrentUrl 455 return this.torrentUrl
diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts
index 455597d22..a6a1a4f0d 100644
--- a/server/models/video/video-format-utils.ts
+++ b/server/models/video/video-format-utils.ts
@@ -14,11 +14,11 @@ import {
14} from '../../lib/activitypub/url' 14} from '../../lib/activitypub/url'
15import { 15import {
16 MStreamingPlaylistRedundanciesOpt, 16 MStreamingPlaylistRedundanciesOpt,
17 MVideo,
17 MVideoAP, 18 MVideoAP,
18 MVideoFile, 19 MVideoFile,
19 MVideoFormattable, 20 MVideoFormattable,
20 MVideoFormattableDetails, 21 MVideoFormattableDetails
21 MVideoWithHost
22} from '../../types/models' 22} from '../../types/models'
23import { MVideoFileRedundanciesOpt } from '../../types/models/video/video-file' 23import { MVideoFileRedundanciesOpt } from '../../types/models/video/video-file'
24import { VideoModel } from './video' 24import { VideoModel } from './video'
@@ -225,7 +225,7 @@ function videoFilesModelToFormattedJSON (
225 225
226function addVideoFilesInAPAcc ( 226function addVideoFilesInAPAcc (
227 acc: ActivityUrlObject[] | ActivityTagObject[], 227 acc: ActivityUrlObject[] | ActivityTagObject[],
228 video: MVideoWithHost, 228 video: MVideo,
229 files: MVideoFile[] 229 files: MVideoFile[]
230) { 230) {
231 const trackerUrls = video.getTrackerUrls() 231 const trackerUrls = video.getTrackerUrls()