X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Factivitypub%2Factor.ts;h=4a466441cd98a73c034ace260279a884d38aeb34;hb=3acc50844047a37698f0618fa235c138e386a053;hp=7d91e8a4ac97ac92bc3e575fa64d43b16c5b08d6;hpb=9f79ade627f0044606a9fbbe16ca0154661d12b9;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 7d91e8a4a..4a466441c 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts @@ -30,7 +30,7 @@ import { isActorPublicKeyValid } from '../../helpers/custom-validators/activitypub/actor' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' -import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' +import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' import { AccountModel } from '../account/account' import { AvatarModel } from '../avatar/avatar' import { ServerModel } from '../server/server' @@ -56,46 +56,46 @@ export const unusedActorAttributesForAPI = [ 'updatedAt' ] -@DefaultScope({ +@DefaultScope(() => ({ include: [ { - model: () => ServerModel, + model: ServerModel, required: false }, { - model: () => AvatarModel, + model: AvatarModel, required: false } ] -}) -@Scopes({ +})) +@Scopes(() => ({ [ScopeNames.FULL]: { include: [ { - model: () => AccountModel.unscoped(), + model: AccountModel.unscoped(), required: false }, { - model: () => VideoChannelModel.unscoped(), + model: VideoChannelModel.unscoped(), required: false, include: [ { - model: () => AccountModel, + model: AccountModel, required: true } ] }, { - model: () => ServerModel, + model: ServerModel, required: false }, { - model: () => AvatarModel, + model: AvatarModel, required: false } ] } -}) +})) @Table({ tableName: 'actor', indexes: [ @@ -131,7 +131,7 @@ export const unusedActorAttributesForAPI = [ export class ActorModel extends Model { @AllowNull(false) - @Column(DataType.ENUM(values(ACTIVITY_PUB_ACTOR_TYPES))) + @Column(DataType.ENUM(...values(ACTIVITY_PUB_ACTOR_TYPES))) type: ActivityPubActorType @AllowNull(false) @@ -151,12 +151,12 @@ export class ActorModel extends Model { url: string @AllowNull(true) - @Is('ActorPublicKey', value => throwIfNotValid(value, isActorPublicKeyValid, 'public key')) + @Is('ActorPublicKey', value => throwIfNotValid(value, isActorPublicKeyValid, 'public key', true)) @Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.PUBLIC_KEY.max)) publicKey: string @AllowNull(true) - @Is('ActorPublicKey', value => throwIfNotValid(value, isActorPrivateKeyValid, 'private key')) + @Is('ActorPublicKey', value => throwIfNotValid(value, isActorPrivateKeyValid, 'private key', true)) @Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.PRIVATE_KEY.max)) privateKey: string @@ -280,14 +280,16 @@ export class ActorModel extends Model { attributes: [ 'id' ], model: VideoChannelModel.unscoped(), required: true, - include: { - attributes: [ 'id' ], - model: VideoModel.unscoped(), - required: true, - where: { - id: videoId + include: [ + { + attributes: [ 'id' ], + model: VideoModel.unscoped(), + required: true, + where: { + id: videoId + } } - } + ] } ] } @@ -295,7 +297,7 @@ export class ActorModel extends Model { transaction } - return ActorModel.unscoped().findOne(query as any) // FIXME: typings + return ActorModel.unscoped().findOne(query) } static isActorUrlExist (url: string) { @@ -389,8 +391,7 @@ export class ActorModel extends Model { } static incrementFollows (id: number, column: 'followersCount' | 'followingCount', by: number) { - // FIXME: typings - return (ActorModel as any).increment(column, { + return ActorModel.increment(column, { by, where: { id @@ -516,7 +517,7 @@ export class ActorModel extends Model { } getHost () { - return this.Server ? this.Server.host : CONFIG.WEBSERVER.HOST + return this.Server ? this.Server.host : WEBSERVER.HOST } getRedundancyAllowed () { @@ -526,7 +527,7 @@ export class ActorModel extends Model { getAvatarUrl () { if (!this.avatarId) return undefined - return CONFIG.WEBSERVER.URL + this.Avatar.getWebserverPath() + return WEBSERVER.URL + this.Avatar.getWebserverPath() } isOutdated () {