aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-12-08 14:30:29 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-12-09 11:41:22 +0100
commitb49f22d8f9a52ab75fd38db2d377249eb58fa678 (patch)
treea2825877d7b3b53454804a79c9d2a14c5d37385c /server/models/activitypub
parent6c8c15f914cd375da1db5d0cd4d924a86c53d4c1 (diff)
downloadPeerTube-b49f22d8f9a52ab75fd38db2d377249eb58fa678.tar.gz
PeerTube-b49f22d8f9a52ab75fd38db2d377249eb58fa678.tar.zst
PeerTube-b49f22d8f9a52ab75fd38db2d377249eb58fa678.zip
Upgrade sequelize to v6
Diffstat (limited to 'server/models/activitypub')
-rw-r--r--server/models/activitypub/actor-follow.ts13
-rw-r--r--server/models/activitypub/actor.ts44
2 files changed, 28 insertions, 29 deletions
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 @@
1import * as Bluebird from 'bluebird'
2import { difference, values } from 'lodash' 1import { difference, values } from 'lodash'
3import { IncludeOptions, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' 2import { IncludeOptions, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
4import { 3import {
@@ -62,7 +61,7 @@ import { ActorModel, unusedActorAttributesForAPI } from './actor'
62 } 61 }
63 ] 62 ]
64}) 63})
65export class ActorFollowModel extends Model<ActorFollowModel> { 64export 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 @@
1import { values } from 'lodash' 1import { values } from 'lodash'
2import { extname } from 'path' 2import { extname } from 'path'
3import { literal, Op, Transaction } from 'sequelize'
3import { 4import {
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'
20import { ModelCache } from '@server/models/model-cache'
19import { ActivityIconObject, ActivityPubActorType } from '../../../shared/models/activitypub' 21import { ActivityIconObject, ActivityPubActorType } from '../../../shared/models/activitypub'
20import { Avatar } from '../../../shared/models/avatars/avatar.model' 22import { Avatar } from '../../../shared/models/avatars/avatar.model'
21import { activityPubContextify } from '../../helpers/activitypub' 23import { activityPubContextify } from '../../helpers/activitypub'
@@ -28,13 +30,6 @@ import {
28} from '../../helpers/custom-validators/activitypub/actor' 30} from '../../helpers/custom-validators/activitypub/actor'
29import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 31import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
30import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONSTRAINTS_FIELDS, SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' 32import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONSTRAINTS_FIELDS, SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants'
31import { AccountModel } from '../account/account'
32import { AvatarModel } from '../avatar/avatar'
33import { ServerModel } from '../server/server'
34import { isOutdated, throwIfNotValid } from '../utils'
35import { VideoChannelModel } from '../video/video-channel'
36import { ActorFollowModel } from './actor-follow'
37import { VideoModel } from '../video/video'
38import { 33import {
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'
49import * as Bluebird from 'bluebird' 45import { AccountModel } from '../account/account'
50import { Op, Transaction, literal } from 'sequelize' 46import { AvatarModel } from '../avatar/avatar'
51import { ModelCache } from '@server/models/model-cache' 47import { ServerModel } from '../server/server'
48import { isOutdated, throwIfNotValid } from '../utils'
49import { VideoModel } from '../video/video'
50import { VideoChannelModel } from '../video/video-channel'
51import { ActorFollowModel } from './actor-follow'
52 52
53enum ScopeNames { 53enum ScopeNames {
54 FULL = 'FULL' 54 FULL = 'FULL'
@@ -146,7 +146,7 @@ export const unusedActorAttributesForAPI = [
146 } 146 }
147 ] 147 ]
148}) 148})
149export class ActorModel extends Model<ActorModel> { 149export 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 {