aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-18 11:28:17 +0200
committerChocobozzz <me@florianbigard.com>2019-04-24 16:26:20 +0200
commit1735c825726edaa0af5035cb6cbb0cc0db502c6d (patch)
tree7bbb442f2cb4d7be58a4e08d87f5974403a3047c /server/models/activitypub
parente8bafea35bc930cb8ac5b2d521a188642a1adffe (diff)
downloadPeerTube-1735c825726edaa0af5035cb6cbb0cc0db502c6d.tar.gz
PeerTube-1735c825726edaa0af5035cb6cbb0cc0db502c6d.tar.zst
PeerTube-1735c825726edaa0af5035cb6cbb0cc0db502c6d.zip
Update sequelize
Diffstat (limited to 'server/models/activitypub')
-rw-r--r--server/models/activitypub/actor-follow.ts39
-rw-r--r--server/models/activitypub/actor.ts8
2 files changed, 23 insertions, 24 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index f9b4f57f3..b0461b981 100644
--- a/server/models/activitypub/actor-follow.ts
+++ b/server/models/activitypub/actor-follow.ts
@@ -1,6 +1,5 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { values } from 'lodash' 2import { values } from 'lodash'
3import * as Sequelize from 'sequelize'
4import { 3import {
5 AfterCreate, 4 AfterCreate,
6 AfterDestroy, 5 AfterDestroy,
@@ -27,8 +26,8 @@ import { ServerModel } from '../server/server'
27import { getSort } from '../utils' 26import { getSort } from '../utils'
28import { ActorModel, unusedActorAttributesForAPI } from './actor' 27import { ActorModel, unusedActorAttributesForAPI } from './actor'
29import { VideoChannelModel } from '../video/video-channel' 28import { VideoChannelModel } from '../video/video-channel'
30import { IIncludeOptions } from '../../../node_modules/sequelize-typescript/lib/interfaces/IIncludeOptions'
31import { AccountModel } from '../account/account' 29import { AccountModel } from '../account/account'
30import { IncludeOptions, Op, Transaction, QueryTypes } from 'sequelize'
32 31
33@Table({ 32@Table({
34 tableName: 'actorFollow', 33 tableName: 'actorFollow',
@@ -51,7 +50,7 @@ import { AccountModel } from '../account/account'
51export class ActorFollowModel extends Model<ActorFollowModel> { 50export class ActorFollowModel extends Model<ActorFollowModel> {
52 51
53 @AllowNull(false) 52 @AllowNull(false)
54 @Column(DataType.ENUM(values(FOLLOW_STATES))) 53 @Column(DataType.ENUM(...values(FOLLOW_STATES)))
55 state: FollowState 54 state: FollowState
56 55
57 @AllowNull(false) 56 @AllowNull(false)
@@ -126,7 +125,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
126 if (numberOfActorFollowsRemoved) logger.info('Removed bad %d actor follows.', numberOfActorFollowsRemoved) 125 if (numberOfActorFollowsRemoved) logger.info('Removed bad %d actor follows.', numberOfActorFollowsRemoved)
127 } 126 }
128 127
129 static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Sequelize.Transaction) { 128 static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Transaction) {
130 const query = { 129 const query = {
131 where: { 130 where: {
132 actorId, 131 actorId,
@@ -150,8 +149,8 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
150 return ActorFollowModel.findOne(query) 149 return ActorFollowModel.findOne(query)
151 } 150 }
152 151
153 static loadByActorAndTargetNameAndHostForAPI (actorId: number, targetName: string, targetHost: string, t?: Sequelize.Transaction) { 152 static loadByActorAndTargetNameAndHostForAPI (actorId: number, targetName: string, targetHost: string, t?: Transaction) {
154 const actorFollowingPartInclude: IIncludeOptions = { 153 const actorFollowingPartInclude: IncludeOptions = {
155 model: ActorModel, 154 model: ActorModel,
156 required: true, 155 required: true,
157 as: 'ActorFollowing', 156 as: 'ActorFollowing',
@@ -208,7 +207,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
208 .map(t => { 207 .map(t => {
209 if (t.host) { 208 if (t.host) {
210 return { 209 return {
211 [ Sequelize.Op.and ]: [ 210 [ Op.and ]: [
212 { 211 {
213 '$preferredUsername$': t.name 212 '$preferredUsername$': t.name
214 }, 213 },
@@ -220,7 +219,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
220 } 219 }
221 220
222 return { 221 return {
223 [ Sequelize.Op.and ]: [ 222 [ Op.and ]: [
224 { 223 {
225 '$preferredUsername$': t.name 224 '$preferredUsername$': t.name
226 }, 225 },
@@ -234,9 +233,9 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
234 const query = { 233 const query = {
235 attributes: [], 234 attributes: [],
236 where: { 235 where: {
237 [ Sequelize.Op.and ]: [ 236 [ Op.and ]: [
238 { 237 {
239 [ Sequelize.Op.or ]: whereTab 238 [ Op.or ]: whereTab
240 }, 239 },
241 { 240 {
242 actorId 241 actorId
@@ -288,7 +287,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
288 required: true, 287 required: true,
289 where: search ? { 288 where: search ? {
290 host: { 289 host: {
291 [Sequelize.Op.iLike]: '%' + search + '%' 290 [Op.iLike]: '%' + search + '%'
292 } 291 }
293 } : undefined 292 } : undefined
294 } 293 }
@@ -323,7 +322,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
323 required: true, 322 required: true,
324 where: search ? { 323 where: search ? {
325 host: { 324 host: {
326 [ Sequelize.Op.iLike ]: '%' + search + '%' 325 [ Op.iLike ]: '%' + search + '%'
327 } 326 }
328 } : undefined 327 } : undefined
329 } 328 }
@@ -406,11 +405,11 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
406 }) 405 })
407 } 406 }
408 407
409 static listAcceptedFollowerUrlsForAP (actorIds: number[], t: Sequelize.Transaction, start?: number, count?: number) { 408 static listAcceptedFollowerUrlsForAP (actorIds: number[], t: Transaction, start?: number, count?: number) {
410 return ActorFollowModel.createListAcceptedFollowForApiQuery('followers', actorIds, t, start, count) 409 return ActorFollowModel.createListAcceptedFollowForApiQuery('followers', actorIds, t, start, count)
411 } 410 }
412 411
413 static listAcceptedFollowerSharedInboxUrls (actorIds: number[], t: Sequelize.Transaction) { 412 static listAcceptedFollowerSharedInboxUrls (actorIds: number[], t: Transaction) {
414 return ActorFollowModel.createListAcceptedFollowForApiQuery( 413 return ActorFollowModel.createListAcceptedFollowForApiQuery(
415 'followers', 414 'followers',
416 actorIds, 415 actorIds,
@@ -422,7 +421,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
422 ) 421 )
423 } 422 }
424 423
425 static listAcceptedFollowingUrlsForApi (actorIds: number[], t: Sequelize.Transaction, start?: number, count?: number) { 424 static listAcceptedFollowingUrlsForApi (actorIds: number[], t: Transaction, start?: number, count?: number) {
426 return ActorFollowModel.createListAcceptedFollowForApiQuery('following', actorIds, t, start, count) 425 return ActorFollowModel.createListAcceptedFollowForApiQuery('following', actorIds, t, start, count)
427 } 426 }
428 427
@@ -447,7 +446,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
447 } 446 }
448 } 447 }
449 448
450 static updateFollowScore (inboxUrl: string, value: number, t?: Sequelize.Transaction) { 449 static updateFollowScore (inboxUrl: string, value: number, t?: Transaction) {
451 const query = `UPDATE "actorFollow" SET "score" = LEAST("score" + ${value}, ${ACTOR_FOLLOW_SCORE.MAX}) ` + 450 const query = `UPDATE "actorFollow" SET "score" = LEAST("score" + ${value}, ${ACTOR_FOLLOW_SCORE.MAX}) ` +
452 'WHERE id IN (' + 451 'WHERE id IN (' +
453 'SELECT "actorFollow"."id" FROM "actorFollow" ' + 452 'SELECT "actorFollow"."id" FROM "actorFollow" ' +
@@ -456,7 +455,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
456 ')' 455 ')'
457 456
458 const options = { 457 const options = {
459 type: Sequelize.QueryTypes.BULKUPDATE, 458 type: QueryTypes.BULKUPDATE,
460 transaction: t 459 transaction: t
461 } 460 }
462 461
@@ -466,7 +465,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
466 private static async createListAcceptedFollowForApiQuery ( 465 private static async createListAcceptedFollowForApiQuery (
467 type: 'followers' | 'following', 466 type: 'followers' | 'following',
468 actorIds: number[], 467 actorIds: number[],
469 t: Sequelize.Transaction, 468 t: Transaction,
470 start?: number, 469 start?: number,
471 count?: number, 470 count?: number,
472 columnUrl = 'url', 471 columnUrl = 'url',
@@ -502,7 +501,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
502 501
503 const options = { 502 const options = {
504 bind: { actorIds }, 503 bind: { actorIds },
505 type: Sequelize.QueryTypes.SELECT, 504 type: QueryTypes.SELECT,
506 transaction: t 505 transaction: t
507 } 506 }
508 tasks.push(ActorFollowModel.sequelize.query(query, options)) 507 tasks.push(ActorFollowModel.sequelize.query(query, options))
@@ -521,7 +520,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
521 const query = { 520 const query = {
522 where: { 521 where: {
523 score: { 522 score: {
524 [Sequelize.Op.lte]: 0 523 [Op.lte]: 0
525 } 524 }
526 }, 525 },
527 logging: false 526 logging: false
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index e8f603031..1ebee8df5 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -93,7 +93,7 @@ export const unusedActorAttributesForAPI = [
93 model: () => AvatarModel, 93 model: () => AvatarModel,
94 required: false 94 required: false
95 } 95 }
96 ] 96 ] as any // FIXME: sequelize typings
97 } 97 }
98}) 98})
99@Table({ 99@Table({
@@ -131,7 +131,7 @@ export const unusedActorAttributesForAPI = [
131export class ActorModel extends Model<ActorModel> { 131export class ActorModel extends Model<ActorModel> {
132 132
133 @AllowNull(false) 133 @AllowNull(false)
134 @Column(DataType.ENUM(values(ACTIVITY_PUB_ACTOR_TYPES))) 134 @Column({ type: DataType.ENUM(...values(ACTIVITY_PUB_ACTOR_TYPES)) }) // FIXME: sequelize typings
135 type: ActivityPubActorType 135 type: ActivityPubActorType
136 136
137 @AllowNull(false) 137 @AllowNull(false)
@@ -151,12 +151,12 @@ export class ActorModel extends Model<ActorModel> {
151 url: string 151 url: string
152 152
153 @AllowNull(true) 153 @AllowNull(true)
154 @Is('ActorPublicKey', value => throwIfNotValid(value, isActorPublicKeyValid, 'public key')) 154 @Is('ActorPublicKey', value => throwIfNotValid(value, isActorPublicKeyValid, 'public key', true))
155 @Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.PUBLIC_KEY.max)) 155 @Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.PUBLIC_KEY.max))
156 publicKey: string 156 publicKey: string
157 157
158 @AllowNull(true) 158 @AllowNull(true)
159 @Is('ActorPublicKey', value => throwIfNotValid(value, isActorPrivateKeyValid, 'private key')) 159 @Is('ActorPublicKey', value => throwIfNotValid(value, isActorPrivateKeyValid, 'private key', true))
160 @Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.PRIVATE_KEY.max)) 160 @Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.PRIVATE_KEY.max))
161 privateKey: string 161 privateKey: string
162 162