aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/url.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-31 14:34:36 +0200
committerChocobozzz <me@florianbigard.com>2023-08-11 15:02:33 +0200
commit3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch)
treee4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/lib/activitypub/url.ts
parent04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff)
downloadPeerTube-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/url.ts')
-rw-r--r--server/lib/activitypub/url.ts177
1 files changed, 0 insertions, 177 deletions
diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts
deleted file mode 100644
index 5cdac71bf..000000000
--- a/server/lib/activitypub/url.ts
+++ /dev/null
@@ -1,177 +0,0 @@
1import { REMOTE_SCHEME, WEBSERVER } from '../../initializers/constants'
2import {
3 MAbuseFull,
4 MAbuseId,
5 MActor,
6 MActorFollow,
7 MActorId,
8 MActorUrl,
9 MCommentId,
10 MLocalVideoViewer,
11 MVideoId,
12 MVideoPlaylistElement,
13 MVideoUrl,
14 MVideoUUID,
15 MVideoWithHost
16} from '../../types/models'
17import { MVideoFileVideoUUID } from '../../types/models/video/video-file'
18import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist'
19import { MStreamingPlaylist } from '../../types/models/video/video-streaming-playlist'
20
21function getLocalVideoActivityPubUrl (video: MVideoUUID) {
22 return WEBSERVER.URL + '/videos/watch/' + video.uuid
23}
24
25function getLocalVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) {
26 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid
27}
28
29function getLocalVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) {
30 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id
31}
32
33function getLocalVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) {
34 const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : ''
35
36 return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}`
37}
38
39function getLocalVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) {
40 return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}`
41}
42
43function getLocalVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) {
44 return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
45}
46
47function getLocalVideoChannelActivityPubUrl (videoChannelName: string) {
48 return WEBSERVER.URL + '/video-channels/' + videoChannelName
49}
50
51function getLocalAccountActivityPubUrl (accountName: string) {
52 return WEBSERVER.URL + '/accounts/' + accountName
53}
54
55function getLocalAbuseActivityPubUrl (abuse: MAbuseId) {
56 return WEBSERVER.URL + '/admin/abuses/' + abuse.id
57}
58
59function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId, viewerIdentifier: string) {
60 return byActor.url + '/views/videos/' + video.id + '/' + viewerIdentifier
61}
62
63function getLocalVideoViewerActivityPubUrl (stats: MLocalVideoViewer) {
64 return WEBSERVER.URL + '/videos/local-viewer/' + stats.uuid
65}
66
67function getVideoLikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
68 return byActor.url + '/likes/' + video.id
69}
70
71function getVideoDislikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
72 return byActor.url + '/dislikes/' + video.id
73}
74
75function getLocalVideoSharesActivityPubUrl (video: MVideoUrl) {
76 return video.url + '/announces'
77}
78
79function getLocalVideoCommentsActivityPubUrl (video: MVideoUrl) {
80 return video.url + '/comments'
81}
82
83function getLocalVideoLikesActivityPubUrl (video: MVideoUrl) {
84 return video.url + '/likes'
85}
86
87function getLocalVideoDislikesActivityPubUrl (video: MVideoUrl) {
88 return video.url + '/dislikes'
89}
90
91function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorId) {
92 return follower.url + '/follows/' + following.id
93}
94
95function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollow) {
96 return WEBSERVER.URL + '/accepts/follows/' + actorFollow.id
97}
98
99function getLocalActorFollowRejectActivityPubUrl () {
100 return WEBSERVER.URL + '/rejects/follows/' + new Date().toISOString()
101}
102
103function getLocalVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) {
104 return video.url + '/announces/' + byActor.id
105}
106
107function getDeleteActivityPubUrl (originalUrl: string) {
108 return originalUrl + '/delete'
109}
110
111function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
112 return originalUrl + '/updates/' + updatedAt
113}
114
115function getUndoActivityPubUrl (originalUrl: string) {
116 return originalUrl + '/undo'
117}
118
119// ---------------------------------------------------------------------------
120
121function getAbuseTargetUrl (abuse: MAbuseFull) {
122 return abuse.VideoAbuse?.Video?.url ||
123 abuse.VideoCommentAbuse?.VideoComment?.url ||
124 abuse.FlaggedAccount.Actor.url
125}
126
127// ---------------------------------------------------------------------------
128
129function buildRemoteVideoBaseUrl (video: MVideoWithHost, path: string, scheme?: string) {
130 if (!scheme) scheme = REMOTE_SCHEME.HTTP
131
132 const host = video.VideoChannel.Actor.Server.host
133
134 return scheme + '://' + host + path
135}
136
137// ---------------------------------------------------------------------------
138
139function checkUrlsSameHost (url1: string, url2: string) {
140 const idHost = new URL(url1).host
141 const actorHost = new URL(url2).host
142
143 return idHost && actorHost && idHost.toLowerCase() === actorHost.toLowerCase()
144}
145
146// ---------------------------------------------------------------------------
147
148export {
149 getLocalVideoActivityPubUrl,
150 getLocalVideoPlaylistActivityPubUrl,
151 getLocalVideoPlaylistElementActivityPubUrl,
152 getLocalVideoCacheFileActivityPubUrl,
153 getLocalVideoCacheStreamingPlaylistActivityPubUrl,
154 getLocalVideoCommentActivityPubUrl,
155 getLocalVideoChannelActivityPubUrl,
156 getLocalAccountActivityPubUrl,
157 getLocalAbuseActivityPubUrl,
158 getLocalActorFollowActivityPubUrl,
159 getLocalActorFollowAcceptActivityPubUrl,
160 getLocalVideoAnnounceActivityPubUrl,
161 getUpdateActivityPubUrl,
162 getUndoActivityPubUrl,
163 getVideoLikeActivityPubUrlByLocalActor,
164 getLocalVideoViewActivityPubUrl,
165 getVideoDislikeActivityPubUrlByLocalActor,
166 getLocalActorFollowRejectActivityPubUrl,
167 getDeleteActivityPubUrl,
168 getLocalVideoSharesActivityPubUrl,
169 getLocalVideoCommentsActivityPubUrl,
170 getLocalVideoLikesActivityPubUrl,
171 getLocalVideoDislikesActivityPubUrl,
172 getLocalVideoViewerActivityPubUrl,
173
174 getAbuseTargetUrl,
175 checkUrlsSameHost,
176 buildRemoteVideoBaseUrl
177}