aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/activitypub/account.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/activitypub/account.ts')
-rw-r--r--server/helpers/custom-validators/activitypub/account.ts31
1 files changed, 21 insertions, 10 deletions
diff --git a/server/helpers/custom-validators/activitypub/account.ts b/server/helpers/custom-validators/activitypub/account.ts
index acd2b8058..645f55a5a 100644
--- a/server/helpers/custom-validators/activitypub/account.ts
+++ b/server/helpers/custom-validators/activitypub/account.ts
@@ -1,9 +1,8 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2
3import { exists, isUUIDValid } from '../misc'
4import { isActivityPubUrlValid } from './misc'
5import { isUserUsernameValid } from '../users'
6import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 2import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
3import { isAccountNameValid } from '../accounts'
4import { exists, isUUIDValid } from '../misc'
5import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
7 6
8function isAccountEndpointsObjectValid (endpointObject: any) { 7function isAccountEndpointsObjectValid (endpointObject: any) {
9 return isAccountSharedInboxValid(endpointObject.sharedInbox) 8 return isAccountSharedInboxValid(endpointObject.sharedInbox)
@@ -59,10 +58,6 @@ function isAccountOutboxValid (outbox: string) {
59 return isActivityPubUrlValid(outbox) 58 return isActivityPubUrlValid(outbox)
60} 59}
61 60
62function isAccountNameValid (name: string) {
63 return isUserUsernameValid(name)
64}
65
66function isAccountPreferredUsernameValid (preferredUsername: string) { 61function isAccountPreferredUsernameValid (preferredUsername: string) {
67 return isAccountNameValid(preferredUsername) 62 return isAccountNameValid(preferredUsername)
68} 63}
@@ -90,7 +85,7 @@ function isRemoteAccountValid (remoteAccount: any) {
90 isAccountPreferredUsernameValid(remoteAccount.preferredUsername) && 85 isAccountPreferredUsernameValid(remoteAccount.preferredUsername) &&
91 isAccountUrlValid(remoteAccount.url) && 86 isAccountUrlValid(remoteAccount.url) &&
92 isAccountPublicKeyObjectValid(remoteAccount.publicKey) && 87 isAccountPublicKeyObjectValid(remoteAccount.publicKey) &&
93 isAccountEndpointsObjectValid(remoteAccount.endpoint) 88 isAccountEndpointsObjectValid(remoteAccount.endpoints)
94} 89}
95 90
96function isAccountFollowingCountValid (value: string) { 91function isAccountFollowingCountValid (value: string) {
@@ -101,6 +96,19 @@ function isAccountFollowersCountValid (value: string) {
101 return exists(value) && validator.isInt('' + value, { min: 0 }) 96 return exists(value) && validator.isInt('' + value, { min: 0 })
102} 97}
103 98
99function isAccountDeleteActivityValid (activity: any) {
100 return isBaseActivityValid(activity, 'Delete')
101}
102
103function isAccountFollowActivityValid (activity: any) {
104 return isBaseActivityValid(activity, 'Follow') &&
105 isActivityPubUrlValid(activity.object)
106}
107
108function isAccountAcceptActivityValid (activity: any) {
109 return isBaseActivityValid(activity, 'Accept')
110}
111
104// --------------------------------------------------------------------------- 112// ---------------------------------------------------------------------------
105 113
106export { 114export {
@@ -122,5 +130,8 @@ export {
122 isRemoteAccountValid, 130 isRemoteAccountValid,
123 isAccountFollowingCountValid, 131 isAccountFollowingCountValid,
124 isAccountFollowersCountValid, 132 isAccountFollowersCountValid,
125 isAccountNameValid 133 isAccountNameValid,
134 isAccountFollowActivityValid,
135 isAccountAcceptActivityValid,
136 isAccountDeleteActivityValid
126} 137}