]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/account/account.ts
Put activity pub sends inside transactions
[github/Chocobozzz/PeerTube.git] / server / models / account / account.ts
index fff3ce08799b147062c8f6df2dad8a33ca0da283..61a88524c2d39662557d9ba524450f01b0566981 100644 (file)
@@ -2,20 +2,14 @@ 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/send-delete'
-
 import { addMethodsToModel } from '../utils'
 import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface'
 
@@ -61,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.')
           }
         }
@@ -111,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.')
           }
         }
@@ -121,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.')
           }
         }
@@ -131,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.')
           }
         }
@@ -141,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.')
           }
         }
@@ -151,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.')
           }
         }
@@ -320,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<AccountAttributes> = {
     attributes: [ 'sharedInboxUrl' ],
     include: [
@@ -332,7 +326,8 @@ getFollowerSharedInboxUrls = function (this: AccountInstance) {
           targetAccountId: this.id
         }
       }
-    ]
+    ],
+    transaction: t
   }
 
   return Account.findAll(query)