aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/schedule-video-update.ts3
-rw-r--r--server/models/video/video-abuse.ts4
-rw-r--r--server/models/video/video-blacklist.ts4
-rw-r--r--server/models/video/video-caption.ts10
-rw-r--r--server/models/video/video-change-ownership.ts4
-rw-r--r--server/models/video/video-channel.ts30
-rw-r--r--server/models/video/video-comment.ts3
-rw-r--r--server/models/video/video-format-utils.ts6
-rw-r--r--server/models/video/video-import.ts4
-rw-r--r--server/models/video/video-playlist-element.ts19
-rw-r--r--server/models/video/video-playlist.ts3
-rw-r--r--server/models/video/video.ts11
12 files changed, 56 insertions, 45 deletions
diff --git a/server/models/video/schedule-video-update.ts b/server/models/video/schedule-video-update.ts
index 603d55692..fc2a424aa 100644
--- a/server/models/video/schedule-video-update.ts
+++ b/server/models/video/schedule-video-update.ts
@@ -2,6 +2,7 @@ import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Ta
2import { ScopeNames as VideoScopeNames, VideoModel } from './video' 2import { ScopeNames as VideoScopeNames, VideoModel } from './video'
3import { VideoPrivacy } from '../../../shared/models/videos' 3import { VideoPrivacy } from '../../../shared/models/videos'
4import { Op, Transaction } from 'sequelize' 4import { Op, Transaction } from 'sequelize'
5import { MScheduleVideoUpdateFormattable } from '@server/typings/models'
5 6
6@Table({ 7@Table({
7 tableName: 'scheduleVideoUpdate', 8 tableName: 'scheduleVideoUpdate',
@@ -96,7 +97,7 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> {
96 return ScheduleVideoUpdateModel.destroy(query) 97 return ScheduleVideoUpdateModel.destroy(query)
97 } 98 }
98 99
99 toFormattedJSON () { 100 toFormattedJSON (this: MScheduleVideoUpdateFormattable) {
100 return { 101 return {
101 updateAt: this.updateAt, 102 updateAt: this.updateAt,
102 privacy: this.privacy || undefined 103 privacy: this.privacy || undefined
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index af7b40d11..6ef1a915d 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -11,7 +11,7 @@ import { getSort, throwIfNotValid } from '../utils'
11import { VideoModel } from './video' 11import { VideoModel } from './video'
12import { VideoAbuseState } from '../../../shared' 12import { VideoAbuseState } from '../../../shared'
13import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' 13import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants'
14import { MVideoAbuse, MVideoAbuseAccountVideo, MVideoAbuseVideo } from '../../typings/models' 14import { MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models'
15import * as Bluebird from 'bluebird' 15import * as Bluebird from 'bluebird'
16 16
17@Table({ 17@Table({
@@ -108,7 +108,7 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
108 }) 108 })
109 } 109 }
110 110
111 toFormattedJSON (this: MVideoAbuseAccountVideo): VideoAbuse { 111 toFormattedJSON (this: MVideoAbuseFormattable): VideoAbuse {
112 return { 112 return {
113 id: this.id, 113 id: this.id,
114 reason: this.reason, 114 reason: this.reason,
diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts
index 5a0cac94a..b4df6cd6a 100644
--- a/server/models/video/video-blacklist.ts
+++ b/server/models/video/video-blacklist.ts
@@ -8,7 +8,7 @@ import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
8import { FindOptions } from 'sequelize' 8import { FindOptions } from 'sequelize'
9import { ThumbnailModel } from './thumbnail' 9import { ThumbnailModel } from './thumbnail'
10import * as Bluebird from 'bluebird' 10import * as Bluebird from 'bluebird'
11import { MVideoBlacklist } from '@server/typings/models' 11import { MVideoBlacklist, MVideoBlacklistFormattable } from '@server/typings/models'
12 12
13@Table({ 13@Table({
14 tableName: 'videoBlacklist', 14 tableName: 'videoBlacklist',
@@ -111,7 +111,7 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
111 return VideoBlacklistModel.findOne(query) 111 return VideoBlacklistModel.findOne(query)
112 } 112 }
113 113
114 toFormattedJSON (): VideoBlacklist { 114 toFormattedJSON (this: MVideoBlacklistFormattable): VideoBlacklist {
115 return { 115 return {
116 id: this.id, 116 id: this.id,
117 createdAt: this.createdAt, 117 createdAt: this.createdAt,
diff --git a/server/models/video/video-caption.ts b/server/models/video/video-caption.ts
index 9ce350d12..ad5801768 100644
--- a/server/models/video/video-caption.ts
+++ b/server/models/video/video-caption.ts
@@ -22,7 +22,7 @@ import { logger } from '../../helpers/logger'
22import { remove } from 'fs-extra' 22import { remove } from 'fs-extra'
23import { CONFIG } from '../../initializers/config' 23import { CONFIG } from '../../initializers/config'
24import * as Bluebird from 'bluebird' 24import * as Bluebird from 'bluebird'
25import { MVideoCaptionVideo } from '@server/typings/models' 25import { MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/typings/models'
26 26
27export enum ScopeNames { 27export enum ScopeNames {
28 WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE' 28 WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE'
@@ -154,7 +154,7 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> {
154 return this.Video.remote === false 154 return this.Video.remote === false
155 } 155 }
156 156
157 toFormattedJSON (): VideoCaption { 157 toFormattedJSON (this: MVideoCaptionFormattable): VideoCaption {
158 return { 158 return {
159 language: { 159 language: {
160 id: this.language, 160 id: this.language,
@@ -164,15 +164,15 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> {
164 } 164 }
165 } 165 }
166 166
167 getCaptionStaticPath () { 167 getCaptionStaticPath (this: MVideoCaptionFormattable) {
168 return join(LAZY_STATIC_PATHS.VIDEO_CAPTIONS, this.getCaptionName()) 168 return join(LAZY_STATIC_PATHS.VIDEO_CAPTIONS, this.getCaptionName())
169 } 169 }
170 170
171 getCaptionName () { 171 getCaptionName (this: MVideoCaptionFormattable) {
172 return `${this.Video.uuid}-${this.language}.vtt` 172 return `${this.Video.uuid}-${this.language}.vtt`
173 } 173 }
174 174
175 removeCaptionFile () { 175 removeCaptionFile (this: MVideoCaptionFormattable) {
176 return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.getCaptionName()) 176 return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.getCaptionName())
177 } 177 }
178} 178}
diff --git a/server/models/video/video-change-ownership.ts b/server/models/video/video-change-ownership.ts
index 2d0ff48fb..f7a351329 100644
--- a/server/models/video/video-change-ownership.ts
+++ b/server/models/video/video-change-ownership.ts
@@ -3,7 +3,7 @@ import { AccountModel } from '../account/account'
3import { ScopeNames as VideoScopeNames, VideoModel } from './video' 3import { ScopeNames as VideoScopeNames, VideoModel } from './video'
4import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos' 4import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos'
5import { getSort } from '../utils' 5import { getSort } from '../utils'
6import { MVideoChangeOwnershipFull } from '@server/typings/models/video/video-change-ownership' 6import { MVideoChangeOwnershipFormattable, MVideoChangeOwnershipFull } from '@server/typings/models/video/video-change-ownership'
7import * as Bluebird from 'bluebird' 7import * as Bluebird from 'bluebird'
8 8
9enum ScopeNames { 9enum ScopeNames {
@@ -119,7 +119,7 @@ export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel>
119 .findByPk(id) 119 .findByPk(id)
120 } 120 }
121 121
122 toFormattedJSON (): VideoChangeOwnership { 122 toFormattedJSON (this: MVideoChangeOwnershipFormattable): VideoChangeOwnership {
123 return { 123 return {
124 id: this.id, 124 id: this.id,
125 status: this.status, 125 status: this.status,
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index b6a60827f..7a4df516a 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -37,7 +37,7 @@ import * as Bluebird from 'bluebird'
37import { 37import {
38 MChannelAccountDefault, 38 MChannelAccountDefault,
39 MChannelActor, 39 MChannelActor,
40 MChannelActorAccountDefaultVideos 40 MChannelActorAccountDefaultVideos, MChannelSummaryFormattable, MChannelFormattable
41} from '../../typings/models/video' 41} from '../../typings/models/video'
42 42
43// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation 43// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
@@ -482,7 +482,20 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
482 .findByPk(id, options) 482 .findByPk(id, options)
483 } 483 }
484 484
485 toFormattedJSON (): VideoChannel { 485 toFormattedSummaryJSON (this: MChannelSummaryFormattable): VideoChannelSummary {
486 const actor = this.Actor.toFormattedSummaryJSON()
487
488 return {
489 id: this.id,
490 name: actor.name,
491 displayName: this.getDisplayName(),
492 url: actor.url,
493 host: actor.host,
494 avatar: actor.avatar
495 }
496 }
497
498 toFormattedJSON (this: MChannelFormattable): VideoChannel {
486 const actor = this.Actor.toFormattedJSON() 499 const actor = this.Actor.toFormattedJSON()
487 const videoChannel = { 500 const videoChannel = {
488 id: this.id, 501 id: this.id,
@@ -500,19 +513,6 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
500 return Object.assign(actor, videoChannel) 513 return Object.assign(actor, videoChannel)
501 } 514 }
502 515
503 toFormattedSummaryJSON (): VideoChannelSummary {
504 const actor = this.Actor.toFormattedJSON()
505
506 return {
507 id: this.id,
508 name: actor.name,
509 displayName: this.getDisplayName(),
510 url: actor.url,
511 host: actor.host,
512 avatar: actor.avatar
513 }
514 }
515
516 toActivityPubObject (): ActivityPubActor { 516 toActivityPubObject (): ActivityPubActor {
517 const obj = this.Actor.toActivityPubObject(this.name, 'VideoChannel') 517 const obj = this.Actor.toActivityPubObject(this.name, 'VideoChannel')
518 518
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index c88dac1c1..84d71c553 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -17,6 +17,7 @@ import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'se
17import * as Bluebird from 'bluebird' 17import * as Bluebird from 'bluebird'
18import { 18import {
19 MComment, 19 MComment,
20 MCommentFormattable,
20 MCommentId, 21 MCommentId,
21 MCommentOwner, 22 MCommentOwner,
22 MCommentOwnerReplyVideoLight, 23 MCommentOwnerReplyVideoLight,
@@ -475,7 +476,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
475 return uniq(result) 476 return uniq(result)
476 } 477 }
477 478
478 toFormattedJSON () { 479 toFormattedJSON (this: MCommentFormattable) {
479 return { 480 return {
480 id: this.id, 481 id: this.id,
481 url: this.url, 482 url: this.url,
diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts
index 4e7eb5f0c..6aa7c1e3e 100644
--- a/server/models/video/video-format-utils.ts
+++ b/server/models/video/video-format-utils.ts
@@ -16,7 +16,7 @@ import {
16} from '../../lib/activitypub' 16} from '../../lib/activitypub'
17import { isArray } from '../../helpers/custom-validators/misc' 17import { isArray } from '../../helpers/custom-validators/misc'
18import { VideoStreamingPlaylist } from '../../../shared/models/videos/video-streaming-playlist.model' 18import { VideoStreamingPlaylist } from '../../../shared/models/videos/video-streaming-playlist.model'
19import { MVideo, MVideoAP, MVideoDetails } from '../../typings/models' 19import { MVideo, MVideoAP, MVideoFormattable, MVideoFormattableDetails } from '../../typings/models'
20import { MStreamingPlaylistRedundancies } from '../../typings/models/video/video-streaming-playlist' 20import { MStreamingPlaylistRedundancies } from '../../typings/models/video/video-streaming-playlist'
21import { MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' 21import { MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file'
22 22
@@ -29,7 +29,7 @@ export type VideoFormattingJSONOptions = {
29 blacklistInfo?: boolean 29 blacklistInfo?: boolean
30 } 30 }
31} 31}
32function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormattingJSONOptions): Video { 32function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFormattingJSONOptions): Video {
33 const userHistory = isArray(video.UserVideoHistories) ? video.UserVideoHistories[0] : undefined 33 const userHistory = isArray(video.UserVideoHistories) ? video.UserVideoHistories[0] : undefined
34 34
35 const videoObject: Video = { 35 const videoObject: Video = {
@@ -103,7 +103,7 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting
103 return videoObject 103 return videoObject
104} 104}
105 105
106function videoModelToFormattedDetailsJSON (video: MVideoDetails): VideoDetails { 106function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): VideoDetails {
107 const formattedJson = video.toFormattedJSON({ 107 const formattedJson = video.toFormattedJSON({
108 additionalAttributes: { 108 additionalAttributes: {
109 scheduledUpdate: true, 109 scheduledUpdate: true,
diff --git a/server/models/video/video-import.ts b/server/models/video/video-import.ts
index f596eea9d..af5314ce9 100644
--- a/server/models/video/video-import.ts
+++ b/server/models/video/video-import.ts
@@ -21,7 +21,7 @@ import { VideoImport, VideoImportState } from '../../../shared'
21import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos' 21import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos'
22import { UserModel } from '../account/user' 22import { UserModel } from '../account/user'
23import * as Bluebird from 'bluebird' 23import * as Bluebird from 'bluebird'
24import { MVideoImportDefault } from '@server/typings/models/video/video-import' 24import { MVideoImportDefault, MVideoImportFormattable } from '@server/typings/models/video/video-import'
25 25
26@DefaultScope(() => ({ 26@DefaultScope(() => ({
27 include: [ 27 include: [
@@ -154,7 +154,7 @@ export class VideoImportModel extends Model<VideoImportModel> {
154 return this.targetUrl || this.magnetUri || this.torrentName 154 return this.targetUrl || this.magnetUri || this.torrentName
155 } 155 }
156 156
157 toFormattedJSON (): VideoImport { 157 toFormattedJSON (this: MVideoImportFormattable): VideoImport {
158 const videoFormatOptions = { 158 const videoFormatOptions = {
159 completeDescription: true, 159 completeDescription: true,
160 additionalAttributes: { state: true, waitTranscoding: true, scheduledUpdate: true } 160 additionalAttributes: { state: true, waitTranscoding: true, scheduledUpdate: true }
diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts
index 901113161..80ca22a18 100644
--- a/server/models/video/video-playlist-element.ts
+++ b/server/models/video/video-playlist-element.ts
@@ -21,12 +21,16 @@ import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
21import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object' 21import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object'
22import * as validator from 'validator' 22import * as validator from 'validator'
23import { AggregateOptions, Op, ScopeOptions, Sequelize, Transaction } from 'sequelize' 23import { AggregateOptions, Op, ScopeOptions, Sequelize, Transaction } from 'sequelize'
24import { UserModel } from '../account/user'
25import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model' 24import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model'
26import { AccountModel } from '../account/account' 25import { AccountModel } from '../account/account'
27import { VideoPrivacy } from '../../../shared/models/videos' 26import { VideoPrivacy } from '../../../shared/models/videos'
28import * as Bluebird from 'bluebird' 27import * as Bluebird from 'bluebird'
29import { MVideoPlaylistAP, MVideoPlaylistElement, MVideoPlaylistVideoThumbnail } from '@server/typings/models/video/video-playlist-element' 28import {
29 MVideoPlaylistElement,
30 MVideoPlaylistElementAP,
31 MVideoPlaylistElementFormattable,
32 MVideoPlaylistVideoThumbnail
33} from '@server/typings/models/video/video-playlist-element'
30import { MUserAccountId } from '@server/typings/models' 34import { MUserAccountId } from '@server/typings/models'
31 35
32@Table({ 36@Table({
@@ -180,7 +184,7 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
180 return VideoPlaylistElementModel.findByPk(playlistElementId) 184 return VideoPlaylistElementModel.findByPk(playlistElementId)
181 } 185 }
182 186
183 static loadByPlaylistAndVideoForAP (playlistId: number | string, videoId: number | string): Bluebird<MVideoPlaylistAP> { 187 static loadByPlaylistAndVideoForAP (playlistId: number | string, videoId: number | string): Bluebird<MVideoPlaylistElementAP> {
184 const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } 188 const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId }
185 const videoWhere = validator.isUUID('' + videoId) ? { uuid: videoId } : { id: videoId } 189 const videoWhere = validator.isUUID('' + videoId) ? { uuid: videoId } : { id: videoId }
186 190
@@ -293,7 +297,7 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
293 return VideoPlaylistElementModel.increment({ position: by }, query) 297 return VideoPlaylistElementModel.increment({ position: by }, query)
294 } 298 }
295 299
296 getType (displayNSFW?: boolean, accountId?: number) { 300 getType (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) {
297 const video = this.Video 301 const video = this.Video
298 302
299 if (!video) return VideoPlaylistElementType.DELETED 303 if (!video) return VideoPlaylistElementType.DELETED
@@ -309,14 +313,17 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
309 return VideoPlaylistElementType.REGULAR 313 return VideoPlaylistElementType.REGULAR
310 } 314 }
311 315
312 getVideoElement (displayNSFW?: boolean, accountId?: number) { 316 getVideoElement (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) {
313 if (!this.Video) return null 317 if (!this.Video) return null
314 if (this.getType(displayNSFW, accountId) !== VideoPlaylistElementType.REGULAR) return null 318 if (this.getType(displayNSFW, accountId) !== VideoPlaylistElementType.REGULAR) return null
315 319
316 return this.Video.toFormattedJSON() 320 return this.Video.toFormattedJSON()
317 } 321 }
318 322
319 toFormattedJSON (options: { displayNSFW?: boolean, accountId?: number } = {}): VideoPlaylistElement { 323 toFormattedJSON (
324 this: MVideoPlaylistElementFormattable,
325 options: { displayNSFW?: boolean, accountId?: number } = {}
326 ): VideoPlaylistElement {
320 return { 327 return {
321 id: this.id, 328 id: this.id,
322 position: this.position, 329 position: this.position,
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts
index 9f1d03ac5..80dd65322 100644
--- a/server/models/video/video-playlist.ts
+++ b/server/models/video/video-playlist.ts
@@ -46,6 +46,7 @@ import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } fro
46import * as Bluebird from 'bluebird' 46import * as Bluebird from 'bluebird'
47import { 47import {
48 MVideoPlaylistAccountThumbnail, 48 MVideoPlaylistAccountThumbnail,
49 MVideoPlaylistFormattable,
49 MVideoPlaylistFull, 50 MVideoPlaylistFull,
50 MVideoPlaylistFullSummary, 51 MVideoPlaylistFullSummary,
51 MVideoPlaylistIdWithElements 52 MVideoPlaylistIdWithElements
@@ -479,7 +480,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
479 return isOutdated(this, ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL) 480 return isOutdated(this, ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL)
480 } 481 }
481 482
482 toFormattedJSON (): VideoPlaylist { 483 toFormattedJSON (this: MVideoPlaylistFormattable): VideoPlaylist {
483 return { 484 return {
484 id: this.id, 485 id: this.id,
485 uuid: this.uuid, 486 uuid: this.uuid,
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index e62bde344..9c24d1ba8 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -132,8 +132,9 @@ import {
132 MVideoFullLight, 132 MVideoFullLight,
133 MVideoIdThumbnail, 133 MVideoIdThumbnail,
134 MVideoThumbnail, 134 MVideoThumbnail,
135 MVideoWithAllFiles, 135 MVideoWithAllFiles, MVideoWithFile,
136 MVideoWithRights 136 MVideoWithRights,
137 MVideoFormattable
137} from '../../typings/models' 138} from '../../typings/models'
138import { MVideoFile, MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' 139import { MVideoFile, MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file'
139import { MThumbnail } from '../../typings/models/video/thumbnail' 140import { MThumbnail } from '../../typings/models/video/thumbnail'
@@ -1765,14 +1766,14 @@ export class VideoModel extends Model<VideoModel> {
1765 this.VideoChannel.Account.isBlocked() 1766 this.VideoChannel.Account.isBlocked()
1766 } 1767 }
1767 1768
1768 getOriginalFile () { 1769 getOriginalFile <T extends MVideoWithFile> (this: T) {
1769 if (Array.isArray(this.VideoFiles) === false) return undefined 1770 if (Array.isArray(this.VideoFiles) === false) return undefined
1770 1771
1771 // The original file is the file that have the higher resolution 1772 // The original file is the file that have the higher resolution
1772 return maxBy(this.VideoFiles, file => file.resolution) 1773 return maxBy(this.VideoFiles, file => file.resolution)
1773 } 1774 }
1774 1775
1775 getFile (resolution: number) { 1776 getFile <T extends MVideoWithFile> (this: T, resolution: number) {
1776 if (Array.isArray(this.VideoFiles) === false) return undefined 1777 if (Array.isArray(this.VideoFiles) === false) return undefined
1777 1778
1778 return this.VideoFiles.find(f => f.resolution === resolution) 1779 return this.VideoFiles.find(f => f.resolution === resolution)
@@ -1878,7 +1879,7 @@ export class VideoModel extends Model<VideoModel> {
1878 return join(LAZY_STATIC_PATHS.PREVIEWS, preview.filename) 1879 return join(LAZY_STATIC_PATHS.PREVIEWS, preview.filename)
1879 } 1880 }
1880 1881
1881 toFormattedJSON (options?: VideoFormattingJSONOptions): Video { 1882 toFormattedJSON <T extends MVideoFormattable> (this: T, options?: VideoFormattingJSONOptions): Video {
1882 return videoModelToFormattedJSON(this, options) 1883 return videoModelToFormattedJSON(this, options)
1883 } 1884 }
1884 1885