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 /packages/models/src/moderation | |
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 'packages/models/src/moderation')
13 files changed, 182 insertions, 0 deletions
diff --git a/packages/models/src/moderation/abuse/abuse-create.model.ts b/packages/models/src/moderation/abuse/abuse-create.model.ts new file mode 100644 index 000000000..1c2723b1c --- /dev/null +++ b/packages/models/src/moderation/abuse/abuse-create.model.ts | |||
@@ -0,0 +1,21 @@ | |||
1 | import { AbusePredefinedReasonsString } from './abuse-reason.model.js' | ||
2 | |||
3 | export interface AbuseCreate { | ||
4 | reason: string | ||
5 | |||
6 | predefinedReasons?: AbusePredefinedReasonsString[] | ||
7 | |||
8 | account?: { | ||
9 | id: number | ||
10 | } | ||
11 | |||
12 | video?: { | ||
13 | id: number | string | ||
14 | startAt?: number | ||
15 | endAt?: number | ||
16 | } | ||
17 | |||
18 | comment?: { | ||
19 | id: number | ||
20 | } | ||
21 | } | ||
diff --git a/packages/models/src/moderation/abuse/abuse-filter.type.ts b/packages/models/src/moderation/abuse/abuse-filter.type.ts new file mode 100644 index 000000000..7dafc6d77 --- /dev/null +++ b/packages/models/src/moderation/abuse/abuse-filter.type.ts | |||
@@ -0,0 +1 @@ | |||
export type AbuseFilter = 'video' | 'comment' | 'account' | |||
diff --git a/packages/models/src/moderation/abuse/abuse-message.model.ts b/packages/models/src/moderation/abuse/abuse-message.model.ts new file mode 100644 index 000000000..9ba95e724 --- /dev/null +++ b/packages/models/src/moderation/abuse/abuse-message.model.ts | |||
@@ -0,0 +1,10 @@ | |||
1 | import { AccountSummary } from '../../actors/account.model.js' | ||
2 | |||
3 | export interface AbuseMessage { | ||
4 | id: number | ||
5 | message: string | ||
6 | byModerator: boolean | ||
7 | createdAt: Date | string | ||
8 | |||
9 | account: AccountSummary | ||
10 | } | ||
diff --git a/packages/models/src/moderation/abuse/abuse-reason.model.ts b/packages/models/src/moderation/abuse/abuse-reason.model.ts new file mode 100644 index 000000000..770b9d47a --- /dev/null +++ b/packages/models/src/moderation/abuse/abuse-reason.model.ts | |||
@@ -0,0 +1,22 @@ | |||
1 | export const AbusePredefinedReasons = { | ||
2 | VIOLENT_OR_REPULSIVE: 1, | ||
3 | HATEFUL_OR_ABUSIVE: 2, | ||
4 | SPAM_OR_MISLEADING: 3, | ||
5 | PRIVACY: 4, | ||
6 | RIGHTS: 5, | ||
7 | SERVER_RULES: 6, | ||
8 | THUMBNAILS: 7, | ||
9 | CAPTIONS: 8 | ||
10 | } as const | ||
11 | |||
12 | export type AbusePredefinedReasonsType = typeof AbusePredefinedReasons[keyof typeof AbusePredefinedReasons] | ||
13 | |||
14 | export type AbusePredefinedReasonsString = | ||
15 | 'violentOrRepulsive' | | ||
16 | 'hatefulOrAbusive' | | ||
17 | 'spamOrMisleading' | | ||
18 | 'privacy' | | ||
19 | 'rights' | | ||
20 | 'serverRules' | | ||
21 | 'thumbnails' | | ||
22 | 'captions' | ||
diff --git a/packages/models/src/moderation/abuse/abuse-state.model.ts b/packages/models/src/moderation/abuse/abuse-state.model.ts new file mode 100644 index 000000000..5582d73c4 --- /dev/null +++ b/packages/models/src/moderation/abuse/abuse-state.model.ts | |||
@@ -0,0 +1,7 @@ | |||
1 | export const AbuseState = { | ||
2 | PENDING: 1, | ||
3 | REJECTED: 2, | ||
4 | ACCEPTED: 3 | ||
5 | } as const | ||
6 | |||
7 | export type AbuseStateType = typeof AbuseState[keyof typeof AbuseState] | ||
diff --git a/packages/models/src/moderation/abuse/abuse-update.model.ts b/packages/models/src/moderation/abuse/abuse-update.model.ts new file mode 100644 index 000000000..22a01be89 --- /dev/null +++ b/packages/models/src/moderation/abuse/abuse-update.model.ts | |||
@@ -0,0 +1,7 @@ | |||
1 | import { AbuseStateType } from './abuse-state.model.js' | ||
2 | |||
3 | export interface AbuseUpdate { | ||
4 | moderationComment?: string | ||
5 | |||
6 | state?: AbuseStateType | ||
7 | } | ||
diff --git a/packages/models/src/moderation/abuse/abuse-video-is.type.ts b/packages/models/src/moderation/abuse/abuse-video-is.type.ts new file mode 100644 index 000000000..74937f3b9 --- /dev/null +++ b/packages/models/src/moderation/abuse/abuse-video-is.type.ts | |||
@@ -0,0 +1 @@ | |||
export type AbuseVideoIs = 'deleted' | 'blacklisted' | |||
diff --git a/packages/models/src/moderation/abuse/abuse.model.ts b/packages/models/src/moderation/abuse/abuse.model.ts new file mode 100644 index 000000000..253a3f44c --- /dev/null +++ b/packages/models/src/moderation/abuse/abuse.model.ts | |||
@@ -0,0 +1,70 @@ | |||
1 | import { Account } from '../../actors/account.model.js' | ||
2 | import { AbuseStateType } from './abuse-state.model.js' | ||
3 | import { AbusePredefinedReasonsString } from './abuse-reason.model.js' | ||
4 | import { VideoConstant } from '../../videos/video-constant.model.js' | ||
5 | import { VideoChannel } from '../../videos/channel/video-channel.model.js' | ||
6 | |||
7 | export interface AdminVideoAbuse { | ||
8 | id: number | ||
9 | name: string | ||
10 | uuid: string | ||
11 | nsfw: boolean | ||
12 | |||
13 | deleted: boolean | ||
14 | blacklisted: boolean | ||
15 | |||
16 | startAt: number | null | ||
17 | endAt: number | null | ||
18 | |||
19 | thumbnailPath?: string | ||
20 | channel?: VideoChannel | ||
21 | |||
22 | countReports: number | ||
23 | nthReport: number | ||
24 | } | ||
25 | |||
26 | export interface AdminVideoCommentAbuse { | ||
27 | id: number | ||
28 | threadId: number | ||
29 | |||
30 | video: { | ||
31 | id: number | ||
32 | name: string | ||
33 | uuid: string | ||
34 | } | ||
35 | |||
36 | text: string | ||
37 | |||
38 | deleted: boolean | ||
39 | } | ||
40 | |||
41 | export interface AdminAbuse { | ||
42 | id: number | ||
43 | |||
44 | reason: string | ||
45 | predefinedReasons?: AbusePredefinedReasonsString[] | ||
46 | |||
47 | reporterAccount: Account | ||
48 | flaggedAccount: Account | ||
49 | |||
50 | state: VideoConstant<AbuseStateType> | ||
51 | moderationComment?: string | ||
52 | |||
53 | video?: AdminVideoAbuse | ||
54 | comment?: AdminVideoCommentAbuse | ||
55 | |||
56 | createdAt: Date | ||
57 | updatedAt: Date | ||
58 | |||
59 | countReportsForReporter?: number | ||
60 | countReportsForReportee?: number | ||
61 | |||
62 | countMessages: number | ||
63 | } | ||
64 | |||
65 | export type UserVideoAbuse = Omit<AdminVideoAbuse, 'countReports' | 'nthReport'> | ||
66 | |||
67 | export type UserVideoCommentAbuse = AdminVideoCommentAbuse | ||
68 | |||
69 | export type UserAbuse = Omit<AdminAbuse, 'reporterAccount' | 'countReportsForReportee' | 'countReportsForReporter' | 'startAt' | 'endAt' | ||
70 | | 'count' | 'nth' | 'moderationComment'> | ||
diff --git a/packages/models/src/moderation/abuse/index.ts b/packages/models/src/moderation/abuse/index.ts new file mode 100644 index 000000000..27fca7076 --- /dev/null +++ b/packages/models/src/moderation/abuse/index.ts | |||
@@ -0,0 +1,8 @@ | |||
1 | export * from './abuse-create.model.js' | ||
2 | export * from './abuse-filter.type.js' | ||
3 | export * from './abuse-message.model.js' | ||
4 | export * from './abuse-reason.model.js' | ||
5 | export * from './abuse-state.model.js' | ||
6 | export * from './abuse-update.model.js' | ||
7 | export * from './abuse-video-is.type.js' | ||
8 | export * from './abuse.model.js' | ||
diff --git a/packages/models/src/moderation/account-block.model.ts b/packages/models/src/moderation/account-block.model.ts new file mode 100644 index 000000000..2d070da62 --- /dev/null +++ b/packages/models/src/moderation/account-block.model.ts | |||
@@ -0,0 +1,7 @@ | |||
1 | import { Account } from '../actors/index.js' | ||
2 | |||
3 | export interface AccountBlock { | ||
4 | byAccount: Account | ||
5 | blockedAccount: Account | ||
6 | createdAt: Date | string | ||
7 | } | ||
diff --git a/packages/models/src/moderation/block-status.model.ts b/packages/models/src/moderation/block-status.model.ts new file mode 100644 index 000000000..597312757 --- /dev/null +++ b/packages/models/src/moderation/block-status.model.ts | |||
@@ -0,0 +1,15 @@ | |||
1 | export interface BlockStatus { | ||
2 | accounts: { | ||
3 | [ handle: string ]: { | ||
4 | blockedByServer: boolean | ||
5 | blockedByUser?: boolean | ||
6 | } | ||
7 | } | ||
8 | |||
9 | hosts: { | ||
10 | [ host: string ]: { | ||
11 | blockedByServer: boolean | ||
12 | blockedByUser?: boolean | ||
13 | } | ||
14 | } | ||
15 | } | ||
diff --git a/packages/models/src/moderation/index.ts b/packages/models/src/moderation/index.ts new file mode 100644 index 000000000..52e21e7b3 --- /dev/null +++ b/packages/models/src/moderation/index.ts | |||
@@ -0,0 +1,4 @@ | |||
1 | export * from './abuse/index.js' | ||
2 | export * from './block-status.model.js' | ||
3 | export * from './account-block.model.js' | ||
4 | export * from './server-block.model.js' | ||
diff --git a/packages/models/src/moderation/server-block.model.ts b/packages/models/src/moderation/server-block.model.ts new file mode 100644 index 000000000..b85646fc6 --- /dev/null +++ b/packages/models/src/moderation/server-block.model.ts | |||
@@ -0,0 +1,9 @@ | |||
1 | import { Account } from '../actors/index.js' | ||
2 | |||
3 | export interface ServerBlock { | ||
4 | byAccount: Account | ||
5 | blockedServer: { | ||
6 | host: string | ||
7 | } | ||
8 | createdAt: Date | string | ||
9 | } | ||