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.ts30
1 files changed, 29 insertions, 1 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts
index de20ba55d..b376b8ca2 100644
--- a/server/helpers/activitypub.ts
+++ b/server/helpers/activitypub.ts
@@ -1,15 +1,19 @@
1import { join } from 'path' 1import { join } from 'path'
2import * as request from 'request' 2import * as request from 'request'
3import * as Sequelize from 'sequelize'
3import * as url from 'url' 4import * as url from 'url'
4import { ActivityIconObject } from '../../shared/index' 5import { ActivityIconObject } from '../../shared/index'
5import { ActivityPubActor } from '../../shared/models/activitypub/activitypub-actor' 6import { ActivityPubActor } from '../../shared/models/activitypub/activitypub-actor'
6import { ResultList } from '../../shared/models/result-list.model' 7import { ResultList } from '../../shared/models/result-list.model'
7import { database as db, REMOTE_SCHEME } from '../initializers' 8import { database as db, REMOTE_SCHEME } from '../initializers'
8import { ACTIVITY_PUB_ACCEPT_HEADER, CONFIG, STATIC_PATHS } from '../initializers/constants' 9import { ACTIVITY_PUB_ACCEPT_HEADER, CONFIG, STATIC_PATHS } from '../initializers/constants'
10import { sendAnnounce } from '../lib/activitypub/send-request'
11import { VideoChannelInstance } from '../models/video/video-channel-interface'
9import { VideoInstance } from '../models/video/video-interface' 12import { VideoInstance } from '../models/video/video-interface'
10import { isRemoteAccountValid } from './custom-validators' 13import { isRemoteAccountValid } from './custom-validators'
11import { logger } from './logger' 14import { logger } from './logger'
12import { doRequest, doRequestAndSaveToFile } from './requests' 15import { doRequest, doRequestAndSaveToFile } from './requests'
16import { getServerAccount } from './utils'
13 17
14function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObject) { 18function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObject) {
15 const thumbnailName = video.getThumbnailName() 19 const thumbnailName = video.getThumbnailName()
@@ -22,6 +26,28 @@ function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObjec
22 return doRequestAndSaveToFile(options, thumbnailPath) 26 return doRequestAndSaveToFile(options, thumbnailPath)
23} 27}
24 28
29async function shareVideoChannelByServer (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
30 const serverAccount = await getServerAccount()
31
32 await db.VideoChannelShare.create({
33 accountId: serverAccount.id,
34 videoChannelId: videoChannel.id
35 }, { transaction: t })
36
37 return sendAnnounce(serverAccount, videoChannel, t)
38}
39
40async function shareVideoByServer (video: VideoInstance, t: Sequelize.Transaction) {
41 const serverAccount = await getServerAccount()
42
43 await db.VideoShare.create({
44 accountId: serverAccount.id,
45 videoId: video.id
46 }, { transaction: t })
47
48 return sendAnnounce(serverAccount, video, t)
49}
50
25function getActivityPubUrl (type: 'video' | 'videoChannel' | 'account' | 'videoAbuse', id: string) { 51function getActivityPubUrl (type: 'video' | 'videoChannel' | 'account' | 'videoAbuse', id: string) {
26 if (type === 'video') return CONFIG.WEBSERVER.URL + '/videos/watch/' + id 52 if (type === 'video') return CONFIG.WEBSERVER.URL + '/videos/watch/' + id
27 else if (type === 'videoChannel') return CONFIG.WEBSERVER.URL + '/video-channels/' + id 53 else if (type === 'videoChannel') return CONFIG.WEBSERVER.URL + '/video-channels/' + id
@@ -172,7 +198,9 @@ export {
172 generateThumbnailFromUrl, 198 generateThumbnailFromUrl,
173 getOrCreateAccount, 199 getOrCreateAccount,
174 fetchRemoteVideoPreview, 200 fetchRemoteVideoPreview,
175 fetchRemoteVideoDescription 201 fetchRemoteVideoDescription,
202 shareVideoChannelByServer,
203 shareVideoByServer
176} 204}
177 205
178// --------------------------------------------------------------------------- 206// ---------------------------------------------------------------------------