diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video-interface.ts | 2 | ||||
-rw-r--r-- | server/models/video/video.ts | 75 |
2 files changed, 44 insertions, 33 deletions
diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts index 1402df26a..86ce84dd9 100644 --- a/server/models/video/video-interface.ts +++ b/server/models/video/video-interface.ts | |||
@@ -18,7 +18,6 @@ export namespace VideoMethods { | |||
18 | export type ToFormattedJSON = (this: VideoInstance) => FormattedVideo | 18 | export type ToFormattedJSON = (this: VideoInstance) => FormattedVideo |
19 | 19 | ||
20 | export type GetOriginalFile = (this: VideoInstance) => VideoFileInstance | 20 | export type GetOriginalFile = (this: VideoInstance) => VideoFileInstance |
21 | export type GenerateMagnetUri = (this: VideoInstance, videoFile: VideoFileInstance) => string | ||
22 | export type GetTorrentFileName = (this: VideoInstance, videoFile: VideoFileInstance) => string | 21 | export type GetTorrentFileName = (this: VideoInstance, videoFile: VideoFileInstance) => string |
23 | export type GetVideoFilename = (this: VideoInstance, videoFile: VideoFileInstance) => string | 22 | export type GetVideoFilename = (this: VideoInstance, videoFile: VideoFileInstance) => string |
24 | export type CreatePreview = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<string> | 23 | export type CreatePreview = (this: VideoInstance, videoFile: VideoFileInstance) => Promise<string> |
@@ -108,7 +107,6 @@ export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.In | |||
108 | createThumbnail: VideoMethods.CreateThumbnail | 107 | createThumbnail: VideoMethods.CreateThumbnail |
109 | createTorrentAndSetInfoHash: VideoMethods.CreateTorrentAndSetInfoHash | 108 | createTorrentAndSetInfoHash: VideoMethods.CreateTorrentAndSetInfoHash |
110 | getOriginalFile: VideoMethods.GetOriginalFile | 109 | getOriginalFile: VideoMethods.GetOriginalFile |
111 | generateMagnetUri: VideoMethods.GenerateMagnetUri | ||
112 | getPreviewName: VideoMethods.GetPreviewName | 110 | getPreviewName: VideoMethods.GetPreviewName |
113 | getPreviewPath: VideoMethods.GetPreviewPath | 111 | getPreviewPath: VideoMethods.GetPreviewPath |
114 | getThumbnailName: VideoMethods.GetThumbnailName | 112 | getThumbnailName: VideoMethods.GetThumbnailName |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 4bd8eb98f..0b1af4d21 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -52,7 +52,6 @@ import { PREVIEWS_SIZE } from '../../initializers/constants' | |||
52 | 52 | ||
53 | let Video: Sequelize.Model<VideoInstance, VideoAttributes> | 53 | let Video: Sequelize.Model<VideoInstance, VideoAttributes> |
54 | let getOriginalFile: VideoMethods.GetOriginalFile | 54 | let getOriginalFile: VideoMethods.GetOriginalFile |
55 | let generateMagnetUri: VideoMethods.GenerateMagnetUri | ||
56 | let getVideoFilename: VideoMethods.GetVideoFilename | 55 | let getVideoFilename: VideoMethods.GetVideoFilename |
57 | let getThumbnailName: VideoMethods.GetThumbnailName | 56 | let getThumbnailName: VideoMethods.GetThumbnailName |
58 | let getThumbnailPath: VideoMethods.GetThumbnailPath | 57 | let getThumbnailPath: VideoMethods.GetThumbnailPath |
@@ -254,7 +253,6 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da | |||
254 | createPreview, | 253 | createPreview, |
255 | createThumbnail, | 254 | createThumbnail, |
256 | createTorrentAndSetInfoHash, | 255 | createTorrentAndSetInfoHash, |
257 | generateMagnetUri, | ||
258 | getPreviewName, | 256 | getPreviewName, |
259 | getPreviewPath, | 257 | getPreviewPath, |
260 | getThumbnailName, | 258 | getThumbnailName, |
@@ -426,33 +424,6 @@ createTorrentAndSetInfoHash = function (this: VideoInstance, videoFile: VideoFil | |||
426 | }) | 424 | }) |
427 | } | 425 | } |
428 | 426 | ||
429 | generateMagnetUri = function (this: VideoInstance, videoFile: VideoFileInstance) { | ||
430 | let baseUrlHttp | ||
431 | let baseUrlWs | ||
432 | |||
433 | if (this.isOwned()) { | ||
434 | baseUrlHttp = CONFIG.WEBSERVER.URL | ||
435 | baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT | ||
436 | } else { | ||
437 | baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + this.Author.Pod.host | ||
438 | baseUrlWs = REMOTE_SCHEME.WS + '://' + this.Author.Pod.host | ||
439 | } | ||
440 | |||
441 | const xs = baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentFileName(videoFile) | ||
442 | const announce = [ baseUrlWs + '/tracker/socket' ] | ||
443 | const urlList = [ baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) ] | ||
444 | |||
445 | const magnetHash = { | ||
446 | xs, | ||
447 | announce, | ||
448 | urlList, | ||
449 | infoHash: videoFile.infoHash, | ||
450 | name: this.name | ||
451 | } | ||
452 | |||
453 | return magnetUtil.encode(magnetHash) | ||
454 | } | ||
455 | |||
456 | getEmbedPath = function (this: VideoInstance) { | 427 | getEmbedPath = function (this: VideoInstance) { |
457 | return '/videos/embed/' + this.uuid | 428 | return '/videos/embed/' + this.uuid |
458 | } | 429 | } |
@@ -516,6 +487,7 @@ toFormattedJSON = function (this: VideoInstance) { | |||
516 | } | 487 | } |
517 | 488 | ||
518 | // Format and sort video files | 489 | // Format and sort video files |
490 | const { baseUrlHttp, baseUrlWs } = getBaseUrls(this) | ||
519 | json.files = this.VideoFiles | 491 | json.files = this.VideoFiles |
520 | .map(videoFile => { | 492 | .map(videoFile => { |
521 | let resolutionLabel = videoFile.resolution + 'p' | 493 | let resolutionLabel = videoFile.resolution + 'p' |
@@ -523,8 +495,10 @@ toFormattedJSON = function (this: VideoInstance) { | |||
523 | const videoFileJson = { | 495 | const videoFileJson = { |
524 | resolution: videoFile.resolution, | 496 | resolution: videoFile.resolution, |
525 | resolutionLabel, | 497 | resolutionLabel, |
526 | magnetUri: this.generateMagnetUri(videoFile), | 498 | magnetUri: generateMagnetUri(this, videoFile, baseUrlHttp, baseUrlWs), |
527 | size: videoFile.size | 499 | size: videoFile.size, |
500 | torrentUrl: getTorrentUrl(this, videoFile, baseUrlHttp), | ||
501 | fileUrl: getVideoFileUrl(this, videoFile, baseUrlHttp) | ||
528 | } | 502 | } |
529 | 503 | ||
530 | return videoFileJson | 504 | return videoFileJson |
@@ -972,3 +946,42 @@ function createBaseVideosWhere () { | |||
972 | } | 946 | } |
973 | } | 947 | } |
974 | } | 948 | } |
949 | |||
950 | function getBaseUrls (video: VideoInstance) { | ||
951 | let baseUrlHttp | ||
952 | let baseUrlWs | ||
953 | |||
954 | if (video.isOwned()) { | ||
955 | baseUrlHttp = CONFIG.WEBSERVER.URL | ||
956 | baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT | ||
957 | } else { | ||
958 | baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + video.Author.Pod.host | ||
959 | baseUrlWs = REMOTE_SCHEME.WS + '://' + video.Author.Pod.host | ||
960 | } | ||
961 | |||
962 | return { baseUrlHttp, baseUrlWs } | ||
963 | } | ||
964 | |||
965 | function getTorrentUrl (video: VideoInstance, videoFile: VideoFileInstance, baseUrlHttp: string) { | ||
966 | return baseUrlHttp + STATIC_PATHS.TORRENTS + video.getTorrentFileName(videoFile) | ||
967 | } | ||
968 | |||
969 | function getVideoFileUrl (video: VideoInstance, videoFile: VideoFileInstance, baseUrlHttp: string) { | ||
970 | return baseUrlHttp + STATIC_PATHS.WEBSEED + video.getVideoFilename(videoFile) | ||
971 | } | ||
972 | |||
973 | function generateMagnetUri (video: VideoInstance, videoFile: VideoFileInstance, baseUrlHttp: string, baseUrlWs: string) { | ||
974 | const xs = getTorrentUrl(video, videoFile, baseUrlHttp) | ||
975 | const announce = [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ] | ||
976 | const urlList = [ getVideoFileUrl(video, videoFile, baseUrlHttp) ] | ||
977 | |||
978 | const magnetHash = { | ||
979 | xs, | ||
980 | announce, | ||
981 | urlList, | ||
982 | infoHash: videoFile.infoHash, | ||
983 | name: video.name | ||
984 | } | ||
985 | |||
986 | return magnetUtil.encode(magnetHash) | ||
987 | } | ||