diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/lib/activitypub/context.ts | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip |
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge
conflicts, but it's a major step forward:
* Server can be faster at startup because imports() are async and we can
easily lazy import big modules
* Angular doesn't seem to support ES import (with .js extension), so we
had to correctly organize peertube into a monorepo:
* Use yarn workspace feature
* Use typescript reference projects for dependencies
* Shared projects have been moved into "packages", each one is now a
node module (with a dedicated package.json/tsconfig.json)
* server/tools have been moved into apps/ and is now a dedicated app
bundled and published on NPM so users don't have to build peertube
cli tools manually
* server/tests have been moved into packages/ so we don't compile
them every time we want to run the server
* Use isolatedModule option:
* Had to move from const enum to const
(https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)
* Had to explictely specify "type" imports when used in decorators
* Prefer tsx (that uses esbuild under the hood) instead of ts-node to
load typescript files (tests with mocha or scripts):
* To reduce test complexity as esbuild doesn't support decorator
metadata, we only test server files that do not import server
models
* We still build tests files into js files for a faster CI
* Remove unmaintained peertube CLI import script
* Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/lib/activitypub/context.ts')
-rw-r--r-- | server/lib/activitypub/context.ts | 212 |
1 files changed, 0 insertions, 212 deletions
diff --git a/server/lib/activitypub/context.ts b/server/lib/activitypub/context.ts deleted file mode 100644 index 87eb498a3..000000000 --- a/server/lib/activitypub/context.ts +++ /dev/null | |||
@@ -1,212 +0,0 @@ | |||
1 | import { ContextType } from '@shared/models' | ||
2 | import { Hooks } from '../plugins/hooks' | ||
3 | |||
4 | async function activityPubContextify <T> (data: T, type: ContextType) { | ||
5 | return { ...await getContextData(type), ...data } | ||
6 | } | ||
7 | |||
8 | // --------------------------------------------------------------------------- | ||
9 | |||
10 | export { | ||
11 | getContextData, | ||
12 | activityPubContextify | ||
13 | } | ||
14 | |||
15 | // --------------------------------------------------------------------------- | ||
16 | |||
17 | type ContextValue = { [ id: string ]: (string | { '@type': string, '@id': string }) } | ||
18 | |||
19 | const contextStore: { [ id in ContextType ]: (string | { [ id: string ]: string })[] } = { | ||
20 | Video: buildContext({ | ||
21 | Hashtag: 'as:Hashtag', | ||
22 | uuid: 'sc:identifier', | ||
23 | category: 'sc:category', | ||
24 | licence: 'sc:license', | ||
25 | subtitleLanguage: 'sc:subtitleLanguage', | ||
26 | sensitive: 'as:sensitive', | ||
27 | language: 'sc:inLanguage', | ||
28 | identifier: 'sc:identifier', | ||
29 | |||
30 | isLiveBroadcast: 'sc:isLiveBroadcast', | ||
31 | liveSaveReplay: { | ||
32 | '@type': 'sc:Boolean', | ||
33 | '@id': 'pt:liveSaveReplay' | ||
34 | }, | ||
35 | permanentLive: { | ||
36 | '@type': 'sc:Boolean', | ||
37 | '@id': 'pt:permanentLive' | ||
38 | }, | ||
39 | latencyMode: { | ||
40 | '@type': 'sc:Number', | ||
41 | '@id': 'pt:latencyMode' | ||
42 | }, | ||
43 | |||
44 | Infohash: 'pt:Infohash', | ||
45 | |||
46 | tileWidth: { | ||
47 | '@type': 'sc:Number', | ||
48 | '@id': 'pt:tileWidth' | ||
49 | }, | ||
50 | tileHeight: { | ||
51 | '@type': 'sc:Number', | ||
52 | '@id': 'pt:tileHeight' | ||
53 | }, | ||
54 | tileDuration: { | ||
55 | '@type': 'sc:Number', | ||
56 | '@id': 'pt:tileDuration' | ||
57 | }, | ||
58 | |||
59 | originallyPublishedAt: 'sc:datePublished', | ||
60 | |||
61 | uploadDate: 'sc:uploadDate', | ||
62 | |||
63 | views: { | ||
64 | '@type': 'sc:Number', | ||
65 | '@id': 'pt:views' | ||
66 | }, | ||
67 | state: { | ||
68 | '@type': 'sc:Number', | ||
69 | '@id': 'pt:state' | ||
70 | }, | ||
71 | size: { | ||
72 | '@type': 'sc:Number', | ||
73 | '@id': 'pt:size' | ||
74 | }, | ||
75 | fps: { | ||
76 | '@type': 'sc:Number', | ||
77 | '@id': 'pt:fps' | ||
78 | }, | ||
79 | commentsEnabled: { | ||
80 | '@type': 'sc:Boolean', | ||
81 | '@id': 'pt:commentsEnabled' | ||
82 | }, | ||
83 | downloadEnabled: { | ||
84 | '@type': 'sc:Boolean', | ||
85 | '@id': 'pt:downloadEnabled' | ||
86 | }, | ||
87 | waitTranscoding: { | ||
88 | '@type': 'sc:Boolean', | ||
89 | '@id': 'pt:waitTranscoding' | ||
90 | }, | ||
91 | support: { | ||
92 | '@type': 'sc:Text', | ||
93 | '@id': 'pt:support' | ||
94 | }, | ||
95 | likes: { | ||
96 | '@id': 'as:likes', | ||
97 | '@type': '@id' | ||
98 | }, | ||
99 | dislikes: { | ||
100 | '@id': 'as:dislikes', | ||
101 | '@type': '@id' | ||
102 | }, | ||
103 | shares: { | ||
104 | '@id': 'as:shares', | ||
105 | '@type': '@id' | ||
106 | }, | ||
107 | comments: { | ||
108 | '@id': 'as:comments', | ||
109 | '@type': '@id' | ||
110 | } | ||
111 | }), | ||
112 | |||
113 | Playlist: buildContext({ | ||
114 | Playlist: 'pt:Playlist', | ||
115 | PlaylistElement: 'pt:PlaylistElement', | ||
116 | position: { | ||
117 | '@type': 'sc:Number', | ||
118 | '@id': 'pt:position' | ||
119 | }, | ||
120 | startTimestamp: { | ||
121 | '@type': 'sc:Number', | ||
122 | '@id': 'pt:startTimestamp' | ||
123 | }, | ||
124 | stopTimestamp: { | ||
125 | '@type': 'sc:Number', | ||
126 | '@id': 'pt:stopTimestamp' | ||
127 | }, | ||
128 | uuid: 'sc:identifier' | ||
129 | }), | ||
130 | |||
131 | CacheFile: buildContext({ | ||
132 | expires: 'sc:expires', | ||
133 | CacheFile: 'pt:CacheFile' | ||
134 | }), | ||
135 | |||
136 | Flag: buildContext({ | ||
137 | Hashtag: 'as:Hashtag' | ||
138 | }), | ||
139 | |||
140 | Actor: buildContext({ | ||
141 | playlists: { | ||
142 | '@id': 'pt:playlists', | ||
143 | '@type': '@id' | ||
144 | }, | ||
145 | support: { | ||
146 | '@type': 'sc:Text', | ||
147 | '@id': 'pt:support' | ||
148 | }, | ||
149 | |||
150 | // TODO: remove in a few versions, introduced in 4.2 | ||
151 | icons: 'as:icon' | ||
152 | }), | ||
153 | |||
154 | WatchAction: buildContext({ | ||
155 | WatchAction: 'sc:WatchAction', | ||
156 | startTimestamp: { | ||
157 | '@type': 'sc:Number', | ||
158 | '@id': 'pt:startTimestamp' | ||
159 | }, | ||
160 | stopTimestamp: { | ||
161 | '@type': 'sc:Number', | ||
162 | '@id': 'pt:stopTimestamp' | ||
163 | }, | ||
164 | watchSection: { | ||
165 | '@type': 'sc:Number', | ||
166 | '@id': 'pt:stopTimestamp' | ||
167 | }, | ||
168 | uuid: 'sc:identifier' | ||
169 | }), | ||
170 | |||
171 | Collection: buildContext(), | ||
172 | Follow: buildContext(), | ||
173 | Reject: buildContext(), | ||
174 | Accept: buildContext(), | ||
175 | View: buildContext(), | ||
176 | Announce: buildContext(), | ||
177 | Comment: buildContext(), | ||
178 | Delete: buildContext(), | ||
179 | Rate: buildContext() | ||
180 | } | ||
181 | |||
182 | async function getContextData (type: ContextType) { | ||
183 | const contextData = await Hooks.wrapObject( | ||
184 | contextStore[type], | ||
185 | 'filter:activity-pub.activity.context.build.result' | ||
186 | ) | ||
187 | |||
188 | return { '@context': contextData } | ||
189 | } | ||
190 | |||
191 | function buildContext (contextValue?: ContextValue) { | ||
192 | const baseContext = [ | ||
193 | 'https://www.w3.org/ns/activitystreams', | ||
194 | 'https://w3id.org/security/v1', | ||
195 | { | ||
196 | RsaSignature2017: 'https://w3id.org/security#RsaSignature2017' | ||
197 | } | ||
198 | ] | ||
199 | |||
200 | if (!contextValue) return baseContext | ||
201 | |||
202 | return [ | ||
203 | ...baseContext, | ||
204 | |||
205 | { | ||
206 | pt: 'https://joinpeertube.org/ns#', | ||
207 | sc: 'http://schema.org/', | ||
208 | |||
209 | ...contextValue | ||
210 | } | ||
211 | ] | ||
212 | } | ||