aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-08-20 19:05:31 +0200
committerChocobozzz <me@florianbigard.com>2019-08-20 19:23:10 +0200
commit1ca9f7c3f7afac2af4c4c25b98426731f7e789c6 (patch)
tree27fe65c4ea5e9250d2523033d5c65b315bfca23d /server/models
parent0283eaac2a8e73006c66df3cf5bb9012e37450e5 (diff)
downloadPeerTube-1ca9f7c3f7afac2af4c4c25b98426731f7e789c6.tar.gz
PeerTube-1ca9f7c3f7afac2af4c4c25b98426731f7e789c6.tar.zst
PeerTube-1ca9f7c3f7afac2af4c4c25b98426731f7e789c6.zip
Type toFormattedJSON
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account-blocklist.ts4
-rw-r--r--server/models/account/account-video-rate.ts9
-rw-r--r--server/models/account/account.ts8
-rw-r--r--server/models/account/user-notification-setting.ts3
-rw-r--r--server/models/account/user.ts12
-rw-r--r--server/models/activitypub/actor-follow.ts3
-rw-r--r--server/models/activitypub/actor.ts32
-rw-r--r--server/models/avatar/avatar.ts3
-rw-r--r--server/models/server/plugin.ts4
-rw-r--r--server/models/server/server-blocklist.ts4
-rw-r--r--server/models/server/server.ts4
-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
23 files changed, 115 insertions, 72 deletions
diff --git a/server/models/account/account-blocklist.ts b/server/models/account/account-blocklist.ts
index bb5371395..8bcaca828 100644
--- a/server/models/account/account-blocklist.ts
+++ b/server/models/account/account-blocklist.ts
@@ -4,7 +4,7 @@ import { getSort } from '../utils'
4import { AccountBlock } from '../../../shared/models/blocklist' 4import { AccountBlock } from '../../../shared/models/blocklist'
5import { Op } from 'sequelize' 5import { Op } from 'sequelize'
6import * as Bluebird from 'bluebird' 6import * as Bluebird from 'bluebird'
7import { MAccountBlocklist, MAccountBlocklistAccounts } from '@server/typings/models' 7import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/typings/models'
8 8
9enum ScopeNames { 9enum ScopeNames {
10 WITH_ACCOUNTS = 'WITH_ACCOUNTS' 10 WITH_ACCOUNTS = 'WITH_ACCOUNTS'
@@ -134,7 +134,7 @@ export class AccountBlocklistModel extends Model<AccountBlocklistModel> {
134 }) 134 })
135 } 135 }
136 136
137 toFormattedJSON (): AccountBlock { 137 toFormattedJSON (this: MAccountBlocklistFormattable): AccountBlock {
138 return { 138 return {
139 byAccount: this.ByAccount.toFormattedJSON(), 139 byAccount: this.ByAccount.toFormattedJSON(),
140 blockedAccount: this.BlockedAccount.toFormattedJSON(), 140 blockedAccount: this.BlockedAccount.toFormattedJSON(),
diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts
index 8b62dd05f..a6edbeee8 100644
--- a/server/models/account/account-video-rate.ts
+++ b/server/models/account/account-video-rate.ts
@@ -11,7 +11,12 @@ import { isActivityPubUrlValid } from '../../helpers/custom-validators/activityp
11import { AccountVideoRate } from '../../../shared' 11import { AccountVideoRate } from '../../../shared'
12import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel' 12import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel'
13import * as Bluebird from 'bluebird' 13import * as Bluebird from 'bluebird'
14import { MAccountVideoRate, MAccountVideoRateAccountUrl, MAccountVideoRateAccountVideo } from '@server/typings/models/video/video-rate' 14import {
15 MAccountVideoRate,
16 MAccountVideoRateAccountUrl,
17 MAccountVideoRateAccountVideo,
18 MAccountVideoRateFormattable
19} from '@server/typings/models/video/video-rate'
15 20
16/* 21/*
17 Account rates per video. 22 Account rates per video.
@@ -248,7 +253,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
248 }) 253 })
249 } 254 }
250 255
251 toFormattedJSON (): AccountVideoRate { 256 toFormattedJSON (this: MAccountVideoRateFormattable): AccountVideoRate {
252 return { 257 return {
253 video: this.Video.toFormattedJSON(), 258 video: this.Video.toFormattedJSON(),
254 rating: this.type 259 rating: this.type
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 4cc731075..8369738b9 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -32,7 +32,7 @@ import { FindOptions, IncludeOptions, Op, Transaction, WhereOptions } from 'sequ
32import { AccountBlocklistModel } from './account-blocklist' 32import { AccountBlocklistModel } from './account-blocklist'
33import { ServerBlocklistModel } from '../server/server-blocklist' 33import { ServerBlocklistModel } from '../server/server-blocklist'
34import { ActorFollowModel } from '../activitypub/actor-follow' 34import { ActorFollowModel } from '../activitypub/actor-follow'
35import { MAccountActor, MAccountDefault } from '../../typings/models' 35import { MAccountActor, MAccountDefault, MAccountSummaryFormattable, MAccountFormattable } from '../../typings/models'
36import * as Bluebird from 'bluebird' 36import * as Bluebird from 'bluebird'
37 37
38export enum ScopeNames { 38export enum ScopeNames {
@@ -353,7 +353,7 @@ export class AccountModel extends Model<AccountModel> {
353 .findAll(query) 353 .findAll(query)
354 } 354 }
355 355
356 toFormattedJSON (): Account { 356 toFormattedJSON (this: MAccountFormattable): Account {
357 const actor = this.Actor.toFormattedJSON() 357 const actor = this.Actor.toFormattedJSON()
358 const account = { 358 const account = {
359 id: this.id, 359 id: this.id,
@@ -367,8 +367,8 @@ export class AccountModel extends Model<AccountModel> {
367 return Object.assign(actor, account) 367 return Object.assign(actor, account)
368 } 368 }
369 369
370 toFormattedSummaryJSON (): AccountSummary { 370 toFormattedSummaryJSON (this: MAccountSummaryFormattable): AccountSummary {
371 const actor = this.Actor.toFormattedJSON() 371 const actor = this.Actor.toFormattedSummaryJSON()
372 372
373 return { 373 return {
374 id: this.id, 374 id: this.id,
diff --git a/server/models/account/user-notification-setting.ts b/server/models/account/user-notification-setting.ts
index c2fbc6d23..1506295cf 100644
--- a/server/models/account/user-notification-setting.ts
+++ b/server/models/account/user-notification-setting.ts
@@ -17,6 +17,7 @@ import { UserModel } from './user'
17import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' 17import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
18import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model' 18import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model'
19import { clearCacheByUserId } from '../../lib/oauth-model' 19import { clearCacheByUserId } from '../../lib/oauth-model'
20import { MNotificationSettingFormattable } from '@server/typings/models'
20 21
21@Table({ 22@Table({
22 tableName: 'userNotificationSetting', 23 tableName: 'userNotificationSetting',
@@ -152,7 +153,7 @@ export class UserNotificationSettingModel extends Model<UserNotificationSettingM
152 return clearCacheByUserId(instance.userId) 153 return clearCacheByUserId(instance.userId)
153 } 154 }
154 155
155 toFormattedJSON (): UserNotificationSetting { 156 toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting {
156 return { 157 return {
157 newCommentOnMyVideo: this.newCommentOnMyVideo, 158 newCommentOnMyVideo: this.newCommentOnMyVideo,
158 newVideoFromSubscription: this.newVideoFromSubscription, 159 newVideoFromSubscription: this.newVideoFromSubscription,
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index cb54d79af..616dd603c 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -55,7 +55,13 @@ import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
55import { isThemeNameValid } from '../../helpers/custom-validators/plugins' 55import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
56import { getThemeOrDefault } from '../../lib/plugins/theme-utils' 56import { getThemeOrDefault } from '../../lib/plugins/theme-utils'
57import * as Bluebird from 'bluebird' 57import * as Bluebird from 'bluebird'
58import { MUserNotifSettingChannelDefault, MUserDefault, MUserId, MUserWithNotificationSetting } from '@server/typings/models' 58import {
59 MUserDefault,
60 MUserFormattable,
61 MUserId,
62 MUserNotifSettingChannelDefault,
63 MUserWithNotificationSetting
64} from '@server/typings/models'
59 65
60enum ScopeNames { 66enum ScopeNames {
61 WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL' 67 WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL'
@@ -554,7 +560,9 @@ export class UserModel extends Model<UserModel> {
554 return comparePassword(password, this.password) 560 return comparePassword(password, this.password)
555 } 561 }
556 562
557 toFormattedJSON (parameters: { withAdminFlags?: boolean } = {}): User { 563 toSummaryJSON
564
565 toFormattedJSON (this: MUserFormattable, parameters: { withAdminFlags?: boolean } = {}): User {
558 const videoQuotaUsed = this.get('videoQuotaUsed') 566 const videoQuotaUsed = this.get('videoQuotaUsed')
559 const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily') 567 const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily')
560 568
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index 8ef770cd4..c8b3aae9f 100644
--- a/server/models/activitypub/actor-follow.ts
+++ b/server/models/activitypub/actor-follow.ts
@@ -32,6 +32,7 @@ import {
32 MActorFollowActorsDefault, 32 MActorFollowActorsDefault,
33 MActorFollowActorsDefaultSubscription, 33 MActorFollowActorsDefaultSubscription,
34 MActorFollowFollowingHost, 34 MActorFollowFollowingHost,
35 MActorFollowFormattable,
35 MActorFollowSubscriptions 36 MActorFollowSubscriptions
36} from '@server/typings/models' 37} from '@server/typings/models'
37 38
@@ -580,7 +581,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
580 return ActorFollowModel.findAll(query) 581 return ActorFollowModel.findAll(query)
581 } 582 }
582 583
583 toFormattedJSON (): ActorFollow { 584 toFormattedJSON (this: MActorFollowFormattable): ActorFollow {
584 const follower = this.ActorFollower.toFormattedJSON() 585 const follower = this.ActorFollower.toFormattedJSON()
585 const following = this.ActorFollowing.toFormattedJSON() 586 const following = this.ActorFollowing.toFormattedJSON()
586 587
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index 2312127b4..e2213afa1 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -36,7 +36,16 @@ import { isOutdated, throwIfNotValid } from '../utils'
36import { VideoChannelModel } from '../video/video-channel' 36import { VideoChannelModel } from '../video/video-channel'
37import { ActorFollowModel } from './actor-follow' 37import { ActorFollowModel } from './actor-follow'
38import { VideoModel } from '../video/video' 38import { VideoModel } from '../video/video'
39import { MActor, MActorAccountChannelId, MActorFull } from '../../typings/models' 39import {
40 MActor,
41 MActorAccountChannelId,
42 MActorFormattable,
43 MActorFull, MActorHost,
44 MActorServer,
45 MActorSummaryFormattable,
46 MServerHost,
47 MActorRedundancyAllowed
48} from '../../typings/models'
40import * as Bluebird from 'bluebird' 49import * as Bluebird from 'bluebird'
41 50
42enum ScopeNames { 51enum ScopeNames {
@@ -393,24 +402,31 @@ export class ActorModel extends Model<ActorModel> {
393 }) 402 })
394 } 403 }
395 404
396 toFormattedJSON () { 405 toFormattedSummaryJSON (this: MActorSummaryFormattable) {
397 let avatar: Avatar = null 406 let avatar: Avatar = null
398 if (this.Avatar) { 407 if (this.Avatar) {
399 avatar = this.Avatar.toFormattedJSON() 408 avatar = this.Avatar.toFormattedJSON()
400 } 409 }
401 410
402 return { 411 return {
403 id: this.id,
404 url: this.url, 412 url: this.url,
405 name: this.preferredUsername, 413 name: this.preferredUsername,
406 host: this.getHost(), 414 host: this.getHost(),
415 avatar
416 }
417 }
418
419 toFormattedJSON (this: MActorFormattable) {
420 const base = this.toFormattedSummaryJSON()
421
422 return Object.assign(base, {
423 id: this.id,
407 hostRedundancyAllowed: this.getRedundancyAllowed(), 424 hostRedundancyAllowed: this.getRedundancyAllowed(),
408 followingCount: this.followingCount, 425 followingCount: this.followingCount,
409 followersCount: this.followersCount, 426 followersCount: this.followersCount,
410 avatar,
411 createdAt: this.createdAt, 427 createdAt: this.createdAt,
412 updatedAt: this.updatedAt 428 updatedAt: this.updatedAt
413 } 429 })
414 } 430 }
415 431
416 toActivityPubObject (name: string, type: 'Account' | 'Application' | 'VideoChannel') { 432 toActivityPubObject (name: string, type: 'Account' | 'Application' | 'VideoChannel') {
@@ -500,7 +516,7 @@ export class ActorModel extends Model<ActorModel> {
500 return this.serverId === null 516 return this.serverId === null
501 } 517 }
502 518
503 getWebfingerUrl () { 519 getWebfingerUrl (this: MActorServer) {
504 return 'acct:' + this.preferredUsername + '@' + this.getHost() 520 return 'acct:' + this.preferredUsername + '@' + this.getHost()
505 } 521 }
506 522
@@ -508,11 +524,11 @@ export class ActorModel extends Model<ActorModel> {
508 return this.Server ? `${this.preferredUsername}@${this.Server.host}` : this.preferredUsername 524 return this.Server ? `${this.preferredUsername}@${this.Server.host}` : this.preferredUsername
509 } 525 }
510 526
511 getHost () { 527 getHost (this: MActorHost) {
512 return this.Server ? this.Server.host : WEBSERVER.HOST 528 return this.Server ? this.Server.host : WEBSERVER.HOST
513 } 529 }
514 530
515 getRedundancyAllowed () { 531 getRedundancyAllowed (this: MActorRedundancyAllowed) {
516 return this.Server ? this.Server.redundancyAllowed : false 532 return this.Server ? this.Server.redundancyAllowed : false
517 } 533 }
518 534
diff --git a/server/models/avatar/avatar.ts b/server/models/avatar/avatar.ts
index b40144592..950e4b181 100644
--- a/server/models/avatar/avatar.ts
+++ b/server/models/avatar/avatar.ts
@@ -7,6 +7,7 @@ import { remove } from 'fs-extra'
7import { CONFIG } from '../../initializers/config' 7import { CONFIG } from '../../initializers/config'
8import { throwIfNotValid } from '../utils' 8import { throwIfNotValid } from '../utils'
9import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 9import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
10import { MAvatarFormattable } from '@server/typings/models'
10 11
11@Table({ 12@Table({
12 tableName: 'avatar', 13 tableName: 'avatar',
@@ -57,7 +58,7 @@ export class AvatarModel extends Model<AvatarModel> {
57 return AvatarModel.findOne(query) 58 return AvatarModel.findOne(query)
58 } 59 }
59 60
60 toFormattedJSON (): Avatar { 61 toFormattedJSON (this: MAvatarFormattable): Avatar {
61 return { 62 return {
62 path: this.getStaticPath(), 63 path: this.getStaticPath(),
63 createdAt: this.createdAt, 64 createdAt: this.createdAt,
diff --git a/server/models/server/plugin.ts b/server/models/server/plugin.ts
index debd25ea1..d094da1f5 100644
--- a/server/models/server/plugin.ts
+++ b/server/models/server/plugin.ts
@@ -12,7 +12,7 @@ import { PeerTubePlugin } from '../../../shared/models/plugins/peertube-plugin.m
12import { FindAndCountOptions, json } from 'sequelize' 12import { FindAndCountOptions, json } from 'sequelize'
13import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model' 13import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model'
14import * as Bluebird from 'bluebird' 14import * as Bluebird from 'bluebird'
15import { MPlugin } from '@server/typings/models' 15import { MPlugin, MPluginFormattable } from '@server/typings/models'
16 16
17@DefaultScope(() => ({ 17@DefaultScope(() => ({
18 attributes: { 18 attributes: {
@@ -253,7 +253,7 @@ export class PluginModel extends Model<PluginModel> {
253 return result 253 return result
254 } 254 }
255 255
256 toFormattedJSON (): PeerTubePlugin { 256 toFormattedJSON (this: MPluginFormattable): PeerTubePlugin {
257 return { 257 return {
258 name: this.name, 258 name: this.name,
259 type: this.type, 259 type: this.type,
diff --git a/server/models/server/server-blocklist.ts b/server/models/server/server-blocklist.ts
index e4db93dfc..3e9687191 100644
--- a/server/models/server/server-blocklist.ts
+++ b/server/models/server/server-blocklist.ts
@@ -4,7 +4,7 @@ import { ServerModel } from './server'
4import { ServerBlock } from '../../../shared/models/blocklist' 4import { ServerBlock } from '../../../shared/models/blocklist'
5import { getSort } from '../utils' 5import { getSort } from '../utils'
6import * as Bluebird from 'bluebird' 6import * as Bluebird from 'bluebird'
7import { MServerBlocklist, MServerBlocklistAccountServer } from '@server/typings/models' 7import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/typings/models'
8 8
9enum ScopeNames { 9enum ScopeNames {
10 WITH_ACCOUNT = 'WITH_ACCOUNT', 10 WITH_ACCOUNT = 'WITH_ACCOUNT',
@@ -112,7 +112,7 @@ export class ServerBlocklistModel extends Model<ServerBlocklistModel> {
112 }) 112 })
113 } 113 }
114 114
115 toFormattedJSON (): ServerBlock { 115 toFormattedJSON (this: MServerBlocklistFormattable): ServerBlock {
116 return { 116 return {
117 byAccount: this.ByAccount.toFormattedJSON(), 117 byAccount: this.ByAccount.toFormattedJSON(),
118 blockedServer: this.BlockedServer.toFormattedJSON(), 118 blockedServer: this.BlockedServer.toFormattedJSON(),
diff --git a/server/models/server/server.ts b/server/models/server/server.ts
index b0bdd2b0b..3b6759b5c 100644
--- a/server/models/server/server.ts
+++ b/server/models/server/server.ts
@@ -4,7 +4,7 @@ import { ActorModel } from '../activitypub/actor'
4import { throwIfNotValid } from '../utils' 4import { throwIfNotValid } from '../utils'
5import { ServerBlocklistModel } from './server-blocklist' 5import { ServerBlocklistModel } from './server-blocklist'
6import * as Bluebird from 'bluebird' 6import * as Bluebird from 'bluebird'
7import { MServer } from '@server/typings/models/server' 7import { MServer, MServerFormattable } from '@server/typings/models/server'
8 8
9@Table({ 9@Table({
10 tableName: 'server', 10 tableName: 'server',
@@ -65,7 +65,7 @@ export class ServerModel extends Model<ServerModel> {
65 return this.BlockedByAccounts && this.BlockedByAccounts.length !== 0 65 return this.BlockedByAccounts && this.BlockedByAccounts.length !== 0
66 } 66 }
67 67
68 toFormattedJSON () { 68 toFormattedJSON (this: MServerFormattable) {
69 return { 69 return {
70 host: this.host 70 host: this.host
71 } 71 }
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