aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/models/src/users
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 /packages/models/src/users
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 'packages/models/src/users')
-rw-r--r--packages/models/src/users/index.ts16
-rw-r--r--packages/models/src/users/registration/index.ts5
-rw-r--r--packages/models/src/users/registration/user-register.model.ts12
-rw-r--r--packages/models/src/users/registration/user-registration-request.model.ts5
-rw-r--r--packages/models/src/users/registration/user-registration-state.model.ts7
-rw-r--r--packages/models/src/users/registration/user-registration-update-state.model.ts4
-rw-r--r--packages/models/src/users/registration/user-registration.model.ts29
-rw-r--r--packages/models/src/users/two-factor-enable-result.model.ts7
-rw-r--r--packages/models/src/users/user-create-result.model.ts7
-rw-r--r--packages/models/src/users/user-create.model.ts13
-rw-r--r--packages/models/src/users/user-flag.model.ts6
-rw-r--r--packages/models/src/users/user-login.model.ts5
-rw-r--r--packages/models/src/users/user-notification-setting.model.ts34
-rw-r--r--packages/models/src/users/user-notification.model.ts140
-rw-r--r--packages/models/src/users/user-refresh-token.model.ts4
-rw-r--r--packages/models/src/users/user-right.enum.ts53
-rw-r--r--packages/models/src/users/user-role.ts8
-rw-r--r--packages/models/src/users/user-scoped-token.ts5
-rw-r--r--packages/models/src/users/user-update-me.model.ts26
-rw-r--r--packages/models/src/users/user-update.model.ts13
-rw-r--r--packages/models/src/users/user-video-quota.model.ts4
-rw-r--r--packages/models/src/users/user.model.ts78
22 files changed, 481 insertions, 0 deletions
diff --git a/packages/models/src/users/index.ts b/packages/models/src/users/index.ts
new file mode 100644
index 000000000..6f5218234
--- /dev/null
+++ b/packages/models/src/users/index.ts
@@ -0,0 +1,16 @@
1export * from './registration/index.js'
2export * from './two-factor-enable-result.model.js'
3export * from './user-create-result.model.js'
4export * from './user-create.model.js'
5export * from './user-flag.model.js'
6export * from './user-login.model.js'
7export * from './user-notification-setting.model.js'
8export * from './user-notification.model.js'
9export * from './user-refresh-token.model.js'
10export * from './user-right.enum.js'
11export * from './user-role.js'
12export * from './user-scoped-token.js'
13export * from './user-update-me.model.js'
14export * from './user-update.model.js'
15export * from './user-video-quota.model.js'
16export * from './user.model.js'
diff --git a/packages/models/src/users/registration/index.ts b/packages/models/src/users/registration/index.ts
new file mode 100644
index 000000000..dcf16ef9d
--- /dev/null
+++ b/packages/models/src/users/registration/index.ts
@@ -0,0 +1,5 @@
1export * from './user-register.model.js'
2export * from './user-registration-request.model.js'
3export * from './user-registration-state.model.js'
4export * from './user-registration-update-state.model.js'
5export * from './user-registration.model.js'
diff --git a/packages/models/src/users/registration/user-register.model.ts b/packages/models/src/users/registration/user-register.model.ts
new file mode 100644
index 000000000..cf9a43a67
--- /dev/null
+++ b/packages/models/src/users/registration/user-register.model.ts
@@ -0,0 +1,12 @@
1export interface UserRegister {
2 username: string
3 password: string
4 email: string
5
6 displayName?: string
7
8 channel?: {
9 name: string
10 displayName: string
11 }
12}
diff --git a/packages/models/src/users/registration/user-registration-request.model.ts b/packages/models/src/users/registration/user-registration-request.model.ts
new file mode 100644
index 000000000..ed369f96a
--- /dev/null
+++ b/packages/models/src/users/registration/user-registration-request.model.ts
@@ -0,0 +1,5 @@
1import { UserRegister } from './user-register.model.js'
2
3export interface UserRegistrationRequest extends UserRegister {
4 registrationReason: string
5}
diff --git a/packages/models/src/users/registration/user-registration-state.model.ts b/packages/models/src/users/registration/user-registration-state.model.ts
new file mode 100644
index 000000000..7c51f3f9d
--- /dev/null
+++ b/packages/models/src/users/registration/user-registration-state.model.ts
@@ -0,0 +1,7 @@
1export const UserRegistrationState = {
2 PENDING: 1,
3 REJECTED: 2,
4 ACCEPTED: 3
5}
6
7export type UserRegistrationStateType = typeof UserRegistrationState[keyof typeof UserRegistrationState]
diff --git a/packages/models/src/users/registration/user-registration-update-state.model.ts b/packages/models/src/users/registration/user-registration-update-state.model.ts
new file mode 100644
index 000000000..a1740dcca
--- /dev/null
+++ b/packages/models/src/users/registration/user-registration-update-state.model.ts
@@ -0,0 +1,4 @@
1export interface UserRegistrationUpdateState {
2 moderationResponse: string
3 preventEmailDelivery?: boolean
4}
diff --git a/packages/models/src/users/registration/user-registration.model.ts b/packages/models/src/users/registration/user-registration.model.ts
new file mode 100644
index 000000000..0d01add36
--- /dev/null
+++ b/packages/models/src/users/registration/user-registration.model.ts
@@ -0,0 +1,29 @@
1import { UserRegistrationStateType } from './user-registration-state.model.js'
2
3export interface UserRegistration {
4 id: number
5
6 state: {
7 id: UserRegistrationStateType
8 label: string
9 }
10
11 registrationReason: string
12 moderationResponse: string
13
14 username: string
15 email: string
16 emailVerified: boolean
17
18 accountDisplayName: string
19
20 channelHandle: string
21 channelDisplayName: string
22
23 createdAt: Date
24 updatedAt: Date
25
26 user?: {
27 id: number
28 }
29}
diff --git a/packages/models/src/users/two-factor-enable-result.model.ts b/packages/models/src/users/two-factor-enable-result.model.ts
new file mode 100644
index 000000000..1fc801f0a
--- /dev/null
+++ b/packages/models/src/users/two-factor-enable-result.model.ts
@@ -0,0 +1,7 @@
1export interface TwoFactorEnableResult {
2 otpRequest: {
3 requestToken: string
4 secret: string
5 uri: string
6 }
7}
diff --git a/packages/models/src/users/user-create-result.model.ts b/packages/models/src/users/user-create-result.model.ts
new file mode 100644
index 000000000..835b241ed
--- /dev/null
+++ b/packages/models/src/users/user-create-result.model.ts
@@ -0,0 +1,7 @@
1export interface UserCreateResult {
2 id: number
3
4 account: {
5 id: number
6 }
7}
diff --git a/packages/models/src/users/user-create.model.ts b/packages/models/src/users/user-create.model.ts
new file mode 100644
index 000000000..b62cf692f
--- /dev/null
+++ b/packages/models/src/users/user-create.model.ts
@@ -0,0 +1,13 @@
1import { UserAdminFlagType } from './user-flag.model.js'
2import { UserRoleType } from './user-role.js'
3
4export interface UserCreate {
5 username: string
6 password: string
7 email: string
8 videoQuota: number
9 videoQuotaDaily: number
10 role: UserRoleType
11 adminFlags?: UserAdminFlagType
12 channelName?: string
13}
diff --git a/packages/models/src/users/user-flag.model.ts b/packages/models/src/users/user-flag.model.ts
new file mode 100644
index 000000000..0ecbacecc
--- /dev/null
+++ b/packages/models/src/users/user-flag.model.ts
@@ -0,0 +1,6 @@
1export const UserAdminFlag = {
2 NONE: 0,
3 BYPASS_VIDEO_AUTO_BLACKLIST: 1 << 0
4} as const
5
6export type UserAdminFlagType = typeof UserAdminFlag[keyof typeof UserAdminFlag]
diff --git a/packages/models/src/users/user-login.model.ts b/packages/models/src/users/user-login.model.ts
new file mode 100644
index 000000000..1e85ab30b
--- /dev/null
+++ b/packages/models/src/users/user-login.model.ts
@@ -0,0 +1,5 @@
1export interface UserLogin {
2 access_token: string
3 refresh_token: string
4 token_type: string
5}
diff --git a/packages/models/src/users/user-notification-setting.model.ts b/packages/models/src/users/user-notification-setting.model.ts
new file mode 100644
index 000000000..fbd94994e
--- /dev/null
+++ b/packages/models/src/users/user-notification-setting.model.ts
@@ -0,0 +1,34 @@
1export const UserNotificationSettingValue = {
2 NONE: 0,
3 WEB: 1 << 0,
4 EMAIL: 1 << 1
5} as const
6
7export type UserNotificationSettingValueType = typeof UserNotificationSettingValue[keyof typeof UserNotificationSettingValue]
8
9export interface UserNotificationSetting {
10 abuseAsModerator: UserNotificationSettingValueType
11 videoAutoBlacklistAsModerator: UserNotificationSettingValueType
12 newUserRegistration: UserNotificationSettingValueType
13
14 newVideoFromSubscription: UserNotificationSettingValueType
15
16 blacklistOnMyVideo: UserNotificationSettingValueType
17 myVideoPublished: UserNotificationSettingValueType
18 myVideoImportFinished: UserNotificationSettingValueType
19
20 commentMention: UserNotificationSettingValueType
21 newCommentOnMyVideo: UserNotificationSettingValueType
22
23 newFollow: UserNotificationSettingValueType
24 newInstanceFollower: UserNotificationSettingValueType
25 autoInstanceFollowing: UserNotificationSettingValueType
26
27 abuseStateChange: UserNotificationSettingValueType
28 abuseNewMessage: UserNotificationSettingValueType
29
30 newPeerTubeVersion: UserNotificationSettingValueType
31 newPluginVersion: UserNotificationSettingValueType
32
33 myVideoStudioEditionFinished: UserNotificationSettingValueType
34}
diff --git a/packages/models/src/users/user-notification.model.ts b/packages/models/src/users/user-notification.model.ts
new file mode 100644
index 000000000..991fe6728
--- /dev/null
+++ b/packages/models/src/users/user-notification.model.ts
@@ -0,0 +1,140 @@
1import { FollowState } from '../actors/index.js'
2import { AbuseStateType } from '../moderation/index.js'
3import { PluginType_Type } from '../plugins/index.js'
4
5export const UserNotificationType = {
6 NEW_VIDEO_FROM_SUBSCRIPTION: 1,
7 NEW_COMMENT_ON_MY_VIDEO: 2,
8 NEW_ABUSE_FOR_MODERATORS: 3,
9
10 BLACKLIST_ON_MY_VIDEO: 4,
11 UNBLACKLIST_ON_MY_VIDEO: 5,
12
13 MY_VIDEO_PUBLISHED: 6,
14
15 MY_VIDEO_IMPORT_SUCCESS: 7,
16 MY_VIDEO_IMPORT_ERROR: 8,
17
18 NEW_USER_REGISTRATION: 9,
19 NEW_FOLLOW: 10,
20 COMMENT_MENTION: 11,
21
22 VIDEO_AUTO_BLACKLIST_FOR_MODERATORS: 12,
23
24 NEW_INSTANCE_FOLLOWER: 13,
25
26 AUTO_INSTANCE_FOLLOWING: 14,
27
28 ABUSE_STATE_CHANGE: 15,
29
30 ABUSE_NEW_MESSAGE: 16,
31
32 NEW_PLUGIN_VERSION: 17,
33 NEW_PEERTUBE_VERSION: 18,
34
35 MY_VIDEO_STUDIO_EDITION_FINISHED: 19,
36
37 NEW_USER_REGISTRATION_REQUEST: 20
38} as const
39
40export type UserNotificationType_Type = typeof UserNotificationType[keyof typeof UserNotificationType]
41
42export interface VideoInfo {
43 id: number
44 uuid: string
45 shortUUID: string
46 name: string
47}
48
49export interface AvatarInfo {
50 width: number
51 path: string
52}
53
54export interface ActorInfo {
55 id: number
56 displayName: string
57 name: string
58 host: string
59
60 avatars: AvatarInfo[]
61 avatar: AvatarInfo
62}
63
64export interface UserNotification {
65 id: number
66 type: UserNotificationType_Type
67 read: boolean
68
69 video?: VideoInfo & {
70 channel: ActorInfo
71 }
72
73 videoImport?: {
74 id: number
75 video?: VideoInfo
76 torrentName?: string
77 magnetUri?: string
78 targetUrl?: string
79 }
80
81 comment?: {
82 id: number
83 threadId: number
84 account: ActorInfo
85 video: VideoInfo
86 }
87
88 abuse?: {
89 id: number
90 state: AbuseStateType
91
92 video?: VideoInfo
93
94 comment?: {
95 threadId: number
96
97 video: VideoInfo
98 }
99
100 account?: ActorInfo
101 }
102
103 videoBlacklist?: {
104 id: number
105 video: VideoInfo
106 }
107
108 account?: ActorInfo
109
110 actorFollow?: {
111 id: number
112 follower: ActorInfo
113 state: FollowState
114
115 following: {
116 type: 'account' | 'channel' | 'instance'
117 name: string
118 displayName: string
119 host: string
120 }
121 }
122
123 plugin?: {
124 name: string
125 type: PluginType_Type
126 latestVersion: string
127 }
128
129 peertube?: {
130 latestVersion: string
131 }
132
133 registration?: {
134 id: number
135 username: string
136 }
137
138 createdAt: string
139 updatedAt: string
140}
diff --git a/packages/models/src/users/user-refresh-token.model.ts b/packages/models/src/users/user-refresh-token.model.ts
new file mode 100644
index 000000000..f528dd961
--- /dev/null
+++ b/packages/models/src/users/user-refresh-token.model.ts
@@ -0,0 +1,4 @@
1export interface UserRefreshToken {
2 access_token: string
3 refresh_token: string
4}
diff --git a/packages/models/src/users/user-right.enum.ts b/packages/models/src/users/user-right.enum.ts
new file mode 100644
index 000000000..534b9feb0
--- /dev/null
+++ b/packages/models/src/users/user-right.enum.ts
@@ -0,0 +1,53 @@
1export const UserRight = {
2 ALL: 0,
3
4 MANAGE_USERS: 1,
5
6 MANAGE_SERVER_FOLLOW: 2,
7
8 MANAGE_LOGS: 3,
9
10 MANAGE_DEBUG: 4,
11
12 MANAGE_SERVER_REDUNDANCY: 5,
13
14 MANAGE_ABUSES: 6,
15
16 MANAGE_JOBS: 7,
17
18 MANAGE_CONFIGURATION: 8,
19 MANAGE_INSTANCE_CUSTOM_PAGE: 9,
20
21 MANAGE_ACCOUNTS_BLOCKLIST: 10,
22 MANAGE_SERVERS_BLOCKLIST: 11,
23
24 MANAGE_VIDEO_BLACKLIST: 12,
25 MANAGE_ANY_VIDEO_CHANNEL: 13,
26
27 REMOVE_ANY_VIDEO: 14,
28 REMOVE_ANY_VIDEO_PLAYLIST: 15,
29 REMOVE_ANY_VIDEO_COMMENT: 16,
30
31 UPDATE_ANY_VIDEO: 17,
32 UPDATE_ANY_VIDEO_PLAYLIST: 18,
33
34 GET_ANY_LIVE: 19,
35 SEE_ALL_VIDEOS: 20,
36 SEE_ALL_COMMENTS: 21,
37 CHANGE_VIDEO_OWNERSHIP: 22,
38
39 MANAGE_PLUGINS: 23,
40
41 MANAGE_VIDEOS_REDUNDANCIES: 24,
42
43 MANAGE_VIDEO_FILES: 25,
44 RUN_VIDEO_TRANSCODING: 26,
45
46 MANAGE_VIDEO_IMPORTS: 27,
47
48 MANAGE_REGISTRATIONS: 28,
49
50 MANAGE_RUNNERS: 29
51} as const
52
53export type UserRightType = typeof UserRight[keyof typeof UserRight]
diff --git a/packages/models/src/users/user-role.ts b/packages/models/src/users/user-role.ts
new file mode 100644
index 000000000..b496f8153
--- /dev/null
+++ b/packages/models/src/users/user-role.ts
@@ -0,0 +1,8 @@
1// Always keep this order to prevent security issue since we store these values in the database
2export const UserRole = {
3 ADMINISTRATOR: 0,
4 MODERATOR: 1,
5 USER: 2
6} as const
7
8export type UserRoleType = typeof UserRole[keyof typeof UserRole]
diff --git a/packages/models/src/users/user-scoped-token.ts b/packages/models/src/users/user-scoped-token.ts
new file mode 100644
index 000000000..f9d9b0a8b
--- /dev/null
+++ b/packages/models/src/users/user-scoped-token.ts
@@ -0,0 +1,5 @@
1export type ScopedTokenType = 'feedToken'
2
3export type ScopedToken = {
4 feedToken: string
5}
diff --git a/packages/models/src/users/user-update-me.model.ts b/packages/models/src/users/user-update-me.model.ts
new file mode 100644
index 000000000..ba9672136
--- /dev/null
+++ b/packages/models/src/users/user-update-me.model.ts
@@ -0,0 +1,26 @@
1import { NSFWPolicyType } from '../videos/nsfw-policy.type.js'
2
3export interface UserUpdateMe {
4 displayName?: string
5 description?: string
6 nsfwPolicy?: NSFWPolicyType
7
8 p2pEnabled?: boolean
9
10 autoPlayVideo?: boolean
11 autoPlayNextVideo?: boolean
12 autoPlayNextVideoPlaylist?: boolean
13 videosHistoryEnabled?: boolean
14 videoLanguages?: string[]
15
16 email?: string
17 emailPublic?: boolean
18 currentPassword?: string
19 password?: string
20
21 theme?: string
22
23 noInstanceConfigWarningModal?: boolean
24 noWelcomeModal?: boolean
25 noAccountSetupWarningModal?: boolean
26}
diff --git a/packages/models/src/users/user-update.model.ts b/packages/models/src/users/user-update.model.ts
new file mode 100644
index 000000000..283255629
--- /dev/null
+++ b/packages/models/src/users/user-update.model.ts
@@ -0,0 +1,13 @@
1import { UserAdminFlagType } from './user-flag.model.js'
2import { UserRoleType } from './user-role.js'
3
4export interface UserUpdate {
5 password?: string
6 email?: string
7 emailVerified?: boolean
8 videoQuota?: number
9 videoQuotaDaily?: number
10 role?: UserRoleType
11 adminFlags?: UserAdminFlagType
12 pluginAuth?: string
13}
diff --git a/packages/models/src/users/user-video-quota.model.ts b/packages/models/src/users/user-video-quota.model.ts
new file mode 100644
index 000000000..a24871d71
--- /dev/null
+++ b/packages/models/src/users/user-video-quota.model.ts
@@ -0,0 +1,4 @@
1export interface UserVideoQuota {
2 videoQuotaUsed: number
3 videoQuotaUsedDaily: number
4}
diff --git a/packages/models/src/users/user.model.ts b/packages/models/src/users/user.model.ts
new file mode 100644
index 000000000..57b4c1aab
--- /dev/null
+++ b/packages/models/src/users/user.model.ts
@@ -0,0 +1,78 @@
1import { Account } from '../actors/index.js'
2import { VideoChannel } from '../videos/channel/video-channel.model.js'
3import { NSFWPolicyType } from '../videos/nsfw-policy.type.js'
4import { VideoPlaylistType_Type } from '../videos/playlist/video-playlist-type.model.js'
5import { UserAdminFlagType } from './user-flag.model.js'
6import { UserNotificationSetting } from './user-notification-setting.model.js'
7import { UserRoleType } from './user-role.js'
8
9export interface User {
10 id: number
11 username: string
12 email: string
13 pendingEmail: string | null
14
15 emailVerified: boolean
16 emailPublic: boolean
17 nsfwPolicy: NSFWPolicyType
18
19 adminFlags?: UserAdminFlagType
20
21 autoPlayVideo: boolean
22 autoPlayNextVideo: boolean
23 autoPlayNextVideoPlaylist: boolean
24
25 p2pEnabled: boolean
26
27 videosHistoryEnabled: boolean
28 videoLanguages: string[]
29
30 role: {
31 id: UserRoleType
32 label: string
33 }
34
35 videoQuota: number
36 videoQuotaDaily: number
37 videoQuotaUsed?: number
38 videoQuotaUsedDaily?: number
39
40 videosCount?: number
41
42 abusesCount?: number
43 abusesAcceptedCount?: number
44 abusesCreatedCount?: number
45
46 videoCommentsCount?: number
47
48 theme: string
49
50 account: Account
51 notificationSettings?: UserNotificationSetting
52 videoChannels?: VideoChannel[]
53
54 blocked: boolean
55 blockedReason?: string
56
57 noInstanceConfigWarningModal: boolean
58 noWelcomeModal: boolean
59 noAccountSetupWarningModal: boolean
60
61 createdAt: Date
62
63 pluginAuth: string | null
64
65 lastLoginDate: Date | null
66
67 twoFactorEnabled: boolean
68}
69
70export interface MyUserSpecialPlaylist {
71 id: number
72 name: string
73 type: VideoPlaylistType_Type
74}
75
76export interface MyUser extends User {
77 specialPlaylists: MyUserSpecialPlaylist[]
78}