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 /shared/server-commands/users/blocklist-command.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 'shared/server-commands/users/blocklist-command.ts')
-rw-r--r-- | shared/server-commands/users/blocklist-command.ts | 165 |
1 files changed, 0 insertions, 165 deletions
diff --git a/shared/server-commands/users/blocklist-command.ts b/shared/server-commands/users/blocklist-command.ts deleted file mode 100644 index 862d8945e..000000000 --- a/shared/server-commands/users/blocklist-command.ts +++ /dev/null | |||
@@ -1,165 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { AccountBlock, BlockStatus, HttpStatusCode, ResultList, ServerBlock } from '@shared/models' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | type ListBlocklistOptions = OverrideCommandOptions & { | ||
7 | start: number | ||
8 | count: number | ||
9 | |||
10 | sort?: string // default -createdAt | ||
11 | |||
12 | search?: string | ||
13 | } | ||
14 | |||
15 | export class BlocklistCommand extends AbstractCommand { | ||
16 | |||
17 | listMyAccountBlocklist (options: ListBlocklistOptions) { | ||
18 | const path = '/api/v1/users/me/blocklist/accounts' | ||
19 | |||
20 | return this.listBlocklist<AccountBlock>(options, path) | ||
21 | } | ||
22 | |||
23 | listMyServerBlocklist (options: ListBlocklistOptions) { | ||
24 | const path = '/api/v1/users/me/blocklist/servers' | ||
25 | |||
26 | return this.listBlocklist<ServerBlock>(options, path) | ||
27 | } | ||
28 | |||
29 | listServerAccountBlocklist (options: ListBlocklistOptions) { | ||
30 | const path = '/api/v1/server/blocklist/accounts' | ||
31 | |||
32 | return this.listBlocklist<AccountBlock>(options, path) | ||
33 | } | ||
34 | |||
35 | listServerServerBlocklist (options: ListBlocklistOptions) { | ||
36 | const path = '/api/v1/server/blocklist/servers' | ||
37 | |||
38 | return this.listBlocklist<ServerBlock>(options, path) | ||
39 | } | ||
40 | |||
41 | // --------------------------------------------------------------------------- | ||
42 | |||
43 | getStatus (options: OverrideCommandOptions & { | ||
44 | accounts?: string[] | ||
45 | hosts?: string[] | ||
46 | }) { | ||
47 | const { accounts, hosts } = options | ||
48 | |||
49 | const path = '/api/v1/blocklist/status' | ||
50 | |||
51 | return this.getRequestBody<BlockStatus>({ | ||
52 | ...options, | ||
53 | |||
54 | path, | ||
55 | query: { | ||
56 | accounts, | ||
57 | hosts | ||
58 | }, | ||
59 | implicitToken: false, | ||
60 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
61 | }) | ||
62 | } | ||
63 | |||
64 | // --------------------------------------------------------------------------- | ||
65 | |||
66 | addToMyBlocklist (options: OverrideCommandOptions & { | ||
67 | account?: string | ||
68 | server?: string | ||
69 | }) { | ||
70 | const { account, server } = options | ||
71 | |||
72 | const path = account | ||
73 | ? '/api/v1/users/me/blocklist/accounts' | ||
74 | : '/api/v1/users/me/blocklist/servers' | ||
75 | |||
76 | return this.postBodyRequest({ | ||
77 | ...options, | ||
78 | |||
79 | path, | ||
80 | fields: { | ||
81 | accountName: account, | ||
82 | host: server | ||
83 | }, | ||
84 | implicitToken: true, | ||
85 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
86 | }) | ||
87 | } | ||
88 | |||
89 | addToServerBlocklist (options: OverrideCommandOptions & { | ||
90 | account?: string | ||
91 | server?: string | ||
92 | }) { | ||
93 | const { account, server } = options | ||
94 | |||
95 | const path = account | ||
96 | ? '/api/v1/server/blocklist/accounts' | ||
97 | : '/api/v1/server/blocklist/servers' | ||
98 | |||
99 | return this.postBodyRequest({ | ||
100 | ...options, | ||
101 | |||
102 | path, | ||
103 | fields: { | ||
104 | accountName: account, | ||
105 | host: server | ||
106 | }, | ||
107 | implicitToken: true, | ||
108 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
109 | }) | ||
110 | } | ||
111 | |||
112 | // --------------------------------------------------------------------------- | ||
113 | |||
114 | removeFromMyBlocklist (options: OverrideCommandOptions & { | ||
115 | account?: string | ||
116 | server?: string | ||
117 | }) { | ||
118 | const { account, server } = options | ||
119 | |||
120 | const path = account | ||
121 | ? '/api/v1/users/me/blocklist/accounts/' + account | ||
122 | : '/api/v1/users/me/blocklist/servers/' + server | ||
123 | |||
124 | return this.deleteRequest({ | ||
125 | ...options, | ||
126 | |||
127 | path, | ||
128 | implicitToken: true, | ||
129 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
130 | }) | ||
131 | } | ||
132 | |||
133 | removeFromServerBlocklist (options: OverrideCommandOptions & { | ||
134 | account?: string | ||
135 | server?: string | ||
136 | }) { | ||
137 | const { account, server } = options | ||
138 | |||
139 | const path = account | ||
140 | ? '/api/v1/server/blocklist/accounts/' + account | ||
141 | : '/api/v1/server/blocklist/servers/' + server | ||
142 | |||
143 | return this.deleteRequest({ | ||
144 | ...options, | ||
145 | |||
146 | path, | ||
147 | implicitToken: true, | ||
148 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
149 | }) | ||
150 | } | ||
151 | |||
152 | private listBlocklist <T> (options: ListBlocklistOptions, path: string) { | ||
153 | const { start, count, search, sort = '-createdAt' } = options | ||
154 | |||
155 | return this.getRequestBody<ResultList<T>>({ | ||
156 | ...options, | ||
157 | |||
158 | path, | ||
159 | query: { start, count, sort, search }, | ||
160 | implicitToken: true, | ||
161 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
162 | }) | ||
163 | } | ||
164 | |||
165 | } | ||