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.ts46
1 files changed, 33 insertions, 13 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts
index 75de2278c..a1493e5c1 100644
--- a/server/helpers/activitypub.ts
+++ b/server/helpers/activitypub.ts
@@ -1,15 +1,15 @@
1import { join } from 'path'
2import * as request from 'request'
1import * as url from 'url' 3import * as url from 'url'
2 4import { ActivityIconObject } from '../../shared/index'
3import { database as db } from '../initializers'
4import { logger } from './logger'
5import { doRequest, doRequestAndSaveToFile } from './requests'
6import { isRemoteAccountValid } from './custom-validators'
7import { ActivityPubActor } from '../../shared/models/activitypub/activitypub-actor' 5import { ActivityPubActor } from '../../shared/models/activitypub/activitypub-actor'
8import { ResultList } from '../../shared/models/result-list.model' 6import { ResultList } from '../../shared/models/result-list.model'
9import { CONFIG } from '../initializers/constants' 7import { database as db, REMOTE_SCHEME } from '../initializers'
8import { CONFIG, STATIC_PATHS } from '../initializers/constants'
10import { VideoInstance } from '../models/video/video-interface' 9import { VideoInstance } from '../models/video/video-interface'
11import { ActivityIconObject } from '../../shared/index' 10import { isRemoteAccountValid } from './custom-validators'
12import { join } from 'path' 11import { logger } from './logger'
12import { doRequest, doRequestAndSaveToFile } from './requests'
13 13
14function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObject) { 14function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObject) {
15 const thumbnailName = video.getThumbnailName() 15 const thumbnailName = video.getThumbnailName()
@@ -22,9 +22,10 @@ function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObjec
22 return doRequestAndSaveToFile(options, thumbnailPath) 22 return doRequestAndSaveToFile(options, thumbnailPath)
23} 23}
24 24
25function getActivityPubUrl (type: 'video' | 'videoChannel', uuid: string) { 25function getActivityPubUrl (type: 'video' | 'videoChannel' | 'account', id: string) {
26 if (type === 'video') return CONFIG.WEBSERVER.URL + '/videos/watch/' + uuid 26 if (type === 'video') return CONFIG.WEBSERVER.URL + '/videos/watch/' + id
27 else if (type === 'videoChannel') return CONFIG.WEBSERVER.URL + '/video-channels/' + uuid 27 else if (type === 'videoChannel') return CONFIG.WEBSERVER.URL + '/video-channels/' + id
28 else if (type === 'account') return CONFIG.WEBSERVER.URL + '/account/' + id
28 29
29 return '' 30 return ''
30} 31}
@@ -94,7 +95,24 @@ async function fetchRemoteAccountAndCreatePod (accountUrl: string) {
94 return { account, pod } 95 return { account, pod }
95} 96}
96 97
97function activityPubContextify (data: object) { 98function fetchRemoteVideoPreview (video: VideoInstance) {
99 // FIXME: use url
100 const host = video.VideoChannel.Account.Pod.host
101 const path = join(STATIC_PATHS.PREVIEWS, video.getPreviewName())
102
103 return request.get(REMOTE_SCHEME.HTTP + '://' + host + path)
104}
105
106async function fetchRemoteVideoDescription (video: VideoInstance) {
107 const options = {
108 uri: video.url
109 }
110
111 const { body } = await doRequest(options)
112 return body.description ? body.description : ''
113}
114
115function activityPubContextify <T> (data: T) {
98 return Object.assign(data,{ 116 return Object.assign(data,{
99 '@context': [ 117 '@context': [
100 'https://www.w3.org/ns/activitystreams', 118 'https://www.w3.org/ns/activitystreams',
@@ -141,7 +159,9 @@ export {
141 activityPubCollectionPagination, 159 activityPubCollectionPagination,
142 getActivityPubUrl, 160 getActivityPubUrl,
143 generateThumbnailFromUrl, 161 generateThumbnailFromUrl,
144 getOrCreateAccount 162 getOrCreateAccount,
163 fetchRemoteVideoPreview,
164 fetchRemoteVideoDescription
145} 165}
146 166
147// --------------------------------------------------------------------------- 167// ---------------------------------------------------------------------------