diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-20 10:24:29 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | 892211e8493b1f992fce7616cb1e48b7ff87a1dc (patch) | |
tree | 7bb218141a20c14d293d695ad4dad12687e537b2 /server/lib/activitypub/videos.ts | |
parent | 54141398354e6e7b94aa3065a705a1251390111c (diff) | |
download | PeerTube-892211e8493b1f992fce7616cb1e48b7ff87a1dc.tar.gz PeerTube-892211e8493b1f992fce7616cb1e48b7ff87a1dc.tar.zst PeerTube-892211e8493b1f992fce7616cb1e48b7ff87a1dc.zip |
Move activitypub functions from helpers/ to lib/
Diffstat (limited to 'server/lib/activitypub/videos.ts')
-rw-r--r-- | server/lib/activitypub/videos.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts new file mode 100644 index 000000000..944244893 --- /dev/null +++ b/server/lib/activitypub/videos.ts | |||
@@ -0,0 +1,44 @@ | |||
1 | import { join } from 'path' | ||
2 | import * as request from 'request' | ||
3 | import { ActivityIconObject } from '../../../shared/index' | ||
4 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' | ||
5 | import { CONFIG, REMOTE_SCHEME, STATIC_PATHS } from '../../initializers/constants' | ||
6 | import { VideoInstance } from '../../models/video/video-interface' | ||
7 | |||
8 | function fetchRemoteVideoPreview (video: VideoInstance) { | ||
9 | // FIXME: use url | ||
10 | const host = video.VideoChannel.Account.Server.host | ||
11 | const path = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) | ||
12 | |||
13 | return request.get(REMOTE_SCHEME.HTTP + '://' + host + path) | ||
14 | } | ||
15 | |||
16 | async function fetchRemoteVideoDescription (video: VideoInstance) { | ||
17 | // FIXME: use url | ||
18 | const host = video.VideoChannel.Account.Server.host | ||
19 | const path = video.getDescriptionPath() | ||
20 | const options = { | ||
21 | uri: REMOTE_SCHEME.HTTP + '://' + host + path, | ||
22 | json: true | ||
23 | } | ||
24 | |||
25 | const { body } = await doRequest(options) | ||
26 | return body.description ? body.description : '' | ||
27 | } | ||
28 | |||
29 | function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObject) { | ||
30 | const thumbnailName = video.getThumbnailName() | ||
31 | const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName) | ||
32 | |||
33 | const options = { | ||
34 | method: 'GET', | ||
35 | uri: icon.url | ||
36 | } | ||
37 | return doRequestAndSaveToFile(options, thumbnailPath) | ||
38 | } | ||
39 | |||
40 | export { | ||
41 | fetchRemoteVideoPreview, | ||
42 | fetchRemoteVideoDescription, | ||
43 | generateThumbnailFromUrl | ||
44 | } | ||