diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/activitypub.ts | 197 | ||||
-rw-r--r-- | server/helpers/middlewares/videos.ts | 17 | ||||
-rw-r--r-- | server/helpers/video.ts | 27 |
3 files changed, 141 insertions, 100 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts index 326785b68..2d49e6869 100644 --- a/server/helpers/activitypub.ts +++ b/server/helpers/activitypub.ts | |||
@@ -8,102 +8,117 @@ import { pageToStartAndCount } from './core-utils' | |||
8 | import { URL } from 'url' | 8 | import { URL } from 'url' |
9 | import { MActor, MVideoAccountLight } from '../typings/models' | 9 | import { MActor, MVideoAccountLight } from '../typings/models' |
10 | 10 | ||
11 | export type ContextType = 'All' | 'View' | 'Announce' | 11 | export type ContextType = 'All' | 'View' | 'Announce' | 'CacheFile' |
12 | |||
13 | function getContextData (type: ContextType) { | ||
14 | const context: any[] = [ | ||
15 | 'https://www.w3.org/ns/activitystreams', | ||
16 | 'https://w3id.org/security/v1', | ||
17 | { | ||
18 | RsaSignature2017: 'https://w3id.org/security#RsaSignature2017' | ||
19 | } | ||
20 | ] | ||
12 | 21 | ||
13 | function activityPubContextify <T> (data: T, type: ContextType = 'All') { | 22 | if (type !== 'View' && type !== 'Announce') { |
14 | const base = { | 23 | const additional = { |
15 | RsaSignature2017: 'https://w3id.org/security#RsaSignature2017' | 24 | pt: 'https://joinpeertube.org/ns#', |
25 | sc: 'http://schema.org#' | ||
26 | } | ||
27 | |||
28 | if (type === 'CacheFile') { | ||
29 | Object.assign(additional, { | ||
30 | expires: 'sc:expires', | ||
31 | CacheFile: 'pt:CacheFile' | ||
32 | }) | ||
33 | } else { | ||
34 | Object.assign(additional, { | ||
35 | Hashtag: 'as:Hashtag', | ||
36 | uuid: 'sc:identifier', | ||
37 | category: 'sc:category', | ||
38 | licence: 'sc:license', | ||
39 | subtitleLanguage: 'sc:subtitleLanguage', | ||
40 | sensitive: 'as:sensitive', | ||
41 | language: 'sc:inLanguage', | ||
42 | |||
43 | Infohash: 'pt:Infohash', | ||
44 | originallyPublishedAt: 'sc:datePublished', | ||
45 | views: { | ||
46 | '@type': 'sc:Number', | ||
47 | '@id': 'pt:views' | ||
48 | }, | ||
49 | state: { | ||
50 | '@type': 'sc:Number', | ||
51 | '@id': 'pt:state' | ||
52 | }, | ||
53 | size: { | ||
54 | '@type': 'sc:Number', | ||
55 | '@id': 'pt:size' | ||
56 | }, | ||
57 | fps: { | ||
58 | '@type': 'sc:Number', | ||
59 | '@id': 'pt:fps' | ||
60 | }, | ||
61 | startTimestamp: { | ||
62 | '@type': 'sc:Number', | ||
63 | '@id': 'pt:startTimestamp' | ||
64 | }, | ||
65 | stopTimestamp: { | ||
66 | '@type': 'sc:Number', | ||
67 | '@id': 'pt:stopTimestamp' | ||
68 | }, | ||
69 | position: { | ||
70 | '@type': 'sc:Number', | ||
71 | '@id': 'pt:position' | ||
72 | }, | ||
73 | commentsEnabled: { | ||
74 | '@type': 'sc:Boolean', | ||
75 | '@id': 'pt:commentsEnabled' | ||
76 | }, | ||
77 | downloadEnabled: { | ||
78 | '@type': 'sc:Boolean', | ||
79 | '@id': 'pt:downloadEnabled' | ||
80 | }, | ||
81 | waitTranscoding: { | ||
82 | '@type': 'sc:Boolean', | ||
83 | '@id': 'pt:waitTranscoding' | ||
84 | }, | ||
85 | support: { | ||
86 | '@type': 'sc:Text', | ||
87 | '@id': 'pt:support' | ||
88 | }, | ||
89 | likes: { | ||
90 | '@id': 'as:likes', | ||
91 | '@type': '@id' | ||
92 | }, | ||
93 | dislikes: { | ||
94 | '@id': 'as:dislikes', | ||
95 | '@type': '@id' | ||
96 | }, | ||
97 | playlists: { | ||
98 | '@id': 'pt:playlists', | ||
99 | '@type': '@id' | ||
100 | }, | ||
101 | shares: { | ||
102 | '@id': 'as:shares', | ||
103 | '@type': '@id' | ||
104 | }, | ||
105 | comments: { | ||
106 | '@id': 'as:comments', | ||
107 | '@type': '@id' | ||
108 | } | ||
109 | }) | ||
110 | } | ||
111 | |||
112 | context.push(additional) | ||
16 | } | 113 | } |
17 | 114 | ||
18 | if (type === 'All') { | 115 | return { |
19 | Object.assign(base, { | 116 | '@context': context |
20 | pt: 'https://joinpeertube.org/ns#', | ||
21 | sc: 'http://schema.org#', | ||
22 | Hashtag: 'as:Hashtag', | ||
23 | uuid: 'sc:identifier', | ||
24 | category: 'sc:category', | ||
25 | licence: 'sc:license', | ||
26 | subtitleLanguage: 'sc:subtitleLanguage', | ||
27 | sensitive: 'as:sensitive', | ||
28 | language: 'sc:inLanguage', | ||
29 | expires: 'sc:expires', | ||
30 | CacheFile: 'pt:CacheFile', | ||
31 | Infohash: 'pt:Infohash', | ||
32 | originallyPublishedAt: 'sc:datePublished', | ||
33 | views: { | ||
34 | '@type': 'sc:Number', | ||
35 | '@id': 'pt:views' | ||
36 | }, | ||
37 | state: { | ||
38 | '@type': 'sc:Number', | ||
39 | '@id': 'pt:state' | ||
40 | }, | ||
41 | size: { | ||
42 | '@type': 'sc:Number', | ||
43 | '@id': 'pt:size' | ||
44 | }, | ||
45 | fps: { | ||
46 | '@type': 'sc:Number', | ||
47 | '@id': 'pt:fps' | ||
48 | }, | ||
49 | startTimestamp: { | ||
50 | '@type': 'sc:Number', | ||
51 | '@id': 'pt:startTimestamp' | ||
52 | }, | ||
53 | stopTimestamp: { | ||
54 | '@type': 'sc:Number', | ||
55 | '@id': 'pt:stopTimestamp' | ||
56 | }, | ||
57 | position: { | ||
58 | '@type': 'sc:Number', | ||
59 | '@id': 'pt:position' | ||
60 | }, | ||
61 | commentsEnabled: { | ||
62 | '@type': 'sc:Boolean', | ||
63 | '@id': 'pt:commentsEnabled' | ||
64 | }, | ||
65 | downloadEnabled: { | ||
66 | '@type': 'sc:Boolean', | ||
67 | '@id': 'pt:downloadEnabled' | ||
68 | }, | ||
69 | waitTranscoding: { | ||
70 | '@type': 'sc:Boolean', | ||
71 | '@id': 'pt:waitTranscoding' | ||
72 | }, | ||
73 | support: { | ||
74 | '@type': 'sc:Text', | ||
75 | '@id': 'pt:support' | ||
76 | }, | ||
77 | likes: { | ||
78 | '@id': 'as:likes', | ||
79 | '@type': '@id' | ||
80 | }, | ||
81 | dislikes: { | ||
82 | '@id': 'as:dislikes', | ||
83 | '@type': '@id' | ||
84 | }, | ||
85 | playlists: { | ||
86 | '@id': 'pt:playlists', | ||
87 | '@type': '@id' | ||
88 | }, | ||
89 | shares: { | ||
90 | '@id': 'as:shares', | ||
91 | '@type': '@id' | ||
92 | }, | ||
93 | comments: { | ||
94 | '@id': 'as:comments', | ||
95 | '@type': '@id' | ||
96 | } | ||
97 | }) | ||
98 | } | 117 | } |
118 | } | ||
99 | 119 | ||
100 | return Object.assign({}, data, { | 120 | function activityPubContextify <T> (data: T, type: ContextType = 'All') { |
101 | '@context': [ | 121 | return Object.assign({}, data, getContextData(type)) |
102 | 'https://www.w3.org/ns/activitystreams', | ||
103 | 'https://w3id.org/security/v1', | ||
104 | base | ||
105 | ] | ||
106 | }) | ||
107 | } | 122 | } |
108 | 123 | ||
109 | type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>> | 124 | type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>> |
diff --git a/server/helpers/middlewares/videos.ts b/server/helpers/middlewares/videos.ts index 74f529804..409f78650 100644 --- a/server/helpers/middlewares/videos.ts +++ b/server/helpers/middlewares/videos.ts | |||
@@ -2,7 +2,16 @@ import { Response } from 'express' | |||
2 | import { fetchVideo, VideoFetchType } from '../video' | 2 | import { fetchVideo, VideoFetchType } from '../video' |
3 | import { UserRight } from '../../../shared/models/users' | 3 | import { UserRight } from '../../../shared/models/users' |
4 | import { VideoChannelModel } from '../../models/video/video-channel' | 4 | import { VideoChannelModel } from '../../models/video/video-channel' |
5 | import { MUser, MUserAccountId, MVideoAccountLight, MVideoFullLight, MVideoThumbnail, MVideoWithRights } from '@server/typings/models' | 5 | import { |
6 | MUser, | ||
7 | MUserAccountId, | ||
8 | MVideoAccountLight, | ||
9 | MVideoFullLight, | ||
10 | MVideoIdThumbnail, | ||
11 | MVideoImmutable, | ||
12 | MVideoThumbnail, | ||
13 | MVideoWithRights | ||
14 | } from '@server/typings/models' | ||
6 | 15 | ||
7 | async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { | 16 | async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { |
8 | const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined | 17 | const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined |
@@ -22,8 +31,12 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi | |||
22 | res.locals.videoAll = video as MVideoFullLight | 31 | res.locals.videoAll = video as MVideoFullLight |
23 | break | 32 | break |
24 | 33 | ||
34 | case 'only-immutable-attributes': | ||
35 | res.locals.onlyImmutableVideo = video as MVideoImmutable | ||
36 | break | ||
37 | |||
25 | case 'id': | 38 | case 'id': |
26 | res.locals.videoId = video | 39 | res.locals.videoId = video as MVideoIdThumbnail |
27 | break | 40 | break |
28 | 41 | ||
29 | case 'only-video': | 42 | case 'only-video': |
diff --git a/server/helpers/video.ts b/server/helpers/video.ts index 5b9c026b1..4fe2a60f0 100644 --- a/server/helpers/video.ts +++ b/server/helpers/video.ts | |||
@@ -5,13 +5,15 @@ import { | |||
5 | MVideoFullLight, | 5 | MVideoFullLight, |
6 | MVideoIdThumbnail, | 6 | MVideoIdThumbnail, |
7 | MVideoThumbnail, | 7 | MVideoThumbnail, |
8 | MVideoWithRights | 8 | MVideoWithRights, |
9 | MVideoImmutable | ||
9 | } from '@server/typings/models' | 10 | } from '@server/typings/models' |
10 | import { Response } from 'express' | 11 | import { Response } from 'express' |
11 | 12 | ||
12 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 13 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' |
13 | 14 | ||
14 | function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Bluebird<MVideoFullLight> | 15 | function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Bluebird<MVideoFullLight> |
16 | function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Bluebird<MVideoImmutable> | ||
15 | function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Bluebird<MVideoThumbnail> | 17 | function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Bluebird<MVideoThumbnail> |
16 | function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Bluebird<MVideoWithRights> | 18 | function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Bluebird<MVideoWithRights> |
17 | function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Bluebird<MVideoIdThumbnail> | 19 | function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Bluebird<MVideoIdThumbnail> |
@@ -19,14 +21,16 @@ function fetchVideo ( | |||
19 | id: number | string, | 21 | id: number | string, |
20 | fetchType: VideoFetchType, | 22 | fetchType: VideoFetchType, |
21 | userId?: number | 23 | userId?: number |
22 | ): Bluebird<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail> | 24 | ): Bluebird<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> |
23 | function fetchVideo ( | 25 | function fetchVideo ( |
24 | id: number | string, | 26 | id: number | string, |
25 | fetchType: VideoFetchType, | 27 | fetchType: VideoFetchType, |
26 | userId?: number | 28 | userId?: number |
27 | ): Bluebird<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail> { | 29 | ): Bluebird<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> { |
28 | if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) | 30 | if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) |
29 | 31 | ||
32 | if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id) | ||
33 | |||
30 | if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id) | 34 | if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id) |
31 | 35 | ||
32 | if (fetchType === 'only-video') return VideoModel.load(id) | 36 | if (fetchType === 'only-video') return VideoModel.load(id) |
@@ -34,14 +38,23 @@ function fetchVideo ( | |||
34 | if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id) | 38 | if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id) |
35 | } | 39 | } |
36 | 40 | ||
37 | type VideoFetchByUrlType = 'all' | 'only-video' | 41 | type VideoFetchByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' |
38 | 42 | ||
39 | function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird<MVideoAccountLightBlacklistAllFiles> | 43 | function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird<MVideoAccountLightBlacklistAllFiles> |
44 | function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Bluebird<MVideoImmutable> | ||
40 | function fetchVideoByUrl (url: string, fetchType: 'only-video'): Bluebird<MVideoThumbnail> | 45 | function fetchVideoByUrl (url: string, fetchType: 'only-video'): Bluebird<MVideoThumbnail> |
41 | function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail> | 46 | function fetchVideoByUrl ( |
42 | function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail> { | 47 | url: string, |
48 | fetchType: VideoFetchByUrlType | ||
49 | ): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> | ||
50 | function fetchVideoByUrl ( | ||
51 | url: string, | ||
52 | fetchType: VideoFetchByUrlType | ||
53 | ): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> { | ||
43 | if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) | 54 | if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) |
44 | 55 | ||
56 | if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url) | ||
57 | |||
45 | if (fetchType === 'only-video') return VideoModel.loadByUrl(url) | 58 | if (fetchType === 'only-video') return VideoModel.loadByUrl(url) |
46 | } | 59 | } |
47 | 60 | ||