mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
Begin activitypub
This commit is contained in:
parent
343ad675f2
commit
e4f97babf7
92 changed files with 2507 additions and 920 deletions
123
server/helpers/custom-validators/activitypub/account.ts
Normal file
123
server/helpers/custom-validators/activitypub/account.ts
Normal file
|
@ -0,0 +1,123 @@
|
|||
import * as validator from 'validator'
|
||||
|
||||
import { exists, isUUIDValid } from '../misc'
|
||||
import { isActivityPubUrlValid } from './misc'
|
||||
import { isUserUsernameValid } from '../users'
|
||||
|
||||
function isAccountEndpointsObjectValid (endpointObject: any) {
|
||||
return isAccountSharedInboxValid(endpointObject.sharedInbox)
|
||||
}
|
||||
|
||||
function isAccountSharedInboxValid (sharedInbox: string) {
|
||||
return isActivityPubUrlValid(sharedInbox)
|
||||
}
|
||||
|
||||
function isAccountPublicKeyObjectValid (publicKeyObject: any) {
|
||||
return isAccountPublicKeyIdValid(publicKeyObject.id) &&
|
||||
isAccountPublicKeyOwnerValid(publicKeyObject.owner) &&
|
||||
isAccountPublicKeyValid(publicKeyObject.publicKeyPem)
|
||||
}
|
||||
|
||||
function isAccountPublicKeyIdValid (id: string) {
|
||||
return isActivityPubUrlValid(id)
|
||||
}
|
||||
|
||||
function isAccountTypeValid (type: string) {
|
||||
return type === 'Person' || type === 'Application'
|
||||
}
|
||||
|
||||
function isAccountPublicKeyOwnerValid (owner: string) {
|
||||
return isActivityPubUrlValid(owner)
|
||||
}
|
||||
|
||||
function isAccountPublicKeyValid (publicKey: string) {
|
||||
return exists(publicKey) &&
|
||||
typeof publicKey === 'string' &&
|
||||
publicKey.startsWith('-----BEGIN PUBLIC KEY-----') &&
|
||||
publicKey.endsWith('-----END PUBLIC KEY-----')
|
||||
}
|
||||
|
||||
function isAccountIdValid (id: string) {
|
||||
return isActivityPubUrlValid(id)
|
||||
}
|
||||
|
||||
function isAccountFollowingValid (id: string) {
|
||||
return isActivityPubUrlValid(id)
|
||||
}
|
||||
|
||||
function isAccountFollowersValid (id: string) {
|
||||
return isActivityPubUrlValid(id)
|
||||
}
|
||||
|
||||
function isAccountInboxValid (inbox: string) {
|
||||
return isActivityPubUrlValid(inbox)
|
||||
}
|
||||
|
||||
function isAccountOutboxValid (outbox: string) {
|
||||
return isActivityPubUrlValid(outbox)
|
||||
}
|
||||
|
||||
function isAccountNameValid (name: string) {
|
||||
return isUserUsernameValid(name)
|
||||
}
|
||||
|
||||
function isAccountPreferredUsernameValid (preferredUsername: string) {
|
||||
return isAccountNameValid(preferredUsername)
|
||||
}
|
||||
|
||||
function isAccountUrlValid (url: string) {
|
||||
return isActivityPubUrlValid(url)
|
||||
}
|
||||
|
||||
function isAccountPrivateKeyValid (privateKey: string) {
|
||||
return exists(privateKey) &&
|
||||
typeof privateKey === 'string' &&
|
||||
privateKey.startsWith('-----BEGIN RSA PRIVATE KEY-----') &&
|
||||
privateKey.endsWith('-----END RSA PRIVATE KEY-----')
|
||||
}
|
||||
|
||||
function isRemoteAccountValid (remoteAccount: any) {
|
||||
return isAccountIdValid(remoteAccount.id) &&
|
||||
isUUIDValid(remoteAccount.uuid) &&
|
||||
isAccountTypeValid(remoteAccount.type) &&
|
||||
isAccountFollowingValid(remoteAccount.following) &&
|
||||
isAccountFollowersValid(remoteAccount.followers) &&
|
||||
isAccountInboxValid(remoteAccount.inbox) &&
|
||||
isAccountOutboxValid(remoteAccount.outbox) &&
|
||||
isAccountPreferredUsernameValid(remoteAccount.preferredUsername) &&
|
||||
isAccountUrlValid(remoteAccount.url) &&
|
||||
isAccountPublicKeyObjectValid(remoteAccount.publicKey) &&
|
||||
isAccountEndpointsObjectValid(remoteAccount.endpoint)
|
||||
}
|
||||
|
||||
function isAccountFollowingCountValid (value: string) {
|
||||
return exists(value) && validator.isInt('' + value, { min: 0 })
|
||||
}
|
||||
|
||||
function isAccountFollowersCountValid (value: string) {
|
||||
return exists(value) && validator.isInt('' + value, { min: 0 })
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
isAccountEndpointsObjectValid,
|
||||
isAccountSharedInboxValid,
|
||||
isAccountPublicKeyObjectValid,
|
||||
isAccountPublicKeyIdValid,
|
||||
isAccountTypeValid,
|
||||
isAccountPublicKeyOwnerValid,
|
||||
isAccountPublicKeyValid,
|
||||
isAccountIdValid,
|
||||
isAccountFollowingValid,
|
||||
isAccountFollowersValid,
|
||||
isAccountInboxValid,
|
||||
isAccountOutboxValid,
|
||||
isAccountPreferredUsernameValid,
|
||||
isAccountUrlValid,
|
||||
isAccountPrivateKeyValid,
|
||||
isRemoteAccountValid,
|
||||
isAccountFollowingCountValid,
|
||||
isAccountFollowersCountValid,
|
||||
isAccountNameValid
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue