X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Faccount%2Faccount.ts;h=61a88524c2d39662557d9ba524450f01b0566981;hb=25ed141c7c7631ef21d8764c1163fbf8a6591391;hp=faf5fa841f5ca3c645cea15e37d736f458329d8d;hpb=79d5caf994edd87ad721994490f10677be277497;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/account/account.ts b/server/models/account/account.ts index faf5fa841..61a88524c 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -1,34 +1,26 @@ import * as Sequelize from 'sequelize' - import { activityPubContextify, isAccountFollowersCountValid, - isAccountFollowersValid, isAccountFollowingCountValid, - isAccountFollowingValid, - isAccountInboxValid, - isAccountOutboxValid, isAccountPrivateKeyValid, isAccountPublicKeyValid, - isAccountSharedInboxValid, - isAccountUrlValid, isUserUsernameValid } from '../../helpers' +import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants' -import { sendDeleteAccount } from '../../lib/activitypub/send-request' - +import { sendDeleteAccount } from '../../lib/activitypub/send/send-delete' import { addMethodsToModel } from '../utils' import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface' let Account: Sequelize.Model -let loadAccountByServerAndUUID: AccountMethods.LoadAccountByServerAndUUID let load: AccountMethods.Load let loadApplication: AccountMethods.LoadApplication let loadByUUID: AccountMethods.LoadByUUID let loadByUrl: AccountMethods.LoadByUrl let loadLocalByName: AccountMethods.LoadLocalByName let loadByNameAndHost: AccountMethods.LoadByNameAndHost -let listOwned: AccountMethods.ListOwned +let listByFollowersUrls: AccountMethods.ListByFollowersUrls let isOwned: AccountMethods.IsOwned let toActivityPubObject: AccountMethods.ToActivityPubObject let toFormattedJSON: AccountMethods.ToFormattedJSON @@ -63,7 +55,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { urlValid: value => { - const res = isAccountUrlValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('URL is not valid.') } } @@ -113,7 +105,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { inboxUrlValid: value => { - const res = isAccountInboxValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Inbox URL is not valid.') } } @@ -123,7 +115,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { outboxUrlValid: value => { - const res = isAccountOutboxValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Outbox URL is not valid.') } } @@ -133,7 +125,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { sharedInboxUrlValid: value => { - const res = isAccountSharedInboxValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Shared inbox URL is not valid.') } } @@ -143,7 +135,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { followersUrlValid: value => { - const res = isAccountFollowersValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Followers URL is not valid.') } } @@ -153,7 +145,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { followingUrlValid: value => { - const res = isAccountFollowingValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Following URL is not valid.') } } @@ -186,14 +178,13 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes const classMethods = [ associate, - loadAccountByServerAndUUID, loadApplication, load, loadByUUID, loadByUrl, loadLocalByName, loadByNameAndHost, - listOwned + listByFollowersUrls ] const instanceMethods = [ isOwned, @@ -323,7 +314,7 @@ isOwned = function (this: AccountInstance) { return this.serverId === null } -getFollowerSharedInboxUrls = function (this: AccountInstance) { +getFollowerSharedInboxUrls = function (this: AccountInstance, t: Sequelize.Transaction) { const query: Sequelize.FindOptions = { attributes: [ 'sharedInboxUrl' ], include: [ @@ -335,7 +326,8 @@ getFollowerSharedInboxUrls = function (this: AccountInstance) { targetAccountId: this.id } } - ] + ], + transaction: t } return Account.findAll(query) @@ -356,16 +348,6 @@ getPublicKeyUrl = function (this: AccountInstance) { // ------------------------------ STATICS ------------------------------ -listOwned = function () { - const query: Sequelize.FindOptions = { - where: { - serverId: null - } - } - - return Account.findAll(query) -} - loadApplication = function () { return Account.findOne({ include: [ @@ -443,14 +425,15 @@ loadByUrl = function (url: string, transaction?: Sequelize.Transaction) { return Account.findOne(query) } -loadAccountByServerAndUUID = function (uuid: string, serverId: number, transaction: Sequelize.Transaction) { +listByFollowersUrls = function (followersUrls: string[], transaction?: Sequelize.Transaction) { const query: Sequelize.FindOptions = { where: { - serverId, - uuid + followersUrl: { + [Sequelize.Op.in]: followersUrls + } }, transaction } - return Account.find(query) + return Account.findAll(query) }