diff options
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 2e6b6aeec..9e67ca0f4 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -60,7 +60,6 @@ import { | |||
60 | API_VERSION, | 60 | API_VERSION, |
61 | CONSTRAINTS_FIELDS, | 61 | CONSTRAINTS_FIELDS, |
62 | LAZY_STATIC_PATHS, | 62 | LAZY_STATIC_PATHS, |
63 | REMOTE_SCHEME, | ||
64 | STATIC_PATHS, | 63 | STATIC_PATHS, |
65 | VIDEO_CATEGORIES, | 64 | VIDEO_CATEGORIES, |
66 | VIDEO_LANGUAGES, | 65 | VIDEO_LANGUAGES, |
@@ -107,6 +106,8 @@ import { ActorModel } from '../activitypub/actor' | |||
107 | import { AvatarModel } from '../avatar/avatar' | 106 | import { AvatarModel } from '../avatar/avatar' |
108 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' | 107 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' |
109 | import { ServerModel } from '../server/server' | 108 | import { ServerModel } from '../server/server' |
109 | import { TrackerModel } from '../server/tracker' | ||
110 | import { VideoTrackerModel } from '../server/video-tracker' | ||
110 | import { buildTrigramSearchIndex, buildWhereIdOrUUID, getVideoSort, isOutdated, throwIfNotValid } from '../utils' | 111 | import { buildTrigramSearchIndex, buildWhereIdOrUUID, getVideoSort, isOutdated, throwIfNotValid } from '../utils' |
111 | import { ScheduleVideoUpdateModel } from './schedule-video-update' | 112 | import { ScheduleVideoUpdateModel } from './schedule-video-update' |
112 | import { TagModel } from './tag' | 113 | import { TagModel } from './tag' |
@@ -137,6 +138,7 @@ export enum ScopeNames { | |||
137 | FOR_API = 'FOR_API', | 138 | FOR_API = 'FOR_API', |
138 | WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', | 139 | WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', |
139 | WITH_TAGS = 'WITH_TAGS', | 140 | WITH_TAGS = 'WITH_TAGS', |
141 | WITH_TRACKERS = 'WITH_TRACKERS', | ||
140 | WITH_WEBTORRENT_FILES = 'WITH_WEBTORRENT_FILES', | 142 | WITH_WEBTORRENT_FILES = 'WITH_WEBTORRENT_FILES', |
141 | WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE', | 143 | WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE', |
142 | WITH_BLACKLISTED = 'WITH_BLACKLISTED', | 144 | WITH_BLACKLISTED = 'WITH_BLACKLISTED', |
@@ -320,6 +322,14 @@ export type AvailableForListIDsOptions = { | |||
320 | [ScopeNames.WITH_TAGS]: { | 322 | [ScopeNames.WITH_TAGS]: { |
321 | include: [ TagModel ] | 323 | include: [ TagModel ] |
322 | }, | 324 | }, |
325 | [ScopeNames.WITH_TRACKERS]: { | ||
326 | include: [ | ||
327 | { | ||
328 | attributes: [ 'id', 'url' ], | ||
329 | model: TrackerModel | ||
330 | } | ||
331 | ] | ||
332 | }, | ||
323 | [ScopeNames.WITH_BLACKLISTED]: { | 333 | [ScopeNames.WITH_BLACKLISTED]: { |
324 | include: [ | 334 | include: [ |
325 | { | 335 | { |
@@ -616,6 +626,13 @@ export class VideoModel extends Model { | |||
616 | }) | 626 | }) |
617 | Tags: TagModel[] | 627 | Tags: TagModel[] |
618 | 628 | ||
629 | @BelongsToMany(() => TrackerModel, { | ||
630 | foreignKey: 'videoId', | ||
631 | through: () => VideoTrackerModel, | ||
632 | onDelete: 'CASCADE' | ||
633 | }) | ||
634 | Trackers: TrackerModel[] | ||
635 | |||
619 | @HasMany(() => ThumbnailModel, { | 636 | @HasMany(() => ThumbnailModel, { |
620 | foreignKey: { | 637 | foreignKey: { |
621 | name: 'videoId', | 638 | name: 'videoId', |
@@ -1436,6 +1453,7 @@ export class VideoModel extends Model { | |||
1436 | ScopeNames.WITH_SCHEDULED_UPDATE, | 1453 | ScopeNames.WITH_SCHEDULED_UPDATE, |
1437 | ScopeNames.WITH_THUMBNAILS, | 1454 | ScopeNames.WITH_THUMBNAILS, |
1438 | ScopeNames.WITH_LIVE, | 1455 | ScopeNames.WITH_LIVE, |
1456 | ScopeNames.WITH_TRACKERS, | ||
1439 | { method: [ ScopeNames.WITH_WEBTORRENT_FILES, true ] }, | 1457 | { method: [ ScopeNames.WITH_WEBTORRENT_FILES, true ] }, |
1440 | { method: [ ScopeNames.WITH_STREAMING_PLAYLISTS, true ] } | 1458 | { method: [ ScopeNames.WITH_STREAMING_PLAYLISTS, true ] } |
1441 | ] | 1459 | ] |
@@ -1887,18 +1905,15 @@ export class VideoModel extends Model { | |||
1887 | } | 1905 | } |
1888 | 1906 | ||
1889 | getFormattedVideoFilesJSON (): VideoFile[] { | 1907 | getFormattedVideoFilesJSON (): VideoFile[] { |
1890 | const { baseUrlHttp, baseUrlWs } = this.getBaseUrls() | ||
1891 | let files: VideoFile[] = [] | 1908 | let files: VideoFile[] = [] |
1892 | 1909 | ||
1893 | if (Array.isArray(this.VideoFiles)) { | 1910 | if (Array.isArray(this.VideoFiles)) { |
1894 | const result = videoFilesModelToFormattedJSON(this, this, baseUrlHttp, baseUrlWs, this.VideoFiles) | 1911 | const result = videoFilesModelToFormattedJSON(this, this.VideoFiles) |
1895 | files = files.concat(result) | 1912 | files = files.concat(result) |
1896 | } | 1913 | } |
1897 | 1914 | ||
1898 | for (const p of (this.VideoStreamingPlaylists || [])) { | 1915 | for (const p of (this.VideoStreamingPlaylists || [])) { |
1899 | p.Video = this | 1916 | const result = videoFilesModelToFormattedJSON(this, p.VideoFiles) |
1900 | |||
1901 | const result = videoFilesModelToFormattedJSON(p, this, baseUrlHttp, baseUrlWs, p.VideoFiles) | ||
1902 | files = files.concat(result) | 1917 | files = files.concat(result) |
1903 | } | 1918 | } |
1904 | 1919 | ||
@@ -2030,25 +2045,18 @@ export class VideoModel extends Model { | |||
2030 | return false | 2045 | return false |
2031 | } | 2046 | } |
2032 | 2047 | ||
2033 | getBaseUrls () { | 2048 | getBandwidthBits (videoFile: MVideoFile) { |
2034 | if (this.isOwned()) { | 2049 | return Math.ceil((videoFile.size * 8) / this.duration) |
2035 | return { | ||
2036 | baseUrlHttp: WEBSERVER.URL, | ||
2037 | baseUrlWs: WEBSERVER.WS + '://' + WEBSERVER.HOSTNAME + ':' + WEBSERVER.PORT | ||
2038 | } | ||
2039 | } | ||
2040 | |||
2041 | return { | ||
2042 | baseUrlHttp: REMOTE_SCHEME.HTTP + '://' + this.VideoChannel.Account.Actor.Server.host, | ||
2043 | baseUrlWs: REMOTE_SCHEME.WS + '://' + this.VideoChannel.Account.Actor.Server.host | ||
2044 | } | ||
2045 | } | 2050 | } |
2046 | 2051 | ||
2047 | getTrackerUrls (baseUrlHttp: string, baseUrlWs: string) { | 2052 | getTrackerUrls () { |
2048 | return [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ] | 2053 | if (this.isOwned()) { |
2049 | } | 2054 | return [ |
2055 | WEBSERVER.URL + '/tracker/announce', | ||
2056 | WEBSERVER.WS + '://' + WEBSERVER.HOSTNAME + ':' + WEBSERVER.PORT + '/tracker/socket' | ||
2057 | ] | ||
2058 | } | ||
2050 | 2059 | ||
2051 | getBandwidthBits (videoFile: MVideoFile) { | 2060 | return this.Trackers.map(t => t.url) |
2052 | return Math.ceil((videoFile.size * 8) / this.duration) | ||
2053 | } | 2061 | } |
2054 | } | 2062 | } |