aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/activity.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/activity.ts')
-rw-r--r--server/lib/activitypub/activity.ts74
1 files changed, 0 insertions, 74 deletions
diff --git a/server/lib/activitypub/activity.ts b/server/lib/activitypub/activity.ts
deleted file mode 100644
index 391bcd9c6..000000000
--- a/server/lib/activitypub/activity.ts
+++ /dev/null
@@ -1,74 +0,0 @@
1import { doJSONRequest, PeerTubeRequestOptions } from '@server/helpers/requests'
2import { CONFIG } from '@server/initializers/config'
3import { ActivityObject, ActivityPubActor, ActivityType, APObjectId } from '@shared/models'
4import { buildSignedRequestOptions } from './send'
5
6export function getAPId (object: string | { id: string }) {
7 if (typeof object === 'string') return object
8
9 return object.id
10}
11
12export function getActivityStreamDuration (duration: number) {
13 // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
14 return 'PT' + duration + 'S'
15}
16
17export function getDurationFromActivityStream (duration: string) {
18 return parseInt(duration.replace(/[^\d]+/, ''))
19}
20
21// ---------------------------------------------------------------------------
22
23export function buildAvailableActivities (): ActivityType[] {
24 return [
25 'Create',
26 'Update',
27 'Delete',
28 'Follow',
29 'Accept',
30 'Announce',
31 'Undo',
32 'Like',
33 'Reject',
34 'View',
35 'Dislike',
36 'Flag'
37 ]
38}
39
40// ---------------------------------------------------------------------------
41
42export async function fetchAP <T> (url: string, moreOptions: PeerTubeRequestOptions = {}) {
43 const options = {
44 activityPub: true,
45
46 httpSignature: CONFIG.FEDERATION.SIGN_FEDERATED_FETCHES
47 ? await buildSignedRequestOptions({ hasPayload: false })
48 : undefined,
49
50 ...moreOptions
51 }
52
53 return doJSONRequest<T>(url, options)
54}
55
56export async function fetchAPObjectIfNeeded <T extends (ActivityObject | ActivityPubActor)> (object: APObjectId) {
57 if (typeof object === 'string') {
58 const { body } = await fetchAP<Exclude<T, string>>(object)
59
60 return body
61 }
62
63 return object as Exclude<T, string>
64}
65
66export async function findLatestAPRedirection (url: string, iteration = 1) {
67 if (iteration > 10) throw new Error('Too much iterations to find final URL ' + url)
68
69 const { headers } = await fetchAP(url, { followRedirect: false })
70
71 if (headers.location) return findLatestAPRedirection(headers.location, iteration + 1)
72
73 return url
74}