mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Follow works
This commit is contained in:
parent
e34c85e527
commit
350e31d6b6
39 changed files with 431 additions and 169 deletions
|
@ -10,14 +10,14 @@ import { logger } from '../logger'
|
|||
import { isUserUsernameValid } from './users'
|
||||
import { isHostValid } from './pods'
|
||||
|
||||
function isVideoAccountNameValid (value: string) {
|
||||
function isAccountNameValid (value: string) {
|
||||
return isUserUsernameValid(value)
|
||||
}
|
||||
|
||||
function isAccountNameWithHostValid (value: string) {
|
||||
const [ name, host ] = value.split('@')
|
||||
|
||||
return isVideoAccountNameValid(name) && isHostValid(host)
|
||||
return isAccountNameValid(name) && isHostValid(host)
|
||||
}
|
||||
|
||||
function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) {
|
||||
|
@ -38,10 +38,10 @@ function checkVideoAccountExists (id: string, res: express.Response, callback: (
|
|||
res.locals.account = account
|
||||
callback()
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Error in video account request validator.', err)
|
||||
return res.sendStatus(500)
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Error in video account request validator.', err)
|
||||
return res.sendStatus(500)
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@ -49,5 +49,5 @@ function checkVideoAccountExists (id: string, res: express.Response, callback: (
|
|||
export {
|
||||
checkVideoAccountExists,
|
||||
isAccountNameWithHostValid,
|
||||
isVideoAccountNameValid
|
||||
isAccountNameValid
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
import * as validator from 'validator'
|
||||
|
||||
import { exists, isUUIDValid } from '../misc'
|
||||
import { isActivityPubUrlValid } from './misc'
|
||||
import { isUserUsernameValid } from '../users'
|
||||
import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
|
||||
import { isAccountNameValid } from '../accounts'
|
||||
import { exists, isUUIDValid } from '../misc'
|
||||
import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
|
||||
|
||||
function isAccountEndpointsObjectValid (endpointObject: any) {
|
||||
return isAccountSharedInboxValid(endpointObject.sharedInbox)
|
||||
|
@ -59,10 +58,6 @@ function isAccountOutboxValid (outbox: string) {
|
|||
return isActivityPubUrlValid(outbox)
|
||||
}
|
||||
|
||||
function isAccountNameValid (name: string) {
|
||||
return isUserUsernameValid(name)
|
||||
}
|
||||
|
||||
function isAccountPreferredUsernameValid (preferredUsername: string) {
|
||||
return isAccountNameValid(preferredUsername)
|
||||
}
|
||||
|
@ -90,7 +85,7 @@ function isRemoteAccountValid (remoteAccount: any) {
|
|||
isAccountPreferredUsernameValid(remoteAccount.preferredUsername) &&
|
||||
isAccountUrlValid(remoteAccount.url) &&
|
||||
isAccountPublicKeyObjectValid(remoteAccount.publicKey) &&
|
||||
isAccountEndpointsObjectValid(remoteAccount.endpoint)
|
||||
isAccountEndpointsObjectValid(remoteAccount.endpoints)
|
||||
}
|
||||
|
||||
function isAccountFollowingCountValid (value: string) {
|
||||
|
@ -101,6 +96,19 @@ function isAccountFollowersCountValid (value: string) {
|
|||
return exists(value) && validator.isInt('' + value, { min: 0 })
|
||||
}
|
||||
|
||||
function isAccountDeleteActivityValid (activity: any) {
|
||||
return isBaseActivityValid(activity, 'Delete')
|
||||
}
|
||||
|
||||
function isAccountFollowActivityValid (activity: any) {
|
||||
return isBaseActivityValid(activity, 'Follow') &&
|
||||
isActivityPubUrlValid(activity.object)
|
||||
}
|
||||
|
||||
function isAccountAcceptActivityValid (activity: any) {
|
||||
return isBaseActivityValid(activity, 'Accept')
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
|
@ -122,5 +130,8 @@ export {
|
|||
isRemoteAccountValid,
|
||||
isAccountFollowingCountValid,
|
||||
isAccountFollowersCountValid,
|
||||
isAccountNameValid
|
||||
isAccountNameValid,
|
||||
isAccountFollowActivityValid,
|
||||
isAccountAcceptActivityValid,
|
||||
isAccountDeleteActivityValid
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import * as validator from 'validator'
|
||||
import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account'
|
||||
import { isActivityPubUrlValid } from './misc'
|
||||
import {
|
||||
isVideoChannelCreateActivityValid,
|
||||
isVideoChannelDeleteActivityValid,
|
||||
isVideoChannelUpdateActivityValid,
|
||||
isVideoTorrentAddActivityValid,
|
||||
isVideoTorrentUpdateActivityValid,
|
||||
isVideoChannelUpdateActivityValid
|
||||
isVideoTorrentDeleteActivityValid,
|
||||
isVideoTorrentUpdateActivityValid
|
||||
} from './videos'
|
||||
|
||||
function isRootActivityValid (activity: any) {
|
||||
|
@ -14,8 +18,8 @@ function isRootActivityValid (activity: any) {
|
|||
Array.isArray(activity.items)
|
||||
) ||
|
||||
(
|
||||
validator.isURL(activity.id) &&
|
||||
validator.isURL(activity.actor)
|
||||
isActivityPubUrlValid(activity.id) &&
|
||||
isActivityPubUrlValid(activity.actor)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -23,7 +27,12 @@ function isActivityValid (activity: any) {
|
|||
return isVideoTorrentAddActivityValid(activity) ||
|
||||
isVideoChannelCreateActivityValid(activity) ||
|
||||
isVideoTorrentUpdateActivityValid(activity) ||
|
||||
isVideoChannelUpdateActivityValid(activity)
|
||||
isVideoChannelUpdateActivityValid(activity) ||
|
||||
isVideoTorrentDeleteActivityValid(activity) ||
|
||||
isVideoChannelDeleteActivityValid(activity) ||
|
||||
isAccountDeleteActivityValid(activity) ||
|
||||
isAccountFollowActivityValid(activity) ||
|
||||
isAccountAcceptActivityValid(activity)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
@ -23,10 +23,12 @@ function isActivityPubUrlValid (url: string) {
|
|||
function isBaseActivityValid (activity: any, type: string) {
|
||||
return Array.isArray(activity['@context']) &&
|
||||
activity.type === type &&
|
||||
validator.isURL(activity.id) &&
|
||||
validator.isURL(activity.actor) &&
|
||||
Array.isArray(activity.to) &&
|
||||
activity.to.every(t => validator.isURL(t))
|
||||
isActivityPubUrlValid(activity.id) &&
|
||||
isActivityPubUrlValid(activity.actor) &&
|
||||
(
|
||||
activity.to === undefined ||
|
||||
(Array.isArray(activity.to) && activity.to.every(t => isActivityPubUrlValid(t)))
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
isVideoUrlValid
|
||||
} from '../videos'
|
||||
import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels'
|
||||
import { isBaseActivityValid } from './misc'
|
||||
import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
|
||||
|
||||
function isVideoTorrentAddActivityValid (activity: any) {
|
||||
return isBaseActivityValid(activity, 'Add') &&
|
||||
|
@ -26,6 +26,10 @@ function isVideoTorrentUpdateActivityValid (activity: any) {
|
|||
isVideoTorrentObjectValid(activity.object)
|
||||
}
|
||||
|
||||
function isVideoTorrentDeleteActivityValid (activity: any) {
|
||||
return isBaseActivityValid(activity, 'Delete')
|
||||
}
|
||||
|
||||
function isVideoTorrentObjectValid (video: any) {
|
||||
return video.type === 'Video' &&
|
||||
isVideoNameValid(video.name) &&
|
||||
|
@ -54,6 +58,10 @@ function isVideoChannelUpdateActivityValid (activity: any) {
|
|||
isVideoChannelObjectValid(activity.object)
|
||||
}
|
||||
|
||||
function isVideoChannelDeleteActivityValid (activity: any) {
|
||||
return isBaseActivityValid(activity, 'Delete')
|
||||
}
|
||||
|
||||
function isVideoChannelObjectValid (videoChannel: any) {
|
||||
return videoChannel.type === 'VideoChannel' &&
|
||||
isVideoChannelNameValid(videoChannel.name) &&
|
||||
|
@ -67,7 +75,9 @@ export {
|
|||
isVideoTorrentAddActivityValid,
|
||||
isVideoChannelCreateActivityValid,
|
||||
isVideoTorrentUpdateActivityValid,
|
||||
isVideoChannelUpdateActivityValid
|
||||
isVideoChannelUpdateActivityValid,
|
||||
isVideoChannelDeleteActivityValid,
|
||||
isVideoTorrentDeleteActivityValid
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
@ -3,6 +3,7 @@ export * from './misc'
|
|||
export * from './pods'
|
||||
export * from './pods'
|
||||
export * from './users'
|
||||
export * from './video-accounts'
|
||||
export * from './accounts'
|
||||
export * from './video-channels'
|
||||
export * from './videos'
|
||||
export * from './webfinger'
|
||||
|
|
25
server/helpers/custom-validators/webfinger.ts
Normal file
25
server/helpers/custom-validators/webfinger.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import 'express-validator'
|
||||
import 'multer'
|
||||
import { CONFIG } from '../../initializers/constants'
|
||||
import { exists } from './misc'
|
||||
|
||||
function isWebfingerResourceValid (value: string) {
|
||||
if (!exists(value)) return false
|
||||
if (value.startsWith('acct:') === false) return false
|
||||
|
||||
const accountWithHost = value.substr(5)
|
||||
const accountParts = accountWithHost.split('@')
|
||||
if (accountParts.length !== 2) return false
|
||||
|
||||
const host = accountParts[1]
|
||||
|
||||
if (host !== CONFIG.WEBSERVER.HOST) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
isWebfingerResourceValid
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue