diff options
Diffstat (limited to 'server/helpers/activitypub.ts')
-rw-r--r-- | server/helpers/activitypub.ts | 30 |
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 @@ | |||
1 | import { join } from 'path' | 1 | import { join } from 'path' |
2 | import * as request from 'request' | 2 | import * as request from 'request' |
3 | import * as Sequelize from 'sequelize' | ||
3 | import * as url from 'url' | 4 | import * as url from 'url' |
4 | import { ActivityIconObject } from '../../shared/index' | 5 | import { ActivityIconObject } from '../../shared/index' |
5 | import { ActivityPubActor } from '../../shared/models/activitypub/activitypub-actor' | 6 | import { ActivityPubActor } from '../../shared/models/activitypub/activitypub-actor' |
6 | import { ResultList } from '../../shared/models/result-list.model' | 7 | import { ResultList } from '../../shared/models/result-list.model' |
7 | import { database as db, REMOTE_SCHEME } from '../initializers' | 8 | import { database as db, REMOTE_SCHEME } from '../initializers' |
8 | import { ACTIVITY_PUB_ACCEPT_HEADER, CONFIG, STATIC_PATHS } from '../initializers/constants' | 9 | import { ACTIVITY_PUB_ACCEPT_HEADER, CONFIG, STATIC_PATHS } from '../initializers/constants' |
10 | import { sendAnnounce } from '../lib/activitypub/send-request' | ||
11 | import { VideoChannelInstance } from '../models/video/video-channel-interface' | ||
9 | import { VideoInstance } from '../models/video/video-interface' | 12 | import { VideoInstance } from '../models/video/video-interface' |
10 | import { isRemoteAccountValid } from './custom-validators' | 13 | import { isRemoteAccountValid } from './custom-validators' |
11 | import { logger } from './logger' | 14 | import { logger } from './logger' |
12 | import { doRequest, doRequestAndSaveToFile } from './requests' | 15 | import { doRequest, doRequestAndSaveToFile } from './requests' |
16 | import { getServerAccount } from './utils' | ||
13 | 17 | ||
14 | function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObject) { | 18 | function 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 | ||
29 | async 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 | |||
40 | async 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 | |||
25 | function getActivityPubUrl (type: 'video' | 'videoChannel' | 'account' | 'videoAbuse', id: string) { | 51 | function 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 | // --------------------------------------------------------------------------- |