diff options
Diffstat (limited to 'server/models')
41 files changed, 333 insertions, 343 deletions
diff --git a/server/models/abuse/abuse-message.ts b/server/models/abuse/abuse-message.ts index fce20f7a7..7e51b3e07 100644 --- a/server/models/abuse/abuse-message.ts +++ b/server/models/abuse/abuse-message.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { isAbuseMessageValid } from '@server/helpers/custom-validators/abuses' | 2 | import { isAbuseMessageValid } from '@server/helpers/custom-validators/abuses' |
3 | import { MAbuseMessage, MAbuseMessageFormattable } from '@server/types/models' | ||
3 | import { AbuseMessage } from '@shared/models' | 4 | import { AbuseMessage } from '@shared/models' |
4 | import { AccountModel, ScopeNames as AccountScopeNames } from '../account/account' | 5 | import { AccountModel, ScopeNames as AccountScopeNames } from '../account/account' |
5 | import { throwIfNotValid, getSort } from '../utils' | 6 | import { getSort, throwIfNotValid } from '../utils' |
6 | import { AbuseModel } from './abuse' | 7 | import { AbuseModel } from './abuse' |
7 | import { MAbuseMessageFormattable, MAbuseMessage } from '@server/types/models' | ||
8 | 8 | ||
9 | @Table({ | 9 | @Table({ |
10 | tableName: 'abuseMessage', | 10 | tableName: 'abuseMessage', |
@@ -17,7 +17,7 @@ import { MAbuseMessageFormattable, MAbuseMessage } from '@server/types/models' | |||
17 | } | 17 | } |
18 | ] | 18 | ] |
19 | }) | 19 | }) |
20 | export class AbuseMessageModel extends Model<AbuseMessageModel> { | 20 | export class AbuseMessageModel extends Model { |
21 | 21 | ||
22 | @AllowNull(false) | 22 | @AllowNull(false) |
23 | @Is('AbuseMessage', value => throwIfNotValid(value, isAbuseMessageValid, 'message')) | 23 | @Is('AbuseMessage', value => throwIfNotValid(value, isAbuseMessageValid, 'message')) |
diff --git a/server/models/abuse/abuse.ts b/server/models/abuse/abuse.ts index 290270fe2..de249d211 100644 --- a/server/models/abuse/abuse.ts +++ b/server/models/abuse/abuse.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { invert } from 'lodash' | 1 | import { invert } from 'lodash' |
3 | import { literal, Op, QueryTypes } from 'sequelize' | 2 | import { literal, Op, QueryTypes } from 'sequelize' |
4 | import { | 3 | import { |
@@ -188,7 +187,7 @@ export enum ScopeNames { | |||
188 | } | 187 | } |
189 | ] | 188 | ] |
190 | }) | 189 | }) |
191 | export class AbuseModel extends Model<AbuseModel> { | 190 | export class AbuseModel extends Model { |
192 | 191 | ||
193 | @AllowNull(false) | 192 | @AllowNull(false) |
194 | @Default(null) | 193 | @Default(null) |
@@ -265,7 +264,7 @@ export class AbuseModel extends Model<AbuseModel> { | |||
265 | }) | 264 | }) |
266 | VideoAbuse: VideoAbuseModel | 265 | VideoAbuse: VideoAbuseModel |
267 | 266 | ||
268 | static loadByIdWithReporter (id: number): Bluebird<MAbuseReporter> { | 267 | static loadByIdWithReporter (id: number): Promise<MAbuseReporter> { |
269 | const query = { | 268 | const query = { |
270 | where: { | 269 | where: { |
271 | id | 270 | id |
@@ -281,7 +280,7 @@ export class AbuseModel extends Model<AbuseModel> { | |||
281 | return AbuseModel.findOne(query) | 280 | return AbuseModel.findOne(query) |
282 | } | 281 | } |
283 | 282 | ||
284 | static loadFull (id: number): Bluebird<MAbuseFull> { | 283 | static loadFull (id: number): Promise<MAbuseFull> { |
285 | const query = { | 284 | const query = { |
286 | where: { | 285 | where: { |
287 | id | 286 | id |
diff --git a/server/models/abuse/video-abuse.ts b/server/models/abuse/video-abuse.ts index d92bcf19f..90aa0695e 100644 --- a/server/models/abuse/video-abuse.ts +++ b/server/models/abuse/video-abuse.ts | |||
@@ -14,7 +14,7 @@ import { AbuseModel } from './abuse' | |||
14 | } | 14 | } |
15 | ] | 15 | ] |
16 | }) | 16 | }) |
17 | export class VideoAbuseModel extends Model<VideoAbuseModel> { | 17 | export class VideoAbuseModel extends Model { |
18 | 18 | ||
19 | @CreatedAt | 19 | @CreatedAt |
20 | createdAt: Date | 20 | createdAt: Date |
diff --git a/server/models/abuse/video-comment-abuse.ts b/server/models/abuse/video-comment-abuse.ts index 8b34009b4..d3fce76a5 100644 --- a/server/models/abuse/video-comment-abuse.ts +++ b/server/models/abuse/video-comment-abuse.ts | |||
@@ -13,7 +13,7 @@ import { AbuseModel } from './abuse' | |||
13 | } | 13 | } |
14 | ] | 14 | ] |
15 | }) | 15 | }) |
16 | export class VideoCommentAbuseModel extends Model<VideoCommentAbuseModel> { | 16 | export class VideoCommentAbuseModel extends Model { |
17 | 17 | ||
18 | @CreatedAt | 18 | @CreatedAt |
19 | createdAt: Date | 19 | createdAt: Date |
diff --git a/server/models/account/account-blocklist.ts b/server/models/account/account-blocklist.ts index 577b7dc19..fe9168ab8 100644 --- a/server/models/account/account-blocklist.ts +++ b/server/models/account/account-blocklist.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { Op } from 'sequelize' | 1 | import { Op } from 'sequelize' |
3 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
4 | import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/types/models' | 3 | import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/types/models' |
@@ -41,7 +40,7 @@ enum ScopeNames { | |||
41 | } | 40 | } |
42 | ] | 41 | ] |
43 | }) | 42 | }) |
44 | export class AccountBlocklistModel extends Model<AccountBlocklistModel> { | 43 | export class AccountBlocklistModel extends Model { |
45 | 44 | ||
46 | @CreatedAt | 45 | @CreatedAt |
47 | createdAt: Date | 46 | createdAt: Date |
@@ -102,7 +101,7 @@ export class AccountBlocklistModel extends Model<AccountBlocklistModel> { | |||
102 | }) | 101 | }) |
103 | } | 102 | } |
104 | 103 | ||
105 | static loadByAccountAndTarget (accountId: number, targetAccountId: number): Bluebird<MAccountBlocklist> { | 104 | static loadByAccountAndTarget (accountId: number, targetAccountId: number): Promise<MAccountBlocklist> { |
106 | const query = { | 105 | const query = { |
107 | where: { | 106 | where: { |
108 | accountId, | 107 | accountId, |
@@ -151,9 +150,9 @@ export class AccountBlocklistModel extends Model<AccountBlocklistModel> { | |||
151 | }) | 150 | }) |
152 | } | 151 | } |
153 | 152 | ||
154 | static listHandlesBlockedBy (accountIds: number[]): Bluebird<string[]> { | 153 | static listHandlesBlockedBy (accountIds: number[]): Promise<string[]> { |
155 | const query = { | 154 | const query = { |
156 | attributes: [], | 155 | attributes: [ 'id' ], |
157 | where: { | 156 | where: { |
158 | accountId: { | 157 | accountId: { |
159 | [Op.in]: accountIds | 158 | [Op.in]: accountIds |
diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts index 6955f45ee..d9c529491 100644 --- a/server/models/account/account-video-rate.ts +++ b/server/models/account/account-video-rate.ts | |||
@@ -1,22 +1,21 @@ | |||
1 | import { values } from 'lodash' | 1 | import { values } from 'lodash' |
2 | import { FindOptions, Op, Transaction } from 'sequelize' | 2 | import { FindOptions, Op, QueryTypes, Transaction } from 'sequelize' |
3 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 3 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
4 | import { VideoRateType } from '../../../shared/models/videos' | ||
5 | import { CONSTRAINTS_FIELDS, VIDEO_RATE_TYPES } from '../../initializers/constants' | ||
6 | import { VideoModel } from '../video/video' | ||
7 | import { AccountModel } from './account' | ||
8 | import { ActorModel } from '../activitypub/actor' | ||
9 | import { buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils' | ||
10 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
11 | import { AccountVideoRate } from '../../../shared' | ||
12 | import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel' | ||
13 | import * as Bluebird from 'bluebird' | ||
14 | import { | 4 | import { |
15 | MAccountVideoRate, | 5 | MAccountVideoRate, |
16 | MAccountVideoRateAccountUrl, | 6 | MAccountVideoRateAccountUrl, |
17 | MAccountVideoRateAccountVideo, | 7 | MAccountVideoRateAccountVideo, |
18 | MAccountVideoRateFormattable | 8 | MAccountVideoRateFormattable |
19 | } from '@server/types/models/video/video-rate' | 9 | } from '@server/types/models/video/video-rate' |
10 | import { AccountVideoRate } from '../../../shared' | ||
11 | import { VideoRateType } from '../../../shared/models/videos' | ||
12 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
13 | import { CONSTRAINTS_FIELDS, VIDEO_RATE_TYPES } from '../../initializers/constants' | ||
14 | import { ActorModel } from '../activitypub/actor' | ||
15 | import { buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils' | ||
16 | import { VideoModel } from '../video/video' | ||
17 | import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel' | ||
18 | import { AccountModel } from './account' | ||
20 | 19 | ||
21 | /* | 20 | /* |
22 | Account rates per video. | 21 | Account rates per video. |
@@ -43,7 +42,7 @@ import { | |||
43 | } | 42 | } |
44 | ] | 43 | ] |
45 | }) | 44 | }) |
46 | export class AccountVideoRateModel extends Model<AccountVideoRateModel> { | 45 | export class AccountVideoRateModel extends Model { |
47 | 46 | ||
48 | @AllowNull(false) | 47 | @AllowNull(false) |
49 | @Column(DataType.ENUM(...values(VIDEO_RATE_TYPES))) | 48 | @Column(DataType.ENUM(...values(VIDEO_RATE_TYPES))) |
@@ -84,7 +83,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> { | |||
84 | }) | 83 | }) |
85 | Account: AccountModel | 84 | Account: AccountModel |
86 | 85 | ||
87 | static load (accountId: number, videoId: number, transaction?: Transaction): Bluebird<MAccountVideoRate> { | 86 | static load (accountId: number, videoId: number, transaction?: Transaction): Promise<MAccountVideoRate> { |
88 | const options: FindOptions = { | 87 | const options: FindOptions = { |
89 | where: { | 88 | where: { |
90 | accountId, | 89 | accountId, |
@@ -96,7 +95,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> { | |||
96 | return AccountVideoRateModel.findOne(options) | 95 | return AccountVideoRateModel.findOne(options) |
97 | } | 96 | } |
98 | 97 | ||
99 | static loadByAccountAndVideoOrUrl (accountId: number, videoId: number, url: string, t?: Transaction): Bluebird<MAccountVideoRate> { | 98 | static loadByAccountAndVideoOrUrl (accountId: number, videoId: number, url: string, t?: Transaction): Promise<MAccountVideoRate> { |
100 | const options: FindOptions = { | 99 | const options: FindOptions = { |
101 | where: { | 100 | where: { |
102 | [Op.or]: [ | 101 | [Op.or]: [ |
@@ -152,7 +151,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> { | |||
152 | accountName: string, | 151 | accountName: string, |
153 | videoId: number | string, | 152 | videoId: number | string, |
154 | t?: Transaction | 153 | t?: Transaction |
155 | ): Bluebird<MAccountVideoRateAccountVideo> { | 154 | ): Promise<MAccountVideoRateAccountVideo> { |
156 | const options: FindOptions = { | 155 | const options: FindOptions = { |
157 | where: { | 156 | where: { |
158 | videoId, | 157 | videoId, |
@@ -240,17 +239,23 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> { | |||
240 | transaction: t | 239 | transaction: t |
241 | } | 240 | } |
242 | 241 | ||
243 | const deleted = await AccountVideoRateModel.destroy(query) | 242 | await AccountVideoRateModel.destroy(query) |
244 | 243 | ||
245 | const options = { | 244 | const field = type === 'like' |
246 | transaction: t, | 245 | ? 'likes' |
247 | where: { | 246 | : 'dislikes' |
248 | id: videoId | 247 | |
249 | } | 248 | const rawQuery = `UPDATE "video" SET "${field}" = ` + |
250 | } | 249 | '(' + |
250 | 'SELECT COUNT(id) FROM "accountVideoRate" WHERE "accountVideoRate"."videoId" = "video"."id" AND type = :rateType' + | ||
251 | ') ' + | ||
252 | 'WHERE "video"."id" = :videoId' | ||
251 | 253 | ||
252 | if (type === 'like') await VideoModel.increment({ likes: -deleted }, options) | 254 | return AccountVideoRateModel.sequelize.query(rawQuery, { |
253 | else if (type === 'dislike') await VideoModel.increment({ dislikes: -deleted }, options) | 255 | transaction: t, |
256 | replacements: { videoId, rateType: type }, | ||
257 | type: QueryTypes.UPDATE | ||
258 | }) | ||
254 | }) | 259 | }) |
255 | } | 260 | } |
256 | 261 | ||
diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 8c244d432..c72f9c63d 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import { FindOptions, Includeable, IncludeOptions, Op, Transaction, WhereOptions } from 'sequelize' |
2 | import { FindOptions, IncludeOptions, Op, Transaction, WhereOptions } from 'sequelize' | ||
3 | import { | 2 | import { |
4 | AllowNull, | 3 | AllowNull, |
5 | BeforeDestroy, | 4 | BeforeDestroy, |
@@ -73,28 +72,29 @@ export type SummaryOptions = { | |||
73 | required: false | 72 | required: false |
74 | } | 73 | } |
75 | 74 | ||
76 | const query: FindOptions = { | 75 | const queryInclude: Includeable[] = [ |
77 | attributes: [ 'id', 'name', 'actorId' ], | 76 | { |
78 | include: [ | 77 | attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ], |
79 | { | 78 | model: ActorModel.unscoped(), |
80 | attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ], | 79 | required: options.actorRequired ?? true, |
81 | model: ActorModel.unscoped(), | 80 | where: whereActor, |
82 | required: options.actorRequired ?? true, | 81 | include: [ |
83 | where: whereActor, | 82 | serverInclude, |
84 | include: [ | ||
85 | serverInclude, | ||
86 | 83 | ||
87 | { | 84 | { |
88 | model: AvatarModel.unscoped(), | 85 | model: AvatarModel.unscoped(), |
89 | required: false | 86 | required: false |
90 | } | 87 | } |
91 | ] | 88 | ] |
92 | } | 89 | } |
93 | ] | 90 | ] |
91 | |||
92 | const query: FindOptions = { | ||
93 | attributes: [ 'id', 'name', 'actorId' ] | ||
94 | } | 94 | } |
95 | 95 | ||
96 | if (options.withAccountBlockerIds) { | 96 | if (options.withAccountBlockerIds) { |
97 | query.include.push({ | 97 | queryInclude.push({ |
98 | attributes: [ 'id' ], | 98 | attributes: [ 'id' ], |
99 | model: AccountBlocklistModel.unscoped(), | 99 | model: AccountBlocklistModel.unscoped(), |
100 | as: 'BlockedAccounts', | 100 | as: 'BlockedAccounts', |
@@ -120,6 +120,8 @@ export type SummaryOptions = { | |||
120 | ] | 120 | ] |
121 | } | 121 | } |
122 | 122 | ||
123 | query.include = queryInclude | ||
124 | |||
123 | return query | 125 | return query |
124 | } | 126 | } |
125 | })) | 127 | })) |
@@ -138,7 +140,7 @@ export type SummaryOptions = { | |||
138 | } | 140 | } |
139 | ] | 141 | ] |
140 | }) | 142 | }) |
141 | export class AccountModel extends Model<AccountModel> { | 143 | export class AccountModel extends Model { |
142 | 144 | ||
143 | @AllowNull(false) | 145 | @AllowNull(false) |
144 | @Column | 146 | @Column |
@@ -244,11 +246,11 @@ export class AccountModel extends Model<AccountModel> { | |||
244 | return undefined | 246 | return undefined |
245 | } | 247 | } |
246 | 248 | ||
247 | static load (id: number, transaction?: Transaction): Bluebird<MAccountDefault> { | 249 | static load (id: number, transaction?: Transaction): Promise<MAccountDefault> { |
248 | return AccountModel.findByPk(id, { transaction }) | 250 | return AccountModel.findByPk(id, { transaction }) |
249 | } | 251 | } |
250 | 252 | ||
251 | static loadByNameWithHost (nameWithHost: string): Bluebird<MAccountDefault> { | 253 | static loadByNameWithHost (nameWithHost: string): Promise<MAccountDefault> { |
252 | const [ accountName, host ] = nameWithHost.split('@') | 254 | const [ accountName, host ] = nameWithHost.split('@') |
253 | 255 | ||
254 | if (!host || host === WEBSERVER.HOST) return AccountModel.loadLocalByName(accountName) | 256 | if (!host || host === WEBSERVER.HOST) return AccountModel.loadLocalByName(accountName) |
@@ -256,7 +258,7 @@ export class AccountModel extends Model<AccountModel> { | |||
256 | return AccountModel.loadByNameAndHost(accountName, host) | 258 | return AccountModel.loadByNameAndHost(accountName, host) |
257 | } | 259 | } |
258 | 260 | ||
259 | static loadLocalByName (name: string): Bluebird<MAccountDefault> { | 261 | static loadLocalByName (name: string): Promise<MAccountDefault> { |
260 | const fun = () => { | 262 | const fun = () => { |
261 | const query = { | 263 | const query = { |
262 | where: { | 264 | where: { |
@@ -296,7 +298,7 @@ export class AccountModel extends Model<AccountModel> { | |||
296 | }) | 298 | }) |
297 | } | 299 | } |
298 | 300 | ||
299 | static loadByNameAndHost (name: string, host: string): Bluebird<MAccountDefault> { | 301 | static loadByNameAndHost (name: string, host: string): Promise<MAccountDefault> { |
300 | const query = { | 302 | const query = { |
301 | include: [ | 303 | include: [ |
302 | { | 304 | { |
@@ -321,7 +323,7 @@ export class AccountModel extends Model<AccountModel> { | |||
321 | return AccountModel.findOne(query) | 323 | return AccountModel.findOne(query) |
322 | } | 324 | } |
323 | 325 | ||
324 | static loadByUrl (url: string, transaction?: Transaction): Bluebird<MAccountDefault> { | 326 | static loadByUrl (url: string, transaction?: Transaction): Promise<MAccountDefault> { |
325 | const query = { | 327 | const query = { |
326 | include: [ | 328 | include: [ |
327 | { | 329 | { |
@@ -354,7 +356,7 @@ export class AccountModel extends Model<AccountModel> { | |||
354 | }) | 356 | }) |
355 | } | 357 | } |
356 | 358 | ||
357 | static loadAccountIdFromVideo (videoId: number): Bluebird<MAccount> { | 359 | static loadAccountIdFromVideo (videoId: number): Promise<MAccount> { |
358 | const query = { | 360 | const query = { |
359 | include: [ | 361 | include: [ |
360 | { | 362 | { |
@@ -377,7 +379,7 @@ export class AccountModel extends Model<AccountModel> { | |||
377 | return AccountModel.findOne(query) | 379 | return AccountModel.findOne(query) |
378 | } | 380 | } |
379 | 381 | ||
380 | static listLocalsForSitemap (sort: string): Bluebird<MAccountActor[]> { | 382 | static listLocalsForSitemap (sort: string): Promise<MAccountActor[]> { |
381 | const query = { | 383 | const query = { |
382 | attributes: [ ], | 384 | attributes: [ ], |
383 | offset: 0, | 385 | offset: 0, |
diff --git a/server/models/account/user-notification-setting.ts b/server/models/account/user-notification-setting.ts index acc192d53..ebab8b6d2 100644 --- a/server/models/account/user-notification-setting.ts +++ b/server/models/account/user-notification-setting.ts | |||
@@ -28,7 +28,7 @@ import { UserModel } from './user' | |||
28 | } | 28 | } |
29 | ] | 29 | ] |
30 | }) | 30 | }) |
31 | export class UserNotificationSettingModel extends Model<UserNotificationSettingModel> { | 31 | export class UserNotificationSettingModel extends Model { |
32 | 32 | ||
33 | @AllowNull(false) | 33 | @AllowNull(false) |
34 | @Default(null) | 34 | @Default(null) |
diff --git a/server/models/account/user-notification.ts b/server/models/account/user-notification.ts index 452574dc8..52b792a5b 100644 --- a/server/models/account/user-notification.ts +++ b/server/models/account/user-notification.ts | |||
@@ -254,7 +254,7 @@ function buildAccountInclude (required: boolean, withActor = false) { | |||
254 | } | 254 | } |
255 | ] as (ModelIndexesOptions & { where?: WhereOptions })[] | 255 | ] as (ModelIndexesOptions & { where?: WhereOptions })[] |
256 | }) | 256 | }) |
257 | export class UserNotificationModel extends Model<UserNotificationModel> { | 257 | export class UserNotificationModel extends Model { |
258 | 258 | ||
259 | @AllowNull(false) | 259 | @AllowNull(false) |
260 | @Default(null) | 260 | @Default(null) |
diff --git a/server/models/account/user-video-history.ts b/server/models/account/user-video-history.ts index 76b469fbf..45171fc60 100644 --- a/server/models/account/user-video-history.ts +++ b/server/models/account/user-video-history.ts | |||
@@ -19,7 +19,7 @@ import { MUserAccountId, MUserId } from '@server/types/models' | |||
19 | } | 19 | } |
20 | ] | 20 | ] |
21 | }) | 21 | }) |
22 | export class UserVideoHistoryModel extends Model<UserVideoHistoryModel> { | 22 | export class UserVideoHistoryModel extends Model { |
23 | @CreatedAt | 23 | @CreatedAt |
24 | createdAt: Date | 24 | createdAt: Date |
25 | 25 | ||
diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 10117099b..8e437c3be 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { values } from 'lodash' | 1 | import { values } from 'lodash' |
3 | import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize' | 2 | import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize' |
4 | import { | 3 | import { |
@@ -16,11 +15,11 @@ import { | |||
16 | HasOne, | 15 | HasOne, |
17 | Is, | 16 | Is, |
18 | IsEmail, | 17 | IsEmail, |
18 | IsUUID, | ||
19 | Model, | 19 | Model, |
20 | Scopes, | 20 | Scopes, |
21 | Table, | 21 | Table, |
22 | UpdatedAt, | 22 | UpdatedAt |
23 | IsUUID | ||
24 | } from 'sequelize-typescript' | 23 | } from 'sequelize-typescript' |
25 | import { | 24 | import { |
26 | MMyUserFormattable, | 25 | MMyUserFormattable, |
@@ -220,7 +219,7 @@ enum ScopeNames { | |||
220 | } | 219 | } |
221 | ] | 220 | ] |
222 | }) | 221 | }) |
223 | export class UserModel extends Model<UserModel> { | 222 | export class UserModel extends Model { |
224 | 223 | ||
225 | @AllowNull(true) | 224 | @AllowNull(true) |
226 | @Is('UserPassword', value => throwIfNotValid(value, isUserPasswordValid, 'user password', true)) | 225 | @Is('UserPassword', value => throwIfNotValid(value, isUserPasswordValid, 'user password', true)) |
@@ -483,7 +482,7 @@ export class UserModel extends Model<UserModel> { | |||
483 | }) | 482 | }) |
484 | } | 483 | } |
485 | 484 | ||
486 | static listWithRight (right: UserRight): Bluebird<MUserDefault[]> { | 485 | static listWithRight (right: UserRight): Promise<MUserDefault[]> { |
487 | const roles = Object.keys(USER_ROLE_LABELS) | 486 | const roles = Object.keys(USER_ROLE_LABELS) |
488 | .map(k => parseInt(k, 10) as UserRole) | 487 | .map(k => parseInt(k, 10) as UserRole) |
489 | .filter(role => hasUserRight(role, right)) | 488 | .filter(role => hasUserRight(role, right)) |
@@ -499,7 +498,7 @@ export class UserModel extends Model<UserModel> { | |||
499 | return UserModel.findAll(query) | 498 | return UserModel.findAll(query) |
500 | } | 499 | } |
501 | 500 | ||
502 | static listUserSubscribersOf (actorId: number): Bluebird<MUserWithNotificationSetting[]> { | 501 | static listUserSubscribersOf (actorId: number): Promise<MUserWithNotificationSetting[]> { |
503 | const query = { | 502 | const query = { |
504 | include: [ | 503 | include: [ |
505 | { | 504 | { |
@@ -538,7 +537,7 @@ export class UserModel extends Model<UserModel> { | |||
538 | return UserModel.unscoped().findAll(query) | 537 | return UserModel.unscoped().findAll(query) |
539 | } | 538 | } |
540 | 539 | ||
541 | static listByUsernames (usernames: string[]): Bluebird<MUserDefault[]> { | 540 | static listByUsernames (usernames: string[]): Promise<MUserDefault[]> { |
542 | const query = { | 541 | const query = { |
543 | where: { | 542 | where: { |
544 | username: usernames | 543 | username: usernames |
@@ -548,11 +547,11 @@ export class UserModel extends Model<UserModel> { | |||
548 | return UserModel.findAll(query) | 547 | return UserModel.findAll(query) |
549 | } | 548 | } |
550 | 549 | ||
551 | static loadById (id: number): Bluebird<MUser> { | 550 | static loadById (id: number): Promise<MUser> { |
552 | return UserModel.unscoped().findByPk(id) | 551 | return UserModel.unscoped().findByPk(id) |
553 | } | 552 | } |
554 | 553 | ||
555 | static loadByIdWithChannels (id: number, withStats = false): Bluebird<MUserDefault> { | 554 | static loadByIdWithChannels (id: number, withStats = false): Promise<MUserDefault> { |
556 | const scopes = [ | 555 | const scopes = [ |
557 | ScopeNames.WITH_VIDEOCHANNELS | 556 | ScopeNames.WITH_VIDEOCHANNELS |
558 | ] | 557 | ] |
@@ -562,7 +561,7 @@ export class UserModel extends Model<UserModel> { | |||
562 | return UserModel.scope(scopes).findByPk(id) | 561 | return UserModel.scope(scopes).findByPk(id) |
563 | } | 562 | } |
564 | 563 | ||
565 | static loadByUsername (username: string): Bluebird<MUserDefault> { | 564 | static loadByUsername (username: string): Promise<MUserDefault> { |
566 | const query = { | 565 | const query = { |
567 | where: { | 566 | where: { |
568 | username: { [Op.iLike]: username } | 567 | username: { [Op.iLike]: username } |
@@ -572,7 +571,7 @@ export class UserModel extends Model<UserModel> { | |||
572 | return UserModel.findOne(query) | 571 | return UserModel.findOne(query) |
573 | } | 572 | } |
574 | 573 | ||
575 | static loadForMeAPI (username: string): Bluebird<MUserNotifSettingChannelDefault> { | 574 | static loadForMeAPI (username: string): Promise<MUserNotifSettingChannelDefault> { |
576 | const query = { | 575 | const query = { |
577 | where: { | 576 | where: { |
578 | username: { [Op.iLike]: username } | 577 | username: { [Op.iLike]: username } |
@@ -582,7 +581,7 @@ export class UserModel extends Model<UserModel> { | |||
582 | return UserModel.scope(ScopeNames.FOR_ME_API).findOne(query) | 581 | return UserModel.scope(ScopeNames.FOR_ME_API).findOne(query) |
583 | } | 582 | } |
584 | 583 | ||
585 | static loadByEmail (email: string): Bluebird<MUserDefault> { | 584 | static loadByEmail (email: string): Promise<MUserDefault> { |
586 | const query = { | 585 | const query = { |
587 | where: { | 586 | where: { |
588 | 587 | ||
@@ -592,7 +591,7 @@ export class UserModel extends Model<UserModel> { | |||
592 | return UserModel.findOne(query) | 591 | return UserModel.findOne(query) |
593 | } | 592 | } |
594 | 593 | ||
595 | static loadByUsernameOrEmail (username: string, email?: string): Bluebird<MUserDefault> { | 594 | static loadByUsernameOrEmail (username: string, email?: string): Promise<MUserDefault> { |
596 | if (!email) email = username | 595 | if (!email) email = username |
597 | 596 | ||
598 | const query = { | 597 | const query = { |
@@ -608,7 +607,7 @@ export class UserModel extends Model<UserModel> { | |||
608 | return UserModel.findOne(query) | 607 | return UserModel.findOne(query) |
609 | } | 608 | } |
610 | 609 | ||
611 | static loadByVideoId (videoId: number): Bluebird<MUserDefault> { | 610 | static loadByVideoId (videoId: number): Promise<MUserDefault> { |
612 | const query = { | 611 | const query = { |
613 | include: [ | 612 | include: [ |
614 | { | 613 | { |
@@ -639,7 +638,7 @@ export class UserModel extends Model<UserModel> { | |||
639 | return UserModel.findOne(query) | 638 | return UserModel.findOne(query) |
640 | } | 639 | } |
641 | 640 | ||
642 | static loadByVideoImportId (videoImportId: number): Bluebird<MUserDefault> { | 641 | static loadByVideoImportId (videoImportId: number): Promise<MUserDefault> { |
643 | const query = { | 642 | const query = { |
644 | include: [ | 643 | include: [ |
645 | { | 644 | { |
@@ -656,7 +655,7 @@ export class UserModel extends Model<UserModel> { | |||
656 | return UserModel.findOne(query) | 655 | return UserModel.findOne(query) |
657 | } | 656 | } |
658 | 657 | ||
659 | static loadByChannelActorId (videoChannelActorId: number): Bluebird<MUserDefault> { | 658 | static loadByChannelActorId (videoChannelActorId: number): Promise<MUserDefault> { |
660 | const query = { | 659 | const query = { |
661 | include: [ | 660 | include: [ |
662 | { | 661 | { |
@@ -680,7 +679,7 @@ export class UserModel extends Model<UserModel> { | |||
680 | return UserModel.findOne(query) | 679 | return UserModel.findOne(query) |
681 | } | 680 | } |
682 | 681 | ||
683 | static loadByAccountActorId (accountActorId: number): Bluebird<MUserDefault> { | 682 | static loadByAccountActorId (accountActorId: number): Promise<MUserDefault> { |
684 | const query = { | 683 | const query = { |
685 | include: [ | 684 | include: [ |
686 | { | 685 | { |
@@ -697,7 +696,7 @@ export class UserModel extends Model<UserModel> { | |||
697 | return UserModel.findOne(query) | 696 | return UserModel.findOne(query) |
698 | } | 697 | } |
699 | 698 | ||
700 | static loadByLiveId (liveId: number): Bluebird<MUser> { | 699 | static loadByLiveId (liveId: number): Promise<MUser> { |
701 | const query = { | 700 | const query = { |
702 | include: [ | 701 | include: [ |
703 | { | 702 | { |
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts index 58bc63d34..ce6a4e267 100644 --- a/server/models/activitypub/actor-follow.ts +++ b/server/models/activitypub/actor-follow.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { difference, values } from 'lodash' | 1 | import { difference, values } from 'lodash' |
3 | import { IncludeOptions, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' | 2 | import { IncludeOptions, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' |
4 | import { | 3 | import { |
@@ -62,7 +61,7 @@ import { ActorModel, unusedActorAttributesForAPI } from './actor' | |||
62 | } | 61 | } |
63 | ] | 62 | ] |
64 | }) | 63 | }) |
65 | export class ActorFollowModel extends Model<ActorFollowModel> { | 64 | export class ActorFollowModel extends Model { |
66 | 65 | ||
67 | @AllowNull(false) | 66 | @AllowNull(false) |
68 | @Column(DataType.ENUM(...values(FOLLOW_STATES))) | 67 | @Column(DataType.ENUM(...values(FOLLOW_STATES))) |
@@ -176,7 +175,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
176 | .then(results => results.length === 1) | 175 | .then(results => results.length === 1) |
177 | } | 176 | } |
178 | 177 | ||
179 | static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Transaction): Bluebird<MActorFollowActorsDefault> { | 178 | static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Transaction): Promise<MActorFollowActorsDefault> { |
180 | const query = { | 179 | const query = { |
181 | where: { | 180 | where: { |
182 | actorId, | 181 | actorId, |
@@ -205,7 +204,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
205 | targetName: string, | 204 | targetName: string, |
206 | targetHost: string, | 205 | targetHost: string, |
207 | t?: Transaction | 206 | t?: Transaction |
208 | ): Bluebird<MActorFollowActorsDefaultSubscription> { | 207 | ): Promise<MActorFollowActorsDefaultSubscription> { |
209 | const actorFollowingPartInclude: IncludeOptions = { | 208 | const actorFollowingPartInclude: IncludeOptions = { |
210 | model: ActorModel, | 209 | model: ActorModel, |
211 | required: true, | 210 | required: true, |
@@ -258,7 +257,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
258 | }) | 257 | }) |
259 | } | 258 | } |
260 | 259 | ||
261 | static listSubscribedIn (actorId: number, targets: { name: string, host?: string }[]): Bluebird<MActorFollowFollowingHost[]> { | 260 | static listSubscribedIn (actorId: number, targets: { name: string, host?: string }[]): Promise<MActorFollowFollowingHost[]> { |
262 | const whereTab = targets | 261 | const whereTab = targets |
263 | .map(t => { | 262 | .map(t => { |
264 | if (t.host) { | 263 | if (t.host) { |
@@ -287,7 +286,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
287 | }) | 286 | }) |
288 | 287 | ||
289 | const query = { | 288 | const query = { |
290 | attributes: [], | 289 | attributes: [ 'id' ], |
291 | where: { | 290 | where: { |
292 | [Op.and]: [ | 291 | [Op.and]: [ |
293 | { | 292 | { |
@@ -671,7 +670,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
671 | 670 | ||
672 | selections.push('COUNT(*) AS "total"') | 671 | selections.push('COUNT(*) AS "total"') |
673 | 672 | ||
674 | const tasks: Bluebird<any>[] = [] | 673 | const tasks: Promise<any>[] = [] |
675 | 674 | ||
676 | for (const selection of selections) { | 675 | for (const selection of selections) { |
677 | let query = 'SELECT ' + selection + ' FROM "actor" ' + | 676 | let query = 'SELECT ' + selection + ' FROM "actor" ' + |
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index a2fee0012..3b98e8841 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { values } from 'lodash' | 1 | import { values } from 'lodash' |
2 | import { extname } from 'path' | 2 | import { extname } from 'path' |
3 | import { literal, Op, Transaction } from 'sequelize' | ||
3 | import { | 4 | import { |
4 | AllowNull, | 5 | AllowNull, |
5 | BelongsTo, | 6 | BelongsTo, |
@@ -16,6 +17,7 @@ import { | |||
16 | Table, | 17 | Table, |
17 | UpdatedAt | 18 | UpdatedAt |
18 | } from 'sequelize-typescript' | 19 | } from 'sequelize-typescript' |
20 | import { ModelCache } from '@server/models/model-cache' | ||
19 | import { ActivityIconObject, ActivityPubActorType } from '../../../shared/models/activitypub' | 21 | import { ActivityIconObject, ActivityPubActorType } from '../../../shared/models/activitypub' |
20 | import { Avatar } from '../../../shared/models/avatars/avatar.model' | 22 | import { Avatar } from '../../../shared/models/avatars/avatar.model' |
21 | import { activityPubContextify } from '../../helpers/activitypub' | 23 | import { activityPubContextify } from '../../helpers/activitypub' |
@@ -28,13 +30,6 @@ import { | |||
28 | } from '../../helpers/custom-validators/activitypub/actor' | 30 | } from '../../helpers/custom-validators/activitypub/actor' |
29 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 31 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
30 | import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONSTRAINTS_FIELDS, SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' | 32 | import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONSTRAINTS_FIELDS, SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' |
31 | import { AccountModel } from '../account/account' | ||
32 | import { AvatarModel } from '../avatar/avatar' | ||
33 | import { ServerModel } from '../server/server' | ||
34 | import { isOutdated, throwIfNotValid } from '../utils' | ||
35 | import { VideoChannelModel } from '../video/video-channel' | ||
36 | import { ActorFollowModel } from './actor-follow' | ||
37 | import { VideoModel } from '../video/video' | ||
38 | import { | 33 | import { |
39 | MActor, | 34 | MActor, |
40 | MActorAccountChannelId, | 35 | MActorAccountChannelId, |
@@ -43,12 +38,17 @@ import { | |||
43 | MActorFull, | 38 | MActorFull, |
44 | MActorHost, | 39 | MActorHost, |
45 | MActorServer, | 40 | MActorServer, |
46 | MActorSummaryFormattable, MActorUrl, | 41 | MActorSummaryFormattable, |
42 | MActorUrl, | ||
47 | MActorWithInboxes | 43 | MActorWithInboxes |
48 | } from '../../types/models' | 44 | } from '../../types/models' |
49 | import * as Bluebird from 'bluebird' | 45 | import { AccountModel } from '../account/account' |
50 | import { Op, Transaction, literal } from 'sequelize' | 46 | import { AvatarModel } from '../avatar/avatar' |
51 | import { ModelCache } from '@server/models/model-cache' | 47 | import { ServerModel } from '../server/server' |
48 | import { isOutdated, throwIfNotValid } from '../utils' | ||
49 | import { VideoModel } from '../video/video' | ||
50 | import { VideoChannelModel } from '../video/video-channel' | ||
51 | import { ActorFollowModel } from './actor-follow' | ||
52 | 52 | ||
53 | enum ScopeNames { | 53 | enum ScopeNames { |
54 | FULL = 'FULL' | 54 | FULL = 'FULL' |
@@ -146,7 +146,7 @@ export const unusedActorAttributesForAPI = [ | |||
146 | } | 146 | } |
147 | ] | 147 | ] |
148 | }) | 148 | }) |
149 | export class ActorModel extends Model<ActorModel> { | 149 | export class ActorModel extends Model { |
150 | 150 | ||
151 | @AllowNull(false) | 151 | @AllowNull(false) |
152 | @Column(DataType.ENUM(...values(ACTIVITY_PUB_ACTOR_TYPES))) | 152 | @Column(DataType.ENUM(...values(ACTIVITY_PUB_ACTOR_TYPES))) |
@@ -276,15 +276,15 @@ export class ActorModel extends Model<ActorModel> { | |||
276 | }) | 276 | }) |
277 | VideoChannel: VideoChannelModel | 277 | VideoChannel: VideoChannelModel |
278 | 278 | ||
279 | static load (id: number): Bluebird<MActor> { | 279 | static load (id: number): Promise<MActor> { |
280 | return ActorModel.unscoped().findByPk(id) | 280 | return ActorModel.unscoped().findByPk(id) |
281 | } | 281 | } |
282 | 282 | ||
283 | static loadFull (id: number): Bluebird<MActorFull> { | 283 | static loadFull (id: number): Promise<MActorFull> { |
284 | return ActorModel.scope(ScopeNames.FULL).findByPk(id) | 284 | return ActorModel.scope(ScopeNames.FULL).findByPk(id) |
285 | } | 285 | } |
286 | 286 | ||
287 | static loadFromAccountByVideoId (videoId: number, transaction: Transaction): Bluebird<MActor> { | 287 | static loadFromAccountByVideoId (videoId: number, transaction: Transaction): Promise<MActor> { |
288 | const query = { | 288 | const query = { |
289 | include: [ | 289 | include: [ |
290 | { | 290 | { |
@@ -328,7 +328,7 @@ export class ActorModel extends Model<ActorModel> { | |||
328 | .then(a => !!a) | 328 | .then(a => !!a) |
329 | } | 329 | } |
330 | 330 | ||
331 | static listByFollowersUrls (followersUrls: string[], transaction?: Transaction): Bluebird<MActorFull[]> { | 331 | static listByFollowersUrls (followersUrls: string[], transaction?: Transaction): Promise<MActorFull[]> { |
332 | const query = { | 332 | const query = { |
333 | where: { | 333 | where: { |
334 | followersUrl: { | 334 | followersUrl: { |
@@ -341,7 +341,7 @@ export class ActorModel extends Model<ActorModel> { | |||
341 | return ActorModel.scope(ScopeNames.FULL).findAll(query) | 341 | return ActorModel.scope(ScopeNames.FULL).findAll(query) |
342 | } | 342 | } |
343 | 343 | ||
344 | static loadLocalByName (preferredUsername: string, transaction?: Transaction): Bluebird<MActorFull> { | 344 | static loadLocalByName (preferredUsername: string, transaction?: Transaction): Promise<MActorFull> { |
345 | const fun = () => { | 345 | const fun = () => { |
346 | const query = { | 346 | const query = { |
347 | where: { | 347 | where: { |
@@ -364,7 +364,7 @@ export class ActorModel extends Model<ActorModel> { | |||
364 | }) | 364 | }) |
365 | } | 365 | } |
366 | 366 | ||
367 | static loadLocalUrlByName (preferredUsername: string, transaction?: Transaction): Bluebird<MActorUrl> { | 367 | static loadLocalUrlByName (preferredUsername: string, transaction?: Transaction): Promise<MActorUrl> { |
368 | const fun = () => { | 368 | const fun = () => { |
369 | const query = { | 369 | const query = { |
370 | attributes: [ 'url' ], | 370 | attributes: [ 'url' ], |
@@ -388,7 +388,7 @@ export class ActorModel extends Model<ActorModel> { | |||
388 | }) | 388 | }) |
389 | } | 389 | } |
390 | 390 | ||
391 | static loadByNameAndHost (preferredUsername: string, host: string): Bluebird<MActorFull> { | 391 | static loadByNameAndHost (preferredUsername: string, host: string): Promise<MActorFull> { |
392 | const query = { | 392 | const query = { |
393 | where: { | 393 | where: { |
394 | preferredUsername | 394 | preferredUsername |
@@ -407,7 +407,7 @@ export class ActorModel extends Model<ActorModel> { | |||
407 | return ActorModel.scope(ScopeNames.FULL).findOne(query) | 407 | return ActorModel.scope(ScopeNames.FULL).findOne(query) |
408 | } | 408 | } |
409 | 409 | ||
410 | static loadByUrl (url: string, transaction?: Transaction): Bluebird<MActorAccountChannelId> { | 410 | static loadByUrl (url: string, transaction?: Transaction): Promise<MActorAccountChannelId> { |
411 | const query = { | 411 | const query = { |
412 | where: { | 412 | where: { |
413 | url | 413 | url |
@@ -430,7 +430,7 @@ export class ActorModel extends Model<ActorModel> { | |||
430 | return ActorModel.unscoped().findOne(query) | 430 | return ActorModel.unscoped().findOne(query) |
431 | } | 431 | } |
432 | 432 | ||
433 | static loadByUrlAndPopulateAccountAndChannel (url: string, transaction?: Transaction): Bluebird<MActorFull> { | 433 | static loadByUrlAndPopulateAccountAndChannel (url: string, transaction?: Transaction): Promise<MActorFull> { |
434 | const query = { | 434 | const query = { |
435 | where: { | 435 | where: { |
436 | url | 436 | url |
@@ -461,7 +461,7 @@ export class ActorModel extends Model<ActorModel> { | |||
461 | }, { where, transaction }) | 461 | }, { where, transaction }) |
462 | } | 462 | } |
463 | 463 | ||
464 | static loadAccountActorByVideoId (videoId: number): Bluebird<MActor> { | 464 | static loadAccountActorByVideoId (videoId: number): Promise<MActor> { |
465 | const query = { | 465 | const query = { |
466 | include: [ | 466 | include: [ |
467 | { | 467 | { |
diff --git a/server/models/application/application.ts b/server/models/application/application.ts index 3bba2c70e..909569de1 100644 --- a/server/models/application/application.ts +++ b/server/models/application/application.ts | |||
@@ -24,7 +24,7 @@ export const getServerActor = memoizee(async function () { | |||
24 | tableName: 'application', | 24 | tableName: 'application', |
25 | timestamps: false | 25 | timestamps: false |
26 | }) | 26 | }) |
27 | export class ApplicationModel extends Model<ApplicationModel> { | 27 | export class ApplicationModel extends Model { |
28 | 28 | ||
29 | @AllowNull(false) | 29 | @AllowNull(false) |
30 | @Default(0) | 30 | @Default(0) |
diff --git a/server/models/avatar/avatar.ts b/server/models/avatar/avatar.ts index d874dec99..0d246a144 100644 --- a/server/models/avatar/avatar.ts +++ b/server/models/avatar/avatar.ts | |||
@@ -18,7 +18,7 @@ import { MAvatarFormattable } from '@server/types/models' | |||
18 | } | 18 | } |
19 | ] | 19 | ] |
20 | }) | 20 | }) |
21 | export class AvatarModel extends Model<AvatarModel> { | 21 | export class AvatarModel extends Model { |
22 | 22 | ||
23 | @AllowNull(false) | 23 | @AllowNull(false) |
24 | @Column | 24 | @Column |
diff --git a/server/models/model-cache.ts b/server/models/model-cache.ts index a87f99aa2..eafb5c13c 100644 --- a/server/models/model-cache.ts +++ b/server/models/model-cache.ts | |||
@@ -40,7 +40,7 @@ class ModelCache { | |||
40 | doCache<T extends Model> (options: { | 40 | doCache<T extends Model> (options: { |
41 | cacheType: ModelCacheType | 41 | cacheType: ModelCacheType |
42 | key: string | 42 | key: string |
43 | fun: () => Bluebird<T> | 43 | fun: () => Promise<T> |
44 | whitelist?: () => boolean | 44 | whitelist?: () => boolean |
45 | deleteKey?: DeleteKey | 45 | deleteKey?: DeleteKey |
46 | }) { | 46 | }) { |
diff --git a/server/models/oauth/oauth-client.ts b/server/models/oauth/oauth-client.ts index 42c59bb79..8dbc1c2f5 100644 --- a/server/models/oauth/oauth-client.ts +++ b/server/models/oauth/oauth-client.ts | |||
@@ -14,7 +14,7 @@ import { OAuthTokenModel } from './oauth-token' | |||
14 | } | 14 | } |
15 | ] | 15 | ] |
16 | }) | 16 | }) |
17 | export class OAuthClientModel extends Model<OAuthClientModel> { | 17 | export class OAuthClientModel extends Model { |
18 | 18 | ||
19 | @AllowNull(false) | 19 | @AllowNull(false) |
20 | @Column | 20 | @Column |
diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts index 7f2313dad..6bc6cf27c 100644 --- a/server/models/oauth/oauth-token.ts +++ b/server/models/oauth/oauth-token.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import { Transaction } from 'sequelize' | ||
1 | import { | 2 | import { |
2 | AfterDestroy, | 3 | AfterDestroy, |
3 | AfterUpdate, | 4 | AfterUpdate, |
@@ -11,15 +12,13 @@ import { | |||
11 | Table, | 12 | Table, |
12 | UpdatedAt | 13 | UpdatedAt |
13 | } from 'sequelize-typescript' | 14 | } from 'sequelize-typescript' |
15 | import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token' | ||
14 | import { logger } from '../../helpers/logger' | 16 | import { logger } from '../../helpers/logger' |
15 | import { UserModel } from '../account/user' | 17 | import { clearCacheByToken } from '../../lib/oauth-model' |
16 | import { OAuthClientModel } from './oauth-client' | ||
17 | import { Transaction } from 'sequelize' | ||
18 | import { AccountModel } from '../account/account' | 18 | import { AccountModel } from '../account/account' |
19 | import { UserModel } from '../account/user' | ||
19 | import { ActorModel } from '../activitypub/actor' | 20 | import { ActorModel } from '../activitypub/actor' |
20 | import { clearCacheByToken } from '../../lib/oauth-model' | 21 | import { OAuthClientModel } from './oauth-client' |
21 | import * as Bluebird from 'bluebird' | ||
22 | import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token' | ||
23 | 22 | ||
24 | export type OAuthTokenInfo = { | 23 | export type OAuthTokenInfo = { |
25 | refreshToken: string | 24 | refreshToken: string |
@@ -80,7 +79,7 @@ enum ScopeNames { | |||
80 | } | 79 | } |
81 | ] | 80 | ] |
82 | }) | 81 | }) |
83 | export class OAuthTokenModel extends Model<OAuthTokenModel> { | 82 | export class OAuthTokenModel extends Model { |
84 | 83 | ||
85 | @AllowNull(false) | 84 | @AllowNull(false) |
86 | @Column | 85 | @Column |
@@ -174,7 +173,7 @@ export class OAuthTokenModel extends Model<OAuthTokenModel> { | |||
174 | }) | 173 | }) |
175 | } | 174 | } |
176 | 175 | ||
177 | static getByTokenAndPopulateUser (bearerToken: string): Bluebird<MOAuthTokenUser> { | 176 | static getByTokenAndPopulateUser (bearerToken: string): Promise<MOAuthTokenUser> { |
178 | const query = { | 177 | const query = { |
179 | where: { | 178 | where: { |
180 | accessToken: bearerToken | 179 | accessToken: bearerToken |
@@ -190,7 +189,7 @@ export class OAuthTokenModel extends Model<OAuthTokenModel> { | |||
190 | }) | 189 | }) |
191 | } | 190 | } |
192 | 191 | ||
193 | static getByRefreshTokenAndPopulateUser (refreshToken: string): Bluebird<MOAuthTokenUser> { | 192 | static getByRefreshTokenAndPopulateUser (refreshToken: string): Promise<MOAuthTokenUser> { |
194 | const query = { | 193 | const query = { |
195 | where: { | 194 | where: { |
196 | refreshToken | 195 | refreshToken |
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index 1b967996c..fa96a1e39 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts | |||
@@ -1,3 +1,5 @@ | |||
1 | import { sample } from 'lodash' | ||
2 | import { col, FindOptions, fn, literal, Op, Transaction, WhereOptions } from 'sequelize' | ||
1 | import { | 3 | import { |
2 | AllowNull, | 4 | AllowNull, |
3 | BeforeDestroy, | 5 | BeforeDestroy, |
@@ -12,23 +14,7 @@ import { | |||
12 | Table, | 14 | Table, |
13 | UpdatedAt | 15 | UpdatedAt |
14 | } from 'sequelize-typescript' | 16 | } from 'sequelize-typescript' |
15 | import { ActorModel } from '../activitypub/actor' | 17 | import { getServerActor } from '@server/models/application/application' |
16 | import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../utils' | ||
17 | import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
18 | import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers/constants' | ||
19 | import { VideoFileModel } from '../video/video-file' | ||
20 | import { VideoModel } from '../video/video' | ||
21 | import { VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../shared/models/redundancy' | ||
22 | import { logger } from '../../helpers/logger' | ||
23 | import { CacheFileObject, VideoPrivacy } from '../../../shared' | ||
24 | import { VideoChannelModel } from '../video/video-channel' | ||
25 | import { ServerModel } from '../server/server' | ||
26 | import { sample } from 'lodash' | ||
27 | import { isTestInstance } from '../../helpers/core-utils' | ||
28 | import * as Bluebird from 'bluebird' | ||
29 | import { col, FindOptions, fn, literal, Op, Transaction, WhereOptions } from 'sequelize' | ||
30 | import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist' | ||
31 | import { CONFIG } from '../../initializers/config' | ||
32 | import { MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models' | 18 | import { MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models' |
33 | import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model' | 19 | import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model' |
34 | import { | 20 | import { |
@@ -36,7 +22,20 @@ import { | |||
36 | StreamingPlaylistRedundancyInformation, | 22 | StreamingPlaylistRedundancyInformation, |
37 | VideoRedundancy | 23 | VideoRedundancy |
38 | } from '@shared/models/redundancy/video-redundancy.model' | 24 | } from '@shared/models/redundancy/video-redundancy.model' |
39 | import { getServerActor } from '@server/models/application/application' | 25 | import { CacheFileObject, VideoPrivacy } from '../../../shared' |
26 | import { VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../shared/models/redundancy' | ||
27 | import { isTestInstance } from '../../helpers/core-utils' | ||
28 | import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
29 | import { logger } from '../../helpers/logger' | ||
30 | import { CONFIG } from '../../initializers/config' | ||
31 | import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers/constants' | ||
32 | import { ActorModel } from '../activitypub/actor' | ||
33 | import { ServerModel } from '../server/server' | ||
34 | import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../utils' | ||
35 | import { VideoModel } from '../video/video' | ||
36 | import { VideoChannelModel } from '../video/video-channel' | ||
37 | import { VideoFileModel } from '../video/video-file' | ||
38 | import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist' | ||
40 | 39 | ||
41 | export enum ScopeNames { | 40 | export enum ScopeNames { |
42 | WITH_VIDEO = 'WITH_VIDEO' | 41 | WITH_VIDEO = 'WITH_VIDEO' |
@@ -84,7 +83,7 @@ export enum ScopeNames { | |||
84 | } | 83 | } |
85 | ] | 84 | ] |
86 | }) | 85 | }) |
87 | export class VideoRedundancyModel extends Model<VideoRedundancyModel> { | 86 | export class VideoRedundancyModel extends Model { |
88 | 87 | ||
89 | @CreatedAt | 88 | @CreatedAt |
90 | createdAt: Date | 89 | createdAt: Date |
@@ -199,7 +198,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> { | |||
199 | return VideoRedundancyModel.scope(ScopeNames.WITH_VIDEO).findOne(query) | 198 | return VideoRedundancyModel.scope(ScopeNames.WITH_VIDEO).findOne(query) |
200 | } | 199 | } |
201 | 200 | ||
202 | static loadByIdWithVideo (id: number, transaction?: Transaction): Bluebird<MVideoRedundancyVideo> { | 201 | static loadByIdWithVideo (id: number, transaction?: Transaction): Promise<MVideoRedundancyVideo> { |
203 | const query = { | 202 | const query = { |
204 | where: { id }, | 203 | where: { id }, |
205 | transaction | 204 | transaction |
@@ -208,7 +207,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> { | |||
208 | return VideoRedundancyModel.scope(ScopeNames.WITH_VIDEO).findOne(query) | 207 | return VideoRedundancyModel.scope(ScopeNames.WITH_VIDEO).findOne(query) |
209 | } | 208 | } |
210 | 209 | ||
211 | static loadByUrl (url: string, transaction?: Transaction): Bluebird<MVideoRedundancy> { | 210 | static loadByUrl (url: string, transaction?: Transaction): Promise<MVideoRedundancy> { |
212 | const query = { | 211 | const query = { |
213 | where: { | 212 | where: { |
214 | url | 213 | url |
@@ -251,7 +250,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> { | |||
251 | .then(r => !!r) | 250 | .then(r => !!r) |
252 | } | 251 | } |
253 | 252 | ||
254 | static async getVideoSample (p: Bluebird<VideoModel[]>) { | 253 | static async getVideoSample (p: Promise<VideoModel[]>) { |
255 | const rows = await p | 254 | const rows = await p |
256 | if (rows.length === 0) return undefined | 255 | if (rows.length === 0) return undefined |
257 | 256 | ||
@@ -696,7 +695,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> { | |||
696 | 695 | ||
697 | const notIn = literal( | 696 | const notIn = literal( |
698 | '(' + | 697 | '(' + |
699 | `SELECT "videoFileId" FROM "videoRedundancy" WHERE "actorId" = ${actor.id} AND "videoFileId" IS NOT NULL` + | 698 | `SELECT "videoFileId" FROM "videoRedundancy" WHERE "actorId" = ${actor.id} AND "videoFileId" IS NOT NULL` + |
700 | ')' | 699 | ')' |
701 | ) | 700 | ) |
702 | 701 | ||
diff --git a/server/models/server/plugin.ts b/server/models/server/plugin.ts index 95fb386b5..82387af6a 100644 --- a/server/models/server/plugin.ts +++ b/server/models/server/plugin.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { FindAndCountOptions, json, QueryTypes } from 'sequelize' | 1 | import { FindAndCountOptions, json, QueryTypes } from 'sequelize' |
3 | import { AllowNull, Column, CreatedAt, DataType, DefaultScope, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, Column, CreatedAt, DataType, DefaultScope, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
4 | import { MPlugin, MPluginFormattable } from '@server/types/models' | 3 | import { MPlugin, MPluginFormattable } from '@server/types/models' |
@@ -29,7 +28,7 @@ import { getSort, throwIfNotValid } from '../utils' | |||
29 | } | 28 | } |
30 | ] | 29 | ] |
31 | }) | 30 | }) |
32 | export class PluginModel extends Model<PluginModel> { | 31 | export class PluginModel extends Model { |
33 | 32 | ||
34 | @AllowNull(false) | 33 | @AllowNull(false) |
35 | @Is('PluginName', value => throwIfNotValid(value, isPluginNameValid, 'name')) | 34 | @Is('PluginName', value => throwIfNotValid(value, isPluginNameValid, 'name')) |
@@ -87,7 +86,7 @@ export class PluginModel extends Model<PluginModel> { | |||
87 | @UpdatedAt | 86 | @UpdatedAt |
88 | updatedAt: Date | 87 | updatedAt: Date |
89 | 88 | ||
90 | static listEnabledPluginsAndThemes (): Bluebird<MPlugin[]> { | 89 | static listEnabledPluginsAndThemes (): Promise<MPlugin[]> { |
91 | const query = { | 90 | const query = { |
92 | where: { | 91 | where: { |
93 | enabled: true, | 92 | enabled: true, |
@@ -98,7 +97,7 @@ export class PluginModel extends Model<PluginModel> { | |||
98 | return PluginModel.findAll(query) | 97 | return PluginModel.findAll(query) |
99 | } | 98 | } |
100 | 99 | ||
101 | static loadByNpmName (npmName: string): Bluebird<MPlugin> { | 100 | static loadByNpmName (npmName: string): Promise<MPlugin> { |
102 | const name = this.normalizePluginName(npmName) | 101 | const name = this.normalizePluginName(npmName) |
103 | const type = this.getTypeFromNpmName(npmName) | 102 | const type = this.getTypeFromNpmName(npmName) |
104 | 103 | ||
@@ -252,7 +251,7 @@ export class PluginModel extends Model<PluginModel> { | |||
252 | }) | 251 | }) |
253 | } | 252 | } |
254 | 253 | ||
255 | static listInstalled (): Bluebird<MPlugin[]> { | 254 | static listInstalled (): Promise<MPlugin[]> { |
256 | const query = { | 255 | const query = { |
257 | where: { | 256 | where: { |
258 | uninstalled: false | 257 | uninstalled: false |
diff --git a/server/models/server/server-blocklist.ts b/server/models/server/server-blocklist.ts index 68cd72ee7..4dc236537 100644 --- a/server/models/server/server-blocklist.ts +++ b/server/models/server/server-blocklist.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { Op } from 'sequelize' | 1 | import { Op } from 'sequelize' |
3 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
4 | import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/types/models' | 3 | import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/types/models' |
@@ -43,7 +42,7 @@ enum ScopeNames { | |||
43 | } | 42 | } |
44 | ] | 43 | ] |
45 | }) | 44 | }) |
46 | export class ServerBlocklistModel extends Model<ServerBlocklistModel> { | 45 | export class ServerBlocklistModel extends Model { |
47 | 46 | ||
48 | @CreatedAt | 47 | @CreatedAt |
49 | createdAt: Date | 48 | createdAt: Date |
@@ -101,7 +100,7 @@ export class ServerBlocklistModel extends Model<ServerBlocklistModel> { | |||
101 | }) | 100 | }) |
102 | } | 101 | } |
103 | 102 | ||
104 | static loadByAccountAndHost (accountId: number, host: string): Bluebird<MServerBlocklist> { | 103 | static loadByAccountAndHost (accountId: number, host: string): Promise<MServerBlocklist> { |
105 | const query = { | 104 | const query = { |
106 | where: { | 105 | where: { |
107 | accountId | 106 | accountId |
@@ -120,7 +119,7 @@ export class ServerBlocklistModel extends Model<ServerBlocklistModel> { | |||
120 | return ServerBlocklistModel.findOne(query) | 119 | return ServerBlocklistModel.findOne(query) |
121 | } | 120 | } |
122 | 121 | ||
123 | static listHostsBlockedBy (accountIds: number[]): Bluebird<string[]> { | 122 | static listHostsBlockedBy (accountIds: number[]): Promise<string[]> { |
124 | const query = { | 123 | const query = { |
125 | attributes: [ ], | 124 | attributes: [ ], |
126 | where: { | 125 | where: { |
diff --git a/server/models/server/server.ts b/server/models/server/server.ts index 771200797..0e58beeaf 100644 --- a/server/models/server/server.ts +++ b/server/models/server/server.ts | |||
@@ -1,10 +1,9 @@ | |||
1 | import { AllowNull, Column, CreatedAt, Default, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AllowNull, Column, CreatedAt, Default, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { MServer, MServerFormattable } from '@server/types/models/server' | ||
2 | import { isHostValid } from '../../helpers/custom-validators/servers' | 3 | import { isHostValid } from '../../helpers/custom-validators/servers' |
3 | import { ActorModel } from '../activitypub/actor' | 4 | import { ActorModel } from '../activitypub/actor' |
4 | import { throwIfNotValid } from '../utils' | 5 | import { throwIfNotValid } from '../utils' |
5 | import { ServerBlocklistModel } from './server-blocklist' | 6 | import { ServerBlocklistModel } from './server-blocklist' |
6 | import * as Bluebird from 'bluebird' | ||
7 | import { MServer, MServerFormattable } from '@server/types/models/server' | ||
8 | 7 | ||
9 | @Table({ | 8 | @Table({ |
10 | tableName: 'server', | 9 | tableName: 'server', |
@@ -15,7 +14,7 @@ import { MServer, MServerFormattable } from '@server/types/models/server' | |||
15 | } | 14 | } |
16 | ] | 15 | ] |
17 | }) | 16 | }) |
18 | export class ServerModel extends Model<ServerModel> { | 17 | export class ServerModel extends Model { |
19 | 18 | ||
20 | @AllowNull(false) | 19 | @AllowNull(false) |
21 | @Is('Host', value => throwIfNotValid(value, isHostValid, 'valid host')) | 20 | @Is('Host', value => throwIfNotValid(value, isHostValid, 'valid host')) |
@@ -51,7 +50,7 @@ export class ServerModel extends Model<ServerModel> { | |||
51 | }) | 50 | }) |
52 | BlockedByAccounts: ServerBlocklistModel[] | 51 | BlockedByAccounts: ServerBlocklistModel[] |
53 | 52 | ||
54 | static load (id: number): Bluebird<MServer> { | 53 | static load (id: number): Promise<MServer> { |
55 | const query = { | 54 | const query = { |
56 | where: { | 55 | where: { |
57 | id | 56 | id |
@@ -61,7 +60,7 @@ export class ServerModel extends Model<ServerModel> { | |||
61 | return ServerModel.findOne(query) | 60 | return ServerModel.findOne(query) |
62 | } | 61 | } |
63 | 62 | ||
64 | static loadByHost (host: string): Bluebird<MServer> { | 63 | static loadByHost (host: string): Promise<MServer> { |
65 | const query = { | 64 | const query = { |
66 | where: { | 65 | where: { |
67 | host | 66 | host |
diff --git a/server/models/utils.ts b/server/models/utils.ts index a06d57831..143c1a23c 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts | |||
@@ -113,7 +113,8 @@ function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldN | |||
113 | function buildTrigramSearchIndex (indexName: string, attribute: string) { | 113 | function buildTrigramSearchIndex (indexName: string, attribute: string) { |
114 | return { | 114 | return { |
115 | name: indexName, | 115 | name: indexName, |
116 | fields: [ Sequelize.literal('lower(immutable_unaccent(' + attribute + '))') as any ], | 116 | // FIXME: gin_trgm_ops is not taken into account in Sequelize 6, so adding it ourselves in the literal function |
117 | fields: [ Sequelize.literal('lower(immutable_unaccent(' + attribute + ')) gin_trgm_ops') as any ], | ||
117 | using: 'gin', | 118 | using: 'gin', |
118 | operator: 'gin_trgm_ops' | 119 | operator: 'gin_trgm_ops' |
119 | } | 120 | } |
diff --git a/server/models/video/schedule-video-update.ts b/server/models/video/schedule-video-update.ts index 1ce6bbfe5..22b08e91a 100644 --- a/server/models/video/schedule-video-update.ts +++ b/server/models/video/schedule-video-update.ts | |||
@@ -16,7 +16,7 @@ import { MScheduleVideoUpdateFormattable, MScheduleVideoUpdateVideoAll } from '@ | |||
16 | } | 16 | } |
17 | ] | 17 | ] |
18 | }) | 18 | }) |
19 | export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> { | 19 | export class ScheduleVideoUpdateModel extends Model { |
20 | 20 | ||
21 | @AllowNull(false) | 21 | @AllowNull(false) |
22 | @Default(null) | 22 | @Default(null) |
diff --git a/server/models/video/tag.ts b/server/models/video/tag.ts index adbc4fb7d..d04205703 100644 --- a/server/models/video/tag.ts +++ b/server/models/video/tag.ts | |||
@@ -1,12 +1,11 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import { col, fn, QueryTypes, Transaction } from 'sequelize' |
2 | import { fn, QueryTypes, Transaction, col } from 'sequelize' | ||
3 | import { AllowNull, BelongsToMany, Column, CreatedAt, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsToMany, Column, CreatedAt, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { MTag } from '@server/types/models' | ||
4 | import { VideoPrivacy, VideoState } from '../../../shared/models/videos' | ||
4 | import { isVideoTagValid } from '../../helpers/custom-validators/videos' | 5 | import { isVideoTagValid } from '../../helpers/custom-validators/videos' |
5 | import { throwIfNotValid } from '../utils' | 6 | import { throwIfNotValid } from '../utils' |
6 | import { VideoModel } from './video' | 7 | import { VideoModel } from './video' |
7 | import { VideoTagModel } from './video-tag' | 8 | import { VideoTagModel } from './video-tag' |
8 | import { VideoPrivacy, VideoState } from '../../../shared/models/videos' | ||
9 | import { MTag } from '@server/types/models' | ||
10 | 9 | ||
11 | @Table({ | 10 | @Table({ |
12 | tableName: 'tag', | 11 | tableName: 'tag', |
@@ -22,7 +21,7 @@ import { MTag } from '@server/types/models' | |||
22 | } | 21 | } |
23 | ] | 22 | ] |
24 | }) | 23 | }) |
25 | export class TagModel extends Model<TagModel> { | 24 | export class TagModel extends Model { |
26 | 25 | ||
27 | @AllowNull(false) | 26 | @AllowNull(false) |
28 | @Is('VideoTag', value => throwIfNotValid(value, isVideoTagValid, 'tag')) | 27 | @Is('VideoTag', value => throwIfNotValid(value, isVideoTagValid, 'tag')) |
@@ -45,7 +44,7 @@ export class TagModel extends Model<TagModel> { | |||
45 | static findOrCreateTags (tags: string[], transaction: Transaction): Promise<MTag[]> { | 44 | static findOrCreateTags (tags: string[], transaction: Transaction): Promise<MTag[]> { |
46 | if (tags === null) return Promise.resolve([]) | 45 | if (tags === null) return Promise.resolve([]) |
47 | 46 | ||
48 | const tasks: Bluebird<MTag>[] = [] | 47 | const tasks: Promise<MTag>[] = [] |
49 | tags.forEach(tag => { | 48 | tags.forEach(tag => { |
50 | const query = { | 49 | const query = { |
51 | where: { | 50 | where: { |
@@ -66,7 +65,7 @@ export class TagModel extends Model<TagModel> { | |||
66 | } | 65 | } |
67 | 66 | ||
68 | // threshold corresponds to how many video the field should have to be returned | 67 | // threshold corresponds to how many video the field should have to be returned |
69 | static getRandomSamples (threshold: number, count: number): Bluebird<string[]> { | 68 | static getRandomSamples (threshold: number, count: number): Promise<string[]> { |
70 | const query = 'SELECT tag.name FROM tag ' + | 69 | const query = 'SELECT tag.name FROM tag ' + |
71 | 'INNER JOIN "videoTag" ON "videoTag"."tagId" = tag.id ' + | 70 | 'INNER JOIN "videoTag" ON "videoTag"."tagId" = tag.id ' + |
72 | 'INNER JOIN video ON video.id = "videoTag"."videoId" ' + | 71 | 'INNER JOIN video ON video.id = "videoTag"."videoId" ' + |
diff --git a/server/models/video/thumbnail.ts b/server/models/video/thumbnail.ts index 20c1e5858..6878a3155 100644 --- a/server/models/video/thumbnail.ts +++ b/server/models/video/thumbnail.ts | |||
@@ -34,7 +34,7 @@ import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub' | |||
34 | } | 34 | } |
35 | ] | 35 | ] |
36 | }) | 36 | }) |
37 | export class ThumbnailModel extends Model<ThumbnailModel> { | 37 | export class ThumbnailModel extends Model { |
38 | 38 | ||
39 | @AllowNull(false) | 39 | @AllowNull(false) |
40 | @Column | 40 | @Column |
diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts index 36d2a30fa..aa18896da 100644 --- a/server/models/video/video-blacklist.ts +++ b/server/models/video/video-blacklist.ts | |||
@@ -1,14 +1,13 @@ | |||
1 | import { FindOptions } from 'sequelize' | ||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { getBlacklistSort, SortType, throwIfNotValid, searchAttribute } from '../utils' | 3 | import { MVideoBlacklist, MVideoBlacklistFormattable } from '@server/types/models' |
3 | import { VideoModel } from './video' | ||
4 | import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel' | ||
5 | import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist' | ||
6 | import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos' | 4 | import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos' |
5 | import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist' | ||
7 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 6 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
8 | import { FindOptions } from 'sequelize' | 7 | import { getBlacklistSort, searchAttribute, SortType, throwIfNotValid } from '../utils' |
9 | import { ThumbnailModel } from './thumbnail' | 8 | import { ThumbnailModel } from './thumbnail' |
10 | import * as Bluebird from 'bluebird' | 9 | import { VideoModel } from './video' |
11 | import { MVideoBlacklist, MVideoBlacklistFormattable } from '@server/types/models' | 10 | import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel' |
12 | 11 | ||
13 | @Table({ | 12 | @Table({ |
14 | tableName: 'videoBlacklist', | 13 | tableName: 'videoBlacklist', |
@@ -19,7 +18,7 @@ import { MVideoBlacklist, MVideoBlacklistFormattable } from '@server/types/model | |||
19 | } | 18 | } |
20 | ] | 19 | ] |
21 | }) | 20 | }) |
22 | export class VideoBlacklistModel extends Model<VideoBlacklistModel> { | 21 | export class VideoBlacklistModel extends Model { |
23 | 22 | ||
24 | @AllowNull(true) | 23 | @AllowNull(true) |
25 | @Is('VideoBlacklistReason', value => throwIfNotValid(value, isVideoBlacklistReasonValid, 'reason', true)) | 24 | @Is('VideoBlacklistReason', value => throwIfNotValid(value, isVideoBlacklistReasonValid, 'reason', true)) |
@@ -109,7 +108,7 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> { | |||
109 | }) | 108 | }) |
110 | } | 109 | } |
111 | 110 | ||
112 | static loadByVideoId (id: number): Bluebird<MVideoBlacklist> { | 111 | static loadByVideoId (id: number): Promise<MVideoBlacklist> { |
113 | const query = { | 112 | const query = { |
114 | where: { | 113 | where: { |
115 | videoId: id | 114 | videoId: id |
diff --git a/server/models/video/video-caption.ts b/server/models/video/video-caption.ts index b68a6e99f..e8e883dd0 100644 --- a/server/models/video/video-caption.ts +++ b/server/models/video/video-caption.ts | |||
@@ -1,3 +1,5 @@ | |||
1 | import { remove } from 'fs-extra' | ||
2 | import { join } from 'path' | ||
1 | import { OrderItem, Transaction } from 'sequelize' | 3 | import { OrderItem, Transaction } from 'sequelize' |
2 | import { | 4 | import { |
3 | AllowNull, | 5 | AllowNull, |
@@ -13,18 +15,15 @@ import { | |||
13 | Table, | 15 | Table, |
14 | UpdatedAt | 16 | UpdatedAt |
15 | } from 'sequelize-typescript' | 17 | } from 'sequelize-typescript' |
16 | import { buildWhereIdOrUUID, throwIfNotValid } from '../utils' | 18 | import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub' |
17 | import { VideoModel } from './video' | 19 | import { MVideoAccountLight, MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/types/models' |
18 | import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions' | ||
19 | import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model' | 20 | import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model' |
20 | import { CONSTRAINTS_FIELDS, LAZY_STATIC_PATHS, VIDEO_LANGUAGES, WEBSERVER } from '../../initializers/constants' | 21 | import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions' |
21 | import { join } from 'path' | ||
22 | import { logger } from '../../helpers/logger' | 22 | import { logger } from '../../helpers/logger' |
23 | import { remove } from 'fs-extra' | ||
24 | import { CONFIG } from '../../initializers/config' | 23 | import { CONFIG } from '../../initializers/config' |
25 | import * as Bluebird from 'bluebird' | 24 | import { CONSTRAINTS_FIELDS, LAZY_STATIC_PATHS, VIDEO_LANGUAGES, WEBSERVER } from '../../initializers/constants' |
26 | import { MVideoAccountLight, MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/types/models' | 25 | import { buildWhereIdOrUUID, throwIfNotValid } from '../utils' |
27 | import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub' | 26 | import { VideoModel } from './video' |
28 | 27 | ||
29 | export enum ScopeNames { | 28 | export enum ScopeNames { |
30 | WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE' | 29 | WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE' |
@@ -54,7 +53,7 @@ export enum ScopeNames { | |||
54 | } | 53 | } |
55 | ] | 54 | ] |
56 | }) | 55 | }) |
57 | export class VideoCaptionModel extends Model<VideoCaptionModel> { | 56 | export class VideoCaptionModel extends Model { |
58 | @CreatedAt | 57 | @CreatedAt |
59 | createdAt: Date | 58 | createdAt: Date |
60 | 59 | ||
@@ -101,7 +100,7 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> { | |||
101 | return undefined | 100 | return undefined |
102 | } | 101 | } |
103 | 102 | ||
104 | static loadByVideoIdAndLanguage (videoId: string | number, language: string): Bluebird<MVideoCaptionVideo> { | 103 | static loadByVideoIdAndLanguage (videoId: string | number, language: string): Promise<MVideoCaptionVideo> { |
105 | const videoInclude = { | 104 | const videoInclude = { |
106 | model: VideoModel.unscoped(), | 105 | model: VideoModel.unscoped(), |
107 | attributes: [ 'id', 'remote', 'uuid' ], | 106 | attributes: [ 'id', 'remote', 'uuid' ], |
@@ -131,7 +130,7 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> { | |||
131 | .then(([ caption ]) => caption) | 130 | .then(([ caption ]) => caption) |
132 | } | 131 | } |
133 | 132 | ||
134 | static listVideoCaptions (videoId: number): Bluebird<MVideoCaptionVideo[]> { | 133 | static listVideoCaptions (videoId: number): Promise<MVideoCaptionVideo[]> { |
135 | const query = { | 134 | const query = { |
136 | order: [ [ 'language', 'ASC' ] ] as OrderItem[], | 135 | order: [ [ 'language', 'ASC' ] ] as OrderItem[], |
137 | where: { | 136 | where: { |
diff --git a/server/models/video/video-change-ownership.ts b/server/models/video/video-change-ownership.ts index ac0ab7e8b..298e8bfe2 100644 --- a/server/models/video/video-change-ownership.ts +++ b/server/models/video/video-change-ownership.ts | |||
@@ -1,10 +1,9 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { AccountModel } from '../account/account' | 2 | import { MVideoChangeOwnershipFormattable, MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership' |
3 | import { ScopeNames as VideoScopeNames, VideoModel } from './video' | ||
4 | import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos' | 3 | import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos' |
4 | import { AccountModel } from '../account/account' | ||
5 | import { getSort } from '../utils' | 5 | import { getSort } from '../utils' |
6 | import { MVideoChangeOwnershipFormattable, MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership' | 6 | import { ScopeNames as VideoScopeNames, VideoModel } from './video' |
7 | import * as Bluebird from 'bluebird' | ||
8 | 7 | ||
9 | enum ScopeNames { | 8 | enum ScopeNames { |
10 | WITH_ACCOUNTS = 'WITH_ACCOUNTS', | 9 | WITH_ACCOUNTS = 'WITH_ACCOUNTS', |
@@ -54,7 +53,7 @@ enum ScopeNames { | |||
54 | ] | 53 | ] |
55 | } | 54 | } |
56 | })) | 55 | })) |
57 | export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel> { | 56 | export class VideoChangeOwnershipModel extends Model { |
58 | @CreatedAt | 57 | @CreatedAt |
59 | createdAt: Date | 58 | createdAt: Date |
60 | 59 | ||
@@ -119,7 +118,7 @@ export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel> | |||
119 | ]).then(([ count, rows ]) => ({ total: count, data: rows })) | 118 | ]).then(([ count, rows ]) => ({ total: count, data: rows })) |
120 | } | 119 | } |
121 | 120 | ||
122 | static load (id: number): Bluebird<MVideoChangeOwnershipFull> { | 121 | static load (id: number): Promise<MVideoChangeOwnershipFull> { |
123 | return VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ]) | 122 | return VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ]) |
124 | .findByPk(id) | 123 | .findByPk(id) |
125 | } | 124 | } |
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 0c8aef18f..178878c55 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import { FindOptions, Includeable, literal, Op, ScopeOptions } from 'sequelize' |
2 | import { FindOptions, literal, Op, ScopeOptions } from 'sequelize' | ||
3 | import { | 2 | import { |
4 | AllowNull, | 3 | AllowNull, |
5 | BeforeDestroy, | 4 | BeforeDestroy, |
@@ -119,30 +118,31 @@ export type SummaryOptions = { | |||
119 | } | 118 | } |
120 | }, | 119 | }, |
121 | [ScopeNames.SUMMARY]: (options: SummaryOptions = {}) => { | 120 | [ScopeNames.SUMMARY]: (options: SummaryOptions = {}) => { |
121 | const include: Includeable[] = [ | ||
122 | { | ||
123 | attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ], | ||
124 | model: ActorModel.unscoped(), | ||
125 | required: options.actorRequired ?? true, | ||
126 | include: [ | ||
127 | { | ||
128 | attributes: [ 'host' ], | ||
129 | model: ServerModel.unscoped(), | ||
130 | required: false | ||
131 | }, | ||
132 | { | ||
133 | model: AvatarModel.unscoped(), | ||
134 | required: false | ||
135 | } | ||
136 | ] | ||
137 | } | ||
138 | ] | ||
139 | |||
122 | const base: FindOptions = { | 140 | const base: FindOptions = { |
123 | attributes: [ 'id', 'name', 'description', 'actorId' ], | 141 | attributes: [ 'id', 'name', 'description', 'actorId' ] |
124 | include: [ | ||
125 | { | ||
126 | attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ], | ||
127 | model: ActorModel.unscoped(), | ||
128 | required: options.actorRequired ?? true, | ||
129 | include: [ | ||
130 | { | ||
131 | attributes: [ 'host' ], | ||
132 | model: ServerModel.unscoped(), | ||
133 | required: false | ||
134 | }, | ||
135 | { | ||
136 | model: AvatarModel.unscoped(), | ||
137 | required: false | ||
138 | } | ||
139 | ] | ||
140 | } | ||
141 | ] | ||
142 | } | 142 | } |
143 | 143 | ||
144 | if (options.withAccount === true) { | 144 | if (options.withAccount === true) { |
145 | base.include.push({ | 145 | include.push({ |
146 | model: AccountModel.scope({ | 146 | model: AccountModel.scope({ |
147 | method: [ AccountModelScopeNames.SUMMARY, { withAccountBlockerIds: options.withAccountBlockerIds } as AccountSummaryOptions ] | 147 | method: [ AccountModelScopeNames.SUMMARY, { withAccountBlockerIds: options.withAccountBlockerIds } as AccountSummaryOptions ] |
148 | }), | 148 | }), |
@@ -150,6 +150,8 @@ export type SummaryOptions = { | |||
150 | }) | 150 | }) |
151 | } | 151 | } |
152 | 152 | ||
153 | base.include = include | ||
154 | |||
153 | return base | 155 | return base |
154 | }, | 156 | }, |
155 | [ScopeNames.WITH_ACCOUNT]: { | 157 | [ScopeNames.WITH_ACCOUNT]: { |
@@ -221,7 +223,7 @@ export type SummaryOptions = { | |||
221 | } | 223 | } |
222 | ] | 224 | ] |
223 | }) | 225 | }) |
224 | export class VideoChannelModel extends Model<VideoChannelModel> { | 226 | export class VideoChannelModel extends Model { |
225 | 227 | ||
226 | @AllowNull(false) | 228 | @AllowNull(false) |
227 | @Is('VideoChannelName', value => throwIfNotValid(value, isVideoChannelNameValid, 'name')) | 229 | @Is('VideoChannelName', value => throwIfNotValid(value, isVideoChannelNameValid, 'name')) |
@@ -328,18 +330,17 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
328 | order: getSort(parameters.sort) | 330 | order: getSort(parameters.sort) |
329 | } | 331 | } |
330 | 332 | ||
331 | const scopes = { | ||
332 | method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ] | ||
333 | } | ||
334 | return VideoChannelModel | 333 | return VideoChannelModel |
335 | .scope(scopes) | 334 | .scope({ |
335 | method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ] | ||
336 | }) | ||
336 | .findAndCountAll(query) | 337 | .findAndCountAll(query) |
337 | .then(({ rows, count }) => { | 338 | .then(({ rows, count }) => { |
338 | return { total: count, data: rows } | 339 | return { total: count, data: rows } |
339 | }) | 340 | }) |
340 | } | 341 | } |
341 | 342 | ||
342 | static listLocalsForSitemap (sort: string): Bluebird<MChannelActor[]> { | 343 | static listLocalsForSitemap (sort: string): Promise<MChannelActor[]> { |
343 | const query = { | 344 | const query = { |
344 | attributes: [ ], | 345 | attributes: [ ], |
345 | offset: 0, | 346 | offset: 0, |
@@ -391,11 +392,10 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
391 | } | 392 | } |
392 | } | 393 | } |
393 | 394 | ||
394 | const scopes = { | ||
395 | method: [ ScopeNames.FOR_API, { actorId: options.actorId } as AvailableForListOptions ] | ||
396 | } | ||
397 | return VideoChannelModel | 395 | return VideoChannelModel |
398 | .scope(scopes) | 396 | .scope({ |
397 | method: [ ScopeNames.FOR_API, { actorId: options.actorId } as AvailableForListOptions ] | ||
398 | }) | ||
399 | .findAndCountAll(query) | 399 | .findAndCountAll(query) |
400 | .then(({ rows, count }) => { | 400 | .then(({ rows, count }) => { |
401 | return { total: count, data: rows } | 401 | return { total: count, data: rows } |
@@ -457,13 +457,13 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
457 | }) | 457 | }) |
458 | } | 458 | } |
459 | 459 | ||
460 | static loadByIdAndPopulateAccount (id: number): Bluebird<MChannelAccountDefault> { | 460 | static loadByIdAndPopulateAccount (id: number): Promise<MChannelAccountDefault> { |
461 | return VideoChannelModel.unscoped() | 461 | return VideoChannelModel.unscoped() |
462 | .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) | 462 | .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) |
463 | .findByPk(id) | 463 | .findByPk(id) |
464 | } | 464 | } |
465 | 465 | ||
466 | static loadByIdAndAccount (id: number, accountId: number): Bluebird<MChannelAccountDefault> { | 466 | static loadByIdAndAccount (id: number, accountId: number): Promise<MChannelAccountDefault> { |
467 | const query = { | 467 | const query = { |
468 | where: { | 468 | where: { |
469 | id, | 469 | id, |
@@ -476,13 +476,13 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
476 | .findOne(query) | 476 | .findOne(query) |
477 | } | 477 | } |
478 | 478 | ||
479 | static loadAndPopulateAccount (id: number): Bluebird<MChannelAccountDefault> { | 479 | static loadAndPopulateAccount (id: number): Promise<MChannelAccountDefault> { |
480 | return VideoChannelModel.unscoped() | 480 | return VideoChannelModel.unscoped() |
481 | .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) | 481 | .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) |
482 | .findByPk(id) | 482 | .findByPk(id) |
483 | } | 483 | } |
484 | 484 | ||
485 | static loadByUrlAndPopulateAccount (url: string): Bluebird<MChannelAccountDefault> { | 485 | static loadByUrlAndPopulateAccount (url: string): Promise<MChannelAccountDefault> { |
486 | const query = { | 486 | const query = { |
487 | include: [ | 487 | include: [ |
488 | { | 488 | { |
@@ -508,7 +508,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
508 | return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host) | 508 | return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host) |
509 | } | 509 | } |
510 | 510 | ||
511 | static loadLocalByNameAndPopulateAccount (name: string): Bluebird<MChannelAccountDefault> { | 511 | static loadLocalByNameAndPopulateAccount (name: string): Promise<MChannelAccountDefault> { |
512 | const query = { | 512 | const query = { |
513 | include: [ | 513 | include: [ |
514 | { | 514 | { |
@@ -527,7 +527,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
527 | .findOne(query) | 527 | .findOne(query) |
528 | } | 528 | } |
529 | 529 | ||
530 | static loadByNameAndHostAndPopulateAccount (name: string, host: string): Bluebird<MChannelAccountDefault> { | 530 | static loadByNameAndHostAndPopulateAccount (name: string, host: string): Promise<MChannelAccountDefault> { |
531 | const query = { | 531 | const query = { |
532 | include: [ | 532 | include: [ |
533 | { | 533 | { |
@@ -552,7 +552,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
552 | .findOne(query) | 552 | .findOne(query) |
553 | } | 553 | } |
554 | 554 | ||
555 | static loadAndPopulateAccountAndVideos (id: number): Bluebird<MChannelActorAccountDefaultVideos> { | 555 | static loadAndPopulateAccountAndVideos (id: number): Promise<MChannelActorAccountDefaultVideos> { |
556 | const options = { | 556 | const options = { |
557 | include: [ | 557 | include: [ |
558 | VideoModel | 558 | VideoModel |
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index ed4a345eb..8d1c38826 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { uniq } from 'lodash' | 1 | import { uniq } from 'lodash' |
3 | import { FindAndCountOptions, FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' | 2 | import { FindAndCountOptions, FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' |
4 | import { | 3 | import { |
@@ -174,7 +173,7 @@ export enum ScopeNames { | |||
174 | } | 173 | } |
175 | ] | 174 | ] |
176 | }) | 175 | }) |
177 | export class VideoCommentModel extends Model<VideoCommentModel> { | 176 | export class VideoCommentModel extends Model { |
178 | @CreatedAt | 177 | @CreatedAt |
179 | createdAt: Date | 178 | createdAt: Date |
180 | 179 | ||
@@ -255,7 +254,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
255 | }) | 254 | }) |
256 | CommentAbuses: VideoCommentAbuseModel[] | 255 | CommentAbuses: VideoCommentAbuseModel[] |
257 | 256 | ||
258 | static loadById (id: number, t?: Transaction): Bluebird<MComment> { | 257 | static loadById (id: number, t?: Transaction): Promise<MComment> { |
259 | const query: FindOptions = { | 258 | const query: FindOptions = { |
260 | where: { | 259 | where: { |
261 | id | 260 | id |
@@ -267,7 +266,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
267 | return VideoCommentModel.findOne(query) | 266 | return VideoCommentModel.findOne(query) |
268 | } | 267 | } |
269 | 268 | ||
270 | static loadByIdAndPopulateVideoAndAccountAndReply (id: number, t?: Transaction): Bluebird<MCommentOwnerVideoReply> { | 269 | static loadByIdAndPopulateVideoAndAccountAndReply (id: number, t?: Transaction): Promise<MCommentOwnerVideoReply> { |
271 | const query: FindOptions = { | 270 | const query: FindOptions = { |
272 | where: { | 271 | where: { |
273 | id | 272 | id |
@@ -281,7 +280,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
281 | .findOne(query) | 280 | .findOne(query) |
282 | } | 281 | } |
283 | 282 | ||
284 | static loadByUrlAndPopulateAccountAndVideo (url: string, t?: Transaction): Bluebird<MCommentOwnerVideo> { | 283 | static loadByUrlAndPopulateAccountAndVideo (url: string, t?: Transaction): Promise<MCommentOwnerVideo> { |
285 | const query: FindOptions = { | 284 | const query: FindOptions = { |
286 | where: { | 285 | where: { |
287 | url | 286 | url |
@@ -293,7 +292,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
293 | return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEO ]).findOne(query) | 292 | return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEO ]).findOne(query) |
294 | } | 293 | } |
295 | 294 | ||
296 | static loadByUrlAndPopulateReplyAndVideoUrlAndAccount (url: string, t?: Transaction): Bluebird<MCommentOwnerReplyVideoLight> { | 295 | static loadByUrlAndPopulateReplyAndVideoUrlAndAccount (url: string, t?: Transaction): Promise<MCommentOwnerReplyVideoLight> { |
297 | const query: FindOptions = { | 296 | const query: FindOptions = { |
298 | where: { | 297 | where: { |
299 | url | 298 | url |
@@ -501,7 +500,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
501 | }) | 500 | }) |
502 | } | 501 | } |
503 | 502 | ||
504 | static listThreadParentComments (comment: MCommentId, t: Transaction, order: 'ASC' | 'DESC' = 'ASC'): Bluebird<MCommentOwner[]> { | 503 | static listThreadParentComments (comment: MCommentId, t: Transaction, order: 'ASC' | 'DESC' = 'ASC'): Promise<MCommentOwner[]> { |
505 | const query = { | 504 | const query = { |
506 | order: [ [ 'createdAt', order ] ] as Order, | 505 | order: [ [ 'createdAt', order ] ] as Order, |
507 | where: { | 506 | where: { |
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index d48c9f5d4..48b337c68 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts | |||
@@ -101,7 +101,7 @@ export enum ScopeNames { | |||
101 | } | 101 | } |
102 | ] | 102 | ] |
103 | }) | 103 | }) |
104 | export class VideoFileModel extends Model<VideoFileModel> { | 104 | export class VideoFileModel extends Model { |
105 | @CreatedAt | 105 | @CreatedAt |
106 | createdAt: Date | 106 | createdAt: Date |
107 | 107 | ||
diff --git a/server/models/video/video-import.ts b/server/models/video/video-import.ts index ea1e085af..f3ed651b2 100644 --- a/server/models/video/video-import.ts +++ b/server/models/video/video-import.ts | |||
@@ -13,15 +13,14 @@ import { | |||
13 | Table, | 13 | Table, |
14 | UpdatedAt | 14 | UpdatedAt |
15 | } from 'sequelize-typescript' | 15 | } from 'sequelize-typescript' |
16 | import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers/constants' | 16 | import { MVideoImportDefault, MVideoImportFormattable } from '@server/types/models/video/video-import' |
17 | import { getSort, throwIfNotValid } from '../utils' | ||
18 | import { ScopeNames as VideoModelScopeNames, VideoModel } from './video' | ||
19 | import { isVideoImportStateValid, isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' | ||
20 | import { VideoImport, VideoImportState } from '../../../shared' | 17 | import { VideoImport, VideoImportState } from '../../../shared' |
18 | import { isVideoImportStateValid, isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' | ||
21 | import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos' | 19 | import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos' |
20 | import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers/constants' | ||
22 | import { UserModel } from '../account/user' | 21 | import { UserModel } from '../account/user' |
23 | import * as Bluebird from 'bluebird' | 22 | import { getSort, throwIfNotValid } from '../utils' |
24 | import { MVideoImportDefault, MVideoImportFormattable } from '@server/types/models/video/video-import' | 23 | import { ScopeNames as VideoModelScopeNames, VideoModel } from './video' |
25 | 24 | ||
26 | @DefaultScope(() => ({ | 25 | @DefaultScope(() => ({ |
27 | include: [ | 26 | include: [ |
@@ -52,7 +51,7 @@ import { MVideoImportDefault, MVideoImportFormattable } from '@server/types/mode | |||
52 | } | 51 | } |
53 | ] | 52 | ] |
54 | }) | 53 | }) |
55 | export class VideoImportModel extends Model<VideoImportModel> { | 54 | export class VideoImportModel extends Model { |
56 | @CreatedAt | 55 | @CreatedAt |
57 | createdAt: Date | 56 | createdAt: Date |
58 | 57 | ||
@@ -120,7 +119,7 @@ export class VideoImportModel extends Model<VideoImportModel> { | |||
120 | return undefined | 119 | return undefined |
121 | } | 120 | } |
122 | 121 | ||
123 | static loadAndPopulateVideo (id: number): Bluebird<MVideoImportDefault> { | 122 | static loadAndPopulateVideo (id: number): Promise<MVideoImportDefault> { |
124 | return VideoImportModel.findByPk(id) | 123 | return VideoImportModel.findByPk(id) |
125 | } | 124 | } |
126 | 125 | ||
diff --git a/server/models/video/video-live.ts b/server/models/video/video-live.ts index 875ba9b31..cb4a9b896 100644 --- a/server/models/video/video-live.ts +++ b/server/models/video/video-live.ts | |||
@@ -28,7 +28,7 @@ import { VideoBlacklistModel } from './video-blacklist' | |||
28 | } | 28 | } |
29 | ] | 29 | ] |
30 | }) | 30 | }) |
31 | export class VideoLiveModel extends Model<VideoLiveModel> { | 31 | export class VideoLiveModel extends Model { |
32 | 32 | ||
33 | @AllowNull(true) | 33 | @AllowNull(true) |
34 | @Column(DataType.STRING) | 34 | @Column(DataType.STRING) |
diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index d357766e9..d2d7e2740 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import { AggregateOptions, Op, ScopeOptions, Sequelize, Transaction } from 'sequelize' | ||
1 | import { | 2 | import { |
2 | AllowNull, | 3 | AllowNull, |
3 | BelongsTo, | 4 | BelongsTo, |
@@ -13,18 +14,8 @@ import { | |||
13 | Table, | 14 | Table, |
14 | UpdatedAt | 15 | UpdatedAt |
15 | } from 'sequelize-typescript' | 16 | } from 'sequelize-typescript' |
16 | import { ForAPIOptions, ScopeNames as VideoScopeNames, VideoModel } from './video' | ||
17 | import { VideoPlaylistModel } from './video-playlist' | ||
18 | import { getSort, throwIfNotValid } from '../utils' | ||
19 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
20 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | ||
21 | import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object' | ||
22 | import validator from 'validator' | 17 | import validator from 'validator' |
23 | import { AggregateOptions, Op, ScopeOptions, Sequelize, Transaction } from 'sequelize' | 18 | import { MUserAccountId } from '@server/types/models' |
24 | import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model' | ||
25 | import { AccountModel } from '../account/account' | ||
26 | import { VideoPrivacy } from '../../../shared/models/videos' | ||
27 | import * as Bluebird from 'bluebird' | ||
28 | import { | 19 | import { |
29 | MVideoPlaylistElement, | 20 | MVideoPlaylistElement, |
30 | MVideoPlaylistElementAP, | 21 | MVideoPlaylistElementAP, |
@@ -32,7 +23,15 @@ import { | |||
32 | MVideoPlaylistElementVideoUrlPlaylistPrivacy, | 23 | MVideoPlaylistElementVideoUrlPlaylistPrivacy, |
33 | MVideoPlaylistVideoThumbnail | 24 | MVideoPlaylistVideoThumbnail |
34 | } from '@server/types/models/video/video-playlist-element' | 25 | } from '@server/types/models/video/video-playlist-element' |
35 | import { MUserAccountId } from '@server/types/models' | 26 | import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object' |
27 | import { VideoPrivacy } from '../../../shared/models/videos' | ||
28 | import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model' | ||
29 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
30 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | ||
31 | import { AccountModel } from '../account/account' | ||
32 | import { getSort, throwIfNotValid } from '../utils' | ||
33 | import { ForAPIOptions, ScopeNames as VideoScopeNames, VideoModel } from './video' | ||
34 | import { VideoPlaylistModel } from './video-playlist' | ||
36 | 35 | ||
37 | @Table({ | 36 | @Table({ |
38 | tableName: 'videoPlaylistElement', | 37 | tableName: 'videoPlaylistElement', |
@@ -49,7 +48,7 @@ import { MUserAccountId } from '@server/types/models' | |||
49 | } | 48 | } |
50 | ] | 49 | ] |
51 | }) | 50 | }) |
52 | export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel> { | 51 | export class VideoPlaylistElementModel extends Model { |
53 | @CreatedAt | 52 | @CreatedAt |
54 | createdAt: Date | 53 | createdAt: Date |
55 | 54 | ||
@@ -166,7 +165,7 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel> | |||
166 | ]).then(([ total, data ]) => ({ total, data })) | 165 | ]).then(([ total, data ]) => ({ total, data })) |
167 | } | 166 | } |
168 | 167 | ||
169 | static loadByPlaylistAndVideo (videoPlaylistId: number, videoId: number): Bluebird<MVideoPlaylistElement> { | 168 | static loadByPlaylistAndVideo (videoPlaylistId: number, videoId: number): Promise<MVideoPlaylistElement> { |
170 | const query = { | 169 | const query = { |
171 | where: { | 170 | where: { |
172 | videoPlaylistId, | 171 | videoPlaylistId, |
@@ -177,14 +176,14 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel> | |||
177 | return VideoPlaylistElementModel.findOne(query) | 176 | return VideoPlaylistElementModel.findOne(query) |
178 | } | 177 | } |
179 | 178 | ||
180 | static loadById (playlistElementId: number | string): Bluebird<MVideoPlaylistElement> { | 179 | static loadById (playlistElementId: number | string): Promise<MVideoPlaylistElement> { |
181 | return VideoPlaylistElementModel.findByPk(playlistElementId) | 180 | return VideoPlaylistElementModel.findByPk(playlistElementId) |
182 | } | 181 | } |
183 | 182 | ||
184 | static loadByPlaylistAndElementIdForAP ( | 183 | static loadByPlaylistAndElementIdForAP ( |
185 | playlistId: number | string, | 184 | playlistId: number | string, |
186 | playlistElementId: number | 185 | playlistElementId: number |
187 | ): Bluebird<MVideoPlaylistElementVideoUrlPlaylistPrivacy> { | 186 | ): Promise<MVideoPlaylistElementVideoUrlPlaylistPrivacy> { |
188 | const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } | 187 | const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } |
189 | 188 | ||
190 | const query = { | 189 | const query = { |
@@ -226,7 +225,7 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel> | |||
226 | }) | 225 | }) |
227 | } | 226 | } |
228 | 227 | ||
229 | static loadFirstElementWithVideoThumbnail (videoPlaylistId: number): Bluebird<MVideoPlaylistVideoThumbnail> { | 228 | static loadFirstElementWithVideoThumbnail (videoPlaylistId: number): Promise<MVideoPlaylistVideoThumbnail> { |
230 | const query = { | 229 | const query = { |
231 | order: getSort('position'), | 230 | order: getSort('position'), |
232 | where: { | 231 | where: { |
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 9f9e0b069..93ecf8cea 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { join } from 'path' | 1 | import { join } from 'path' |
3 | import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } from 'sequelize' | 2 | import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } from 'sequelize' |
4 | import { | 3 | import { |
@@ -125,7 +124,6 @@ type AvailableForListOptions = { | |||
125 | ] | 124 | ] |
126 | }, | 125 | }, |
127 | [ScopeNames.AVAILABLE_FOR_LIST]: (options: AvailableForListOptions) => { | 126 | [ScopeNames.AVAILABLE_FOR_LIST]: (options: AvailableForListOptions) => { |
128 | |||
129 | let whereActor: WhereOptions = {} | 127 | let whereActor: WhereOptions = {} |
130 | 128 | ||
131 | const whereAnd: WhereOptions[] = [] | 129 | const whereAnd: WhereOptions[] = [] |
@@ -182,15 +180,13 @@ type AvailableForListOptions = { | |||
182 | [Op.and]: whereAnd | 180 | [Op.and]: whereAnd |
183 | } | 181 | } |
184 | 182 | ||
185 | const accountScope = { | ||
186 | method: [ AccountScopeNames.SUMMARY, { whereActor } as SummaryOptions ] | ||
187 | } | ||
188 | |||
189 | return { | 183 | return { |
190 | where, | 184 | where, |
191 | include: [ | 185 | include: [ |
192 | { | 186 | { |
193 | model: AccountModel.scope(accountScope), | 187 | model: AccountModel.scope({ |
188 | method: [ AccountScopeNames.SUMMARY, { whereActor } as SummaryOptions ] | ||
189 | }), | ||
194 | required: true | 190 | required: true |
195 | }, | 191 | }, |
196 | { | 192 | { |
@@ -217,7 +213,7 @@ type AvailableForListOptions = { | |||
217 | } | 213 | } |
218 | ] | 214 | ] |
219 | }) | 215 | }) |
220 | export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | 216 | export class VideoPlaylistModel extends Model { |
221 | @CreatedAt | 217 | @CreatedAt |
222 | createdAt: Date | 218 | createdAt: Date |
223 | 219 | ||
@@ -367,7 +363,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
367 | }) | 363 | }) |
368 | } | 364 | } |
369 | 365 | ||
370 | static listPlaylistIdsOf (accountId: number, videoIds: number[]): Bluebird<MVideoPlaylistIdWithElements[]> { | 366 | static listPlaylistIdsOf (accountId: number, videoIds: number[]): Promise<MVideoPlaylistIdWithElements[]> { |
371 | const query = { | 367 | const query = { |
372 | attributes: [ 'id' ], | 368 | attributes: [ 'id' ], |
373 | where: { | 369 | where: { |
@@ -392,7 +388,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
392 | 388 | ||
393 | static doesPlaylistExist (url: string) { | 389 | static doesPlaylistExist (url: string) { |
394 | const query = { | 390 | const query = { |
395 | attributes: [], | 391 | attributes: [ 'id' ], |
396 | where: { | 392 | where: { |
397 | url | 393 | url |
398 | } | 394 | } |
@@ -403,7 +399,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
403 | .then(e => !!e) | 399 | .then(e => !!e) |
404 | } | 400 | } |
405 | 401 | ||
406 | static loadWithAccountAndChannelSummary (id: number | string, transaction: Transaction): Bluebird<MVideoPlaylistFullSummary> { | 402 | static loadWithAccountAndChannelSummary (id: number | string, transaction: Transaction): Promise<MVideoPlaylistFullSummary> { |
407 | const where = buildWhereIdOrUUID(id) | 403 | const where = buildWhereIdOrUUID(id) |
408 | 404 | ||
409 | const query = { | 405 | const query = { |
@@ -416,7 +412,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
416 | .findOne(query) | 412 | .findOne(query) |
417 | } | 413 | } |
418 | 414 | ||
419 | static loadWithAccountAndChannel (id: number | string, transaction: Transaction): Bluebird<MVideoPlaylistFull> { | 415 | static loadWithAccountAndChannel (id: number | string, transaction: Transaction): Promise<MVideoPlaylistFull> { |
420 | const where = buildWhereIdOrUUID(id) | 416 | const where = buildWhereIdOrUUID(id) |
421 | 417 | ||
422 | const query = { | 418 | const query = { |
@@ -429,7 +425,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
429 | .findOne(query) | 425 | .findOne(query) |
430 | } | 426 | } |
431 | 427 | ||
432 | static loadByUrlAndPopulateAccount (url: string): Bluebird<MVideoPlaylistAccountThumbnail> { | 428 | static loadByUrlAndPopulateAccount (url: string): Promise<MVideoPlaylistAccountThumbnail> { |
433 | const query = { | 429 | const query = { |
434 | where: { | 430 | where: { |
435 | url | 431 | url |
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index f9ee94589..b7f5f3fa3 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts | |||
@@ -1,13 +1,12 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import { literal, Op, Transaction } from 'sequelize' |
2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 3 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
5 | import { MActorDefault } from '../../types/models' | ||
6 | import { MVideoShareActor, MVideoShareFull } from '../../types/models/video' | ||
5 | import { ActorModel } from '../activitypub/actor' | 7 | import { ActorModel } from '../activitypub/actor' |
6 | import { buildLocalActorIdsIn, throwIfNotValid } from '../utils' | 8 | import { buildLocalActorIdsIn, throwIfNotValid } from '../utils' |
7 | import { VideoModel } from './video' | 9 | import { VideoModel } from './video' |
8 | import { literal, Op, Transaction } from 'sequelize' | ||
9 | import { MVideoShareActor, MVideoShareFull } from '../../types/models/video' | ||
10 | import { MActorDefault } from '../../types/models' | ||
11 | 10 | ||
12 | enum ScopeNames { | 11 | enum ScopeNames { |
13 | FULL = 'FULL', | 12 | FULL = 'FULL', |
@@ -51,7 +50,7 @@ enum ScopeNames { | |||
51 | } | 50 | } |
52 | ] | 51 | ] |
53 | }) | 52 | }) |
54 | export class VideoShareModel extends Model<VideoShareModel> { | 53 | export class VideoShareModel extends Model { |
55 | 54 | ||
56 | @AllowNull(false) | 55 | @AllowNull(false) |
57 | @Is('VideoShareUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) | 56 | @Is('VideoShareUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) |
@@ -88,7 +87,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
88 | }) | 87 | }) |
89 | Video: VideoModel | 88 | Video: VideoModel |
90 | 89 | ||
91 | static load (actorId: number | string, videoId: number | string, t?: Transaction): Bluebird<MVideoShareActor> { | 90 | static load (actorId: number | string, videoId: number | string, t?: Transaction): Promise<MVideoShareActor> { |
92 | return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({ | 91 | return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({ |
93 | where: { | 92 | where: { |
94 | actorId, | 93 | actorId, |
@@ -98,7 +97,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
98 | }) | 97 | }) |
99 | } | 98 | } |
100 | 99 | ||
101 | static loadByUrl (url: string, t: Transaction): Bluebird<MVideoShareFull> { | 100 | static loadByUrl (url: string, t: Transaction): Promise<MVideoShareFull> { |
102 | return VideoShareModel.scope(ScopeNames.FULL).findOne({ | 101 | return VideoShareModel.scope(ScopeNames.FULL).findOne({ |
103 | where: { | 102 | where: { |
104 | url | 103 | url |
@@ -107,7 +106,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
107 | }) | 106 | }) |
108 | } | 107 | } |
109 | 108 | ||
110 | static loadActorsByShare (videoId: number, t: Transaction): Bluebird<MActorDefault[]> { | 109 | static loadActorsByShare (videoId: number, t: Transaction): Promise<MActorDefault[]> { |
111 | const query = { | 110 | const query = { |
112 | where: { | 111 | where: { |
113 | videoId | 112 | videoId |
@@ -125,7 +124,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
125 | .then((res: MVideoShareFull[]) => res.map(r => r.Actor)) | 124 | .then((res: MVideoShareFull[]) => res.map(r => r.Actor)) |
126 | } | 125 | } |
127 | 126 | ||
128 | static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Bluebird<MActorDefault[]> { | 127 | static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Promise<MActorDefault[]> { |
129 | const safeOwnerId = parseInt(actorOwnerId + '', 10) | 128 | const safeOwnerId = parseInt(actorOwnerId + '', 10) |
130 | 129 | ||
131 | // /!\ On actor model | 130 | // /!\ On actor model |
@@ -150,7 +149,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
150 | return ActorModel.findAll(query) | 149 | return ActorModel.findAll(query) |
151 | } | 150 | } |
152 | 151 | ||
153 | static loadActorsByVideoChannel (videoChannelId: number, t: Transaction): Bluebird<MActorDefault[]> { | 152 | static loadActorsByVideoChannel (videoChannelId: number, t: Transaction): Promise<MActorDefault[]> { |
154 | const safeChannelId = parseInt(videoChannelId + '', 10) | 153 | const safeChannelId = parseInt(videoChannelId + '', 10) |
155 | 154 | ||
156 | // /!\ On actor model | 155 | // /!\ On actor model |
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index 73bd89844..148768c21 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts | |||
@@ -40,7 +40,7 @@ import { logger } from '@server/helpers/logger' | |||
40 | } | 40 | } |
41 | ] | 41 | ] |
42 | }) | 42 | }) |
43 | export class VideoStreamingPlaylistModel extends Model<VideoStreamingPlaylistModel> { | 43 | export class VideoStreamingPlaylistModel extends Model { |
44 | @CreatedAt | 44 | @CreatedAt |
45 | createdAt: Date | 45 | createdAt: Date |
46 | 46 | ||
diff --git a/server/models/video/video-tag.ts b/server/models/video/video-tag.ts index ca15e3426..5052b8c4d 100644 --- a/server/models/video/video-tag.ts +++ b/server/models/video/video-tag.ts | |||
@@ -13,7 +13,7 @@ import { VideoModel } from './video' | |||
13 | } | 13 | } |
14 | ] | 14 | ] |
15 | }) | 15 | }) |
16 | export class VideoTagModel extends Model<VideoTagModel> { | 16 | export class VideoTagModel extends Model { |
17 | @CreatedAt | 17 | @CreatedAt |
18 | createdAt: Date | 18 | createdAt: Date |
19 | 19 | ||
diff --git a/server/models/video/video-view.ts b/server/models/video/video-view.ts index 40db5effd..992cf258a 100644 --- a/server/models/video/video-view.ts +++ b/server/models/video/video-view.ts | |||
@@ -14,7 +14,7 @@ import * as Sequelize from 'sequelize' | |||
14 | } | 14 | } |
15 | ] | 15 | ] |
16 | }) | 16 | }) |
17 | export class VideoViewModel extends Model<VideoViewModel> { | 17 | export class VideoViewModel extends Model { |
18 | @CreatedAt | 18 | @CreatedAt |
19 | createdAt: Date | 19 | createdAt: Date |
20 | 20 | ||
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index a43abbc09..d3fed338a 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -2,7 +2,7 @@ import * as Bluebird from 'bluebird' | |||
2 | import { remove } from 'fs-extra' | 2 | import { remove } from 'fs-extra' |
3 | import { maxBy, minBy, pick } from 'lodash' | 3 | import { maxBy, minBy, pick } from 'lodash' |
4 | import { join } from 'path' | 4 | import { join } from 'path' |
5 | import { FindOptions, IncludeOptions, Op, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' | 5 | import { FindOptions, Includeable, IncludeOptions, Op, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' |
6 | import { | 6 | import { |
7 | AllowNull, | 7 | AllowNull, |
8 | BeforeDestroy, | 8 | BeforeDestroy, |
@@ -190,26 +190,26 @@ export type AvailableForListIDsOptions = { | |||
190 | attributes: [ 'id', 'url', 'uuid', 'remote' ] | 190 | attributes: [ 'id', 'url', 'uuid', 'remote' ] |
191 | }, | 191 | }, |
192 | [ScopeNames.FOR_API]: (options: ForAPIOptions) => { | 192 | [ScopeNames.FOR_API]: (options: ForAPIOptions) => { |
193 | const query: FindOptions = { | 193 | const include: Includeable[] = [ |
194 | include: [ | 194 | { |
195 | { | 195 | model: VideoChannelModel.scope({ |
196 | model: VideoChannelModel.scope({ | 196 | method: [ |
197 | method: [ | 197 | VideoChannelScopeNames.SUMMARY, { |
198 | VideoChannelScopeNames.SUMMARY, { | 198 | withAccount: true, |
199 | withAccount: true, | 199 | withAccountBlockerIds: options.withAccountBlockerIds |
200 | withAccountBlockerIds: options.withAccountBlockerIds | 200 | } as SummaryOptions |
201 | } as SummaryOptions | 201 | ] |
202 | ] | 202 | }), |
203 | }), | 203 | required: true |
204 | required: true | 204 | }, |
205 | }, | 205 | { |
206 | { | 206 | attributes: [ 'type', 'filename' ], |
207 | attributes: [ 'type', 'filename' ], | 207 | model: ThumbnailModel, |
208 | model: ThumbnailModel, | 208 | required: false |
209 | required: false | 209 | } |
210 | } | 210 | ] |
211 | ] | 211 | |
212 | } | 212 | const query: FindOptions = {} |
213 | 213 | ||
214 | if (options.ids) { | 214 | if (options.ids) { |
215 | query.where = { | 215 | query.where = { |
@@ -220,14 +220,14 @@ export type AvailableForListIDsOptions = { | |||
220 | } | 220 | } |
221 | 221 | ||
222 | if (options.withFiles === true) { | 222 | if (options.withFiles === true) { |
223 | query.include.push({ | 223 | include.push({ |
224 | model: VideoFileModel, | 224 | model: VideoFileModel, |
225 | required: true | 225 | required: true |
226 | }) | 226 | }) |
227 | } | 227 | } |
228 | 228 | ||
229 | if (options.videoPlaylistId) { | 229 | if (options.videoPlaylistId) { |
230 | query.include.push({ | 230 | include.push({ |
231 | model: VideoPlaylistElementModel.unscoped(), | 231 | model: VideoPlaylistElementModel.unscoped(), |
232 | required: true, | 232 | required: true, |
233 | where: { | 233 | where: { |
@@ -236,6 +236,8 @@ export type AvailableForListIDsOptions = { | |||
236 | }) | 236 | }) |
237 | } | 237 | } |
238 | 238 | ||
239 | query.include = include | ||
240 | |||
239 | return query | 241 | return query |
240 | }, | 242 | }, |
241 | [ScopeNames.WITH_THUMBNAILS]: { | 243 | [ScopeNames.WITH_THUMBNAILS]: { |
@@ -477,7 +479,7 @@ export type AvailableForListIDsOptions = { | |||
477 | } | 479 | } |
478 | ] | 480 | ] |
479 | }) | 481 | }) |
480 | export class VideoModel extends Model<VideoModel> { | 482 | export class VideoModel extends Model { |
481 | 483 | ||
482 | @AllowNull(false) | 484 | @AllowNull(false) |
483 | @Default(DataType.UUIDV4) | 485 | @Default(DataType.UUIDV4) |
@@ -860,7 +862,7 @@ export class VideoModel extends Model<VideoModel> { | |||
860 | return undefined | 862 | return undefined |
861 | } | 863 | } |
862 | 864 | ||
863 | static listLocal (): Bluebird<MVideoWithAllFiles[]> { | 865 | static listLocal (): Promise<MVideoWithAllFiles[]> { |
864 | const query = { | 866 | const query = { |
865 | where: { | 867 | where: { |
866 | remote: false | 868 | remote: false |
@@ -988,7 +990,7 @@ export class VideoModel extends Model<VideoModel> { | |||
988 | }) | 990 | }) |
989 | } | 991 | } |
990 | 992 | ||
991 | static listPublishedLiveIds () { | 993 | static async listPublishedLiveIds () { |
992 | const options = { | 994 | const options = { |
993 | attributes: [ 'id' ], | 995 | attributes: [ 'id' ], |
994 | where: { | 996 | where: { |
@@ -997,8 +999,9 @@ export class VideoModel extends Model<VideoModel> { | |||
997 | } | 999 | } |
998 | } | 1000 | } |
999 | 1001 | ||
1000 | return VideoModel.findAll(options) | 1002 | const result = await VideoModel.findAll(options) |
1001 | .map(v => v.id) | 1003 | |
1004 | return result.map(v => v.id) | ||
1002 | } | 1005 | } |
1003 | 1006 | ||
1004 | static listUserVideosForApi ( | 1007 | static listUserVideosForApi ( |
@@ -1214,7 +1217,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1214 | return VideoModel.count(options) | 1217 | return VideoModel.count(options) |
1215 | } | 1218 | } |
1216 | 1219 | ||
1217 | static load (id: number | string, t?: Transaction): Bluebird<MVideoThumbnail> { | 1220 | static load (id: number | string, t?: Transaction): Promise<MVideoThumbnail> { |
1218 | const where = buildWhereIdOrUUID(id) | 1221 | const where = buildWhereIdOrUUID(id) |
1219 | const options = { | 1222 | const options = { |
1220 | where, | 1223 | where, |
@@ -1224,7 +1227,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1224 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) | 1227 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) |
1225 | } | 1228 | } |
1226 | 1229 | ||
1227 | static loadWithBlacklist (id: number | string, t?: Transaction): Bluebird<MVideoThumbnailBlacklist> { | 1230 | static loadWithBlacklist (id: number | string, t?: Transaction): Promise<MVideoThumbnailBlacklist> { |
1228 | const where = buildWhereIdOrUUID(id) | 1231 | const where = buildWhereIdOrUUID(id) |
1229 | const options = { | 1232 | const options = { |
1230 | where, | 1233 | where, |
@@ -1237,7 +1240,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1237 | ]).findOne(options) | 1240 | ]).findOne(options) |
1238 | } | 1241 | } |
1239 | 1242 | ||
1240 | static loadImmutableAttributes (id: number | string, t?: Transaction): Bluebird<MVideoImmutable> { | 1243 | static loadImmutableAttributes (id: number | string, t?: Transaction): Promise<MVideoImmutable> { |
1241 | const fun = () => { | 1244 | const fun = () => { |
1242 | const query = { | 1245 | const query = { |
1243 | where: buildWhereIdOrUUID(id), | 1246 | where: buildWhereIdOrUUID(id), |
@@ -1255,7 +1258,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1255 | }) | 1258 | }) |
1256 | } | 1259 | } |
1257 | 1260 | ||
1258 | static loadWithRights (id: number | string, t?: Transaction): Bluebird<MVideoWithRights> { | 1261 | static loadWithRights (id: number | string, t?: Transaction): Promise<MVideoWithRights> { |
1259 | const where = buildWhereIdOrUUID(id) | 1262 | const where = buildWhereIdOrUUID(id) |
1260 | const options = { | 1263 | const options = { |
1261 | where, | 1264 | where, |
@@ -1269,7 +1272,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1269 | ]).findOne(options) | 1272 | ]).findOne(options) |
1270 | } | 1273 | } |
1271 | 1274 | ||
1272 | static loadOnlyId (id: number | string, t?: Transaction): Bluebird<MVideoIdThumbnail> { | 1275 | static loadOnlyId (id: number | string, t?: Transaction): Promise<MVideoIdThumbnail> { |
1273 | const where = buildWhereIdOrUUID(id) | 1276 | const where = buildWhereIdOrUUID(id) |
1274 | 1277 | ||
1275 | const options = { | 1278 | const options = { |
@@ -1281,7 +1284,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1281 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) | 1284 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) |
1282 | } | 1285 | } |
1283 | 1286 | ||
1284 | static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean): Bluebird<MVideoWithAllFiles> { | 1287 | static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean): Promise<MVideoWithAllFiles> { |
1285 | const where = buildWhereIdOrUUID(id) | 1288 | const where = buildWhereIdOrUUID(id) |
1286 | 1289 | ||
1287 | const query = { | 1290 | const query = { |
@@ -1297,7 +1300,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1297 | ]).findOne(query) | 1300 | ]).findOne(query) |
1298 | } | 1301 | } |
1299 | 1302 | ||
1300 | static loadByUUID (uuid: string): Bluebird<MVideoThumbnail> { | 1303 | static loadByUUID (uuid: string): Promise<MVideoThumbnail> { |
1301 | const options = { | 1304 | const options = { |
1302 | where: { | 1305 | where: { |
1303 | uuid | 1306 | uuid |
@@ -1307,7 +1310,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1307 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) | 1310 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) |
1308 | } | 1311 | } |
1309 | 1312 | ||
1310 | static loadByUrl (url: string, transaction?: Transaction): Bluebird<MVideoThumbnail> { | 1313 | static loadByUrl (url: string, transaction?: Transaction): Promise<MVideoThumbnail> { |
1311 | const query: FindOptions = { | 1314 | const query: FindOptions = { |
1312 | where: { | 1315 | where: { |
1313 | url | 1316 | url |
@@ -1318,7 +1321,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1318 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) | 1321 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) |
1319 | } | 1322 | } |
1320 | 1323 | ||
1321 | static loadByUrlImmutableAttributes (url: string, transaction?: Transaction): Bluebird<MVideoImmutable> { | 1324 | static loadByUrlImmutableAttributes (url: string, transaction?: Transaction): Promise<MVideoImmutable> { |
1322 | const fun = () => { | 1325 | const fun = () => { |
1323 | const query: FindOptions = { | 1326 | const query: FindOptions = { |
1324 | where: { | 1327 | where: { |
@@ -1338,7 +1341,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1338 | }) | 1341 | }) |
1339 | } | 1342 | } |
1340 | 1343 | ||
1341 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountLightBlacklistAllFiles> { | 1344 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Promise<MVideoAccountLightBlacklistAllFiles> { |
1342 | const query: FindOptions = { | 1345 | const query: FindOptions = { |
1343 | where: { | 1346 | where: { |
1344 | url | 1347 | url |
@@ -1355,7 +1358,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1355 | ]).findOne(query) | 1358 | ]).findOne(query) |
1356 | } | 1359 | } |
1357 | 1360 | ||
1358 | static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number): Bluebird<MVideoFullLight> { | 1361 | static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number): Promise<MVideoFullLight> { |
1359 | const where = buildWhereIdOrUUID(id) | 1362 | const where = buildWhereIdOrUUID(id) |
1360 | 1363 | ||
1361 | const options = { | 1364 | const options = { |
@@ -1388,7 +1391,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1388 | id: number | string | 1391 | id: number | string |
1389 | t?: Transaction | 1392 | t?: Transaction |
1390 | userId?: number | 1393 | userId?: number |
1391 | }): Bluebird<MVideoDetails> { | 1394 | }): Promise<MVideoDetails> { |
1392 | const { id, t, userId } = parameters | 1395 | const { id, t, userId } = parameters |
1393 | const where = buildWhereIdOrUUID(id) | 1396 | const where = buildWhereIdOrUUID(id) |
1394 | 1397 | ||
@@ -1487,7 +1490,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1487 | return VideoModel.update({ support: videoChannel.support }, options) | 1490 | return VideoModel.update({ support: videoChannel.support }, options) |
1488 | } | 1491 | } |
1489 | 1492 | ||
1490 | static getAllIdsFromChannel (videoChannel: MChannelId): Bluebird<number[]> { | 1493 | static getAllIdsFromChannel (videoChannel: MChannelId): Promise<number[]> { |
1491 | const query = { | 1494 | const query = { |
1492 | attributes: [ 'id' ], | 1495 | attributes: [ 'id' ], |
1493 | where: { | 1496 | where: { |