diff options
Diffstat (limited to 'server/helpers/custom-validators/activitypub/activity.ts')
-rw-r--r-- | server/helpers/custom-validators/activitypub/activity.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts new file mode 100644 index 000000000..dd671c4cf --- /dev/null +++ b/server/helpers/custom-validators/activitypub/activity.ts | |||
@@ -0,0 +1,34 @@ | |||
1 | import * as validator from 'validator' | ||
2 | import { | ||
3 | isVideoChannelCreateActivityValid, | ||
4 | isVideoTorrentAddActivityValid, | ||
5 | isVideoTorrentUpdateActivityValid, | ||
6 | isVideoChannelUpdateActivityValid | ||
7 | } from './videos' | ||
8 | |||
9 | function isRootActivityValid (activity: any) { | ||
10 | return Array.isArray(activity['@context']) && | ||
11 | ( | ||
12 | (activity.type === 'Collection' || activity.type === 'OrderedCollection') && | ||
13 | validator.isInt(activity.totalItems, { min: 0 }) && | ||
14 | Array.isArray(activity.items) | ||
15 | ) || | ||
16 | ( | ||
17 | validator.isURL(activity.id) && | ||
18 | validator.isURL(activity.actor) | ||
19 | ) | ||
20 | } | ||
21 | |||
22 | function isActivityValid (activity: any) { | ||
23 | return isVideoTorrentAddActivityValid(activity) || | ||
24 | isVideoChannelCreateActivityValid(activity) || | ||
25 | isVideoTorrentUpdateActivityValid(activity) || | ||
26 | isVideoChannelUpdateActivityValid(activity) | ||
27 | } | ||
28 | |||
29 | // --------------------------------------------------------------------------- | ||
30 | |||
31 | export { | ||
32 | isRootActivityValid, | ||
33 | isActivityValid | ||
34 | } | ||