aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/activitypub.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/activitypub.ts')
-rw-r--r--server/helpers/activitypub.ts45
1 files changed, 43 insertions, 2 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts
index ecb509b66..75de2278c 100644
--- a/server/helpers/activitypub.ts
+++ b/server/helpers/activitypub.ts
@@ -2,10 +2,48 @@ import * as url from 'url'
2 2
3import { database as db } from '../initializers' 3import { database as db } from '../initializers'
4import { logger } from './logger' 4import { logger } from './logger'
5import { doRequest } from './requests' 5import { doRequest, doRequestAndSaveToFile } from './requests'
6import { isRemoteAccountValid } from './custom-validators' 6import { isRemoteAccountValid } from './custom-validators'
7import { ActivityPubActor } from '../../shared/models/activitypub/activitypub-actor' 7import { ActivityPubActor } from '../../shared/models/activitypub/activitypub-actor'
8import { ResultList } from '../../shared/models/result-list.model' 8import { ResultList } from '../../shared/models/result-list.model'
9import { CONFIG } from '../initializers/constants'
10import { VideoInstance } from '../models/video/video-interface'
11import { ActivityIconObject } from '../../shared/index'
12import { join } from 'path'
13
14function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObject) {
15 const thumbnailName = video.getThumbnailName()
16 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName)
17
18 const options = {
19 method: 'GET',
20 uri: icon.url
21 }
22 return doRequestAndSaveToFile(options, thumbnailPath)
23}
24
25function getActivityPubUrl (type: 'video' | 'videoChannel', uuid: string) {
26 if (type === 'video') return CONFIG.WEBSERVER.URL + '/videos/watch/' + uuid
27 else if (type === 'videoChannel') return CONFIG.WEBSERVER.URL + '/video-channels/' + uuid
28
29 return ''
30}
31
32async function getOrCreateAccount (accountUrl: string) {
33 let account = await db.Account.loadByUrl(accountUrl)
34
35 // We don't have this account in our database, fetch it on remote
36 if (!account) {
37 const { account } = await fetchRemoteAccountAndCreatePod(accountUrl)
38
39 if (!account) throw new Error('Cannot fetch remote account.')
40
41 // Save our new account in database
42 await account.save()
43 }
44
45 return account
46}
9 47
10async function fetchRemoteAccountAndCreatePod (accountUrl: string) { 48async function fetchRemoteAccountAndCreatePod (accountUrl: string) {
11 const options = { 49 const options = {
@@ -100,7 +138,10 @@ function activityPubCollectionPagination (url: string, page: number, result: Res
100export { 138export {
101 fetchRemoteAccountAndCreatePod, 139 fetchRemoteAccountAndCreatePod,
102 activityPubContextify, 140 activityPubContextify,
103 activityPubCollectionPagination 141 activityPubCollectionPagination,
142 getActivityPubUrl,
143 generateThumbnailFromUrl,
144 getOrCreateAccount
104} 145}
105 146
106// --------------------------------------------------------------------------- 147// ---------------------------------------------------------------------------