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/videos/imports-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/videos/imports-command.ts')
-rw-r--r-- | shared/server-commands/videos/imports-command.ts | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/shared/server-commands/videos/imports-command.ts b/shared/server-commands/videos/imports-command.ts deleted file mode 100644 index e307a79be..000000000 --- a/shared/server-commands/videos/imports-command.ts +++ /dev/null | |||
@@ -1,77 +0,0 @@ | |||
1 | |||
2 | import { HttpStatusCode, ResultList } from '@shared/models' | ||
3 | import { VideoImport, VideoImportCreate } from '../../models/videos' | ||
4 | import { unwrapBody } from '../requests' | ||
5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
6 | |||
7 | export class ImportsCommand extends AbstractCommand { | ||
8 | |||
9 | importVideo (options: OverrideCommandOptions & { | ||
10 | attributes: (VideoImportCreate | { torrentfile?: string, previewfile?: string, thumbnailfile?: string }) | ||
11 | }) { | ||
12 | const { attributes } = options | ||
13 | const path = '/api/v1/videos/imports' | ||
14 | |||
15 | let attaches: any = {} | ||
16 | if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile } | ||
17 | if (attributes.thumbnailfile) attaches = { thumbnailfile: attributes.thumbnailfile } | ||
18 | if (attributes.previewfile) attaches = { previewfile: attributes.previewfile } | ||
19 | |||
20 | return unwrapBody<VideoImport>(this.postUploadRequest({ | ||
21 | ...options, | ||
22 | |||
23 | path, | ||
24 | attaches, | ||
25 | fields: options.attributes, | ||
26 | implicitToken: true, | ||
27 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
28 | })) | ||
29 | } | ||
30 | |||
31 | delete (options: OverrideCommandOptions & { | ||
32 | importId: number | ||
33 | }) { | ||
34 | const path = '/api/v1/videos/imports/' + options.importId | ||
35 | |||
36 | return this.deleteRequest({ | ||
37 | ...options, | ||
38 | |||
39 | path, | ||
40 | implicitToken: true, | ||
41 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
42 | }) | ||
43 | } | ||
44 | |||
45 | cancel (options: OverrideCommandOptions & { | ||
46 | importId: number | ||
47 | }) { | ||
48 | const path = '/api/v1/videos/imports/' + options.importId + '/cancel' | ||
49 | |||
50 | return this.postBodyRequest({ | ||
51 | ...options, | ||
52 | |||
53 | path, | ||
54 | implicitToken: true, | ||
55 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
56 | }) | ||
57 | } | ||
58 | |||
59 | getMyVideoImports (options: OverrideCommandOptions & { | ||
60 | sort?: string | ||
61 | targetUrl?: string | ||
62 | videoChannelSyncId?: number | ||
63 | search?: string | ||
64 | } = {}) { | ||
65 | const { sort, targetUrl, videoChannelSyncId, search } = options | ||
66 | const path = '/api/v1/users/me/videos/imports' | ||
67 | |||
68 | return this.getRequestBody<ResultList<VideoImport>>({ | ||
69 | ...options, | ||
70 | |||
71 | path, | ||
72 | query: { sort, targetUrl, videoChannelSyncId, search }, | ||
73 | implicitToken: true, | ||
74 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
75 | }) | ||
76 | } | ||
77 | } | ||