From 3a4992633ee62d5edfbb484d9c6bcb3cf158489d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 31 Jul 2023 14:34:36 +0200 Subject: 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) --- shared/models/users/index.ts | 16 --- shared/models/users/registration/index.ts | 5 - .../users/registration/user-register.model.ts | 12 -- .../user-registration-request.model.ts | 5 - .../registration/user-registration-state.model.ts | 5 - .../user-registration-update-state.model.ts | 4 - .../users/registration/user-registration.model.ts | 29 ----- .../models/users/two-factor-enable-result.model.ts | 7 -- shared/models/users/user-create-result.model.ts | 7 -- shared/models/users/user-create.model.ts | 13 -- shared/models/users/user-flag.model.ts | 4 - shared/models/users/user-login.model.ts | 5 - .../users/user-notification-setting.model.ts | 32 ----- shared/models/users/user-notification.model.ts | 138 --------------------- shared/models/users/user-refresh-token.model.ts | 4 - shared/models/users/user-right.enum.ts | 51 -------- shared/models/users/user-role.ts | 6 - shared/models/users/user-scoped-token.ts | 5 - shared/models/users/user-update-me.model.ts | 26 ---- shared/models/users/user-update.model.ts | 13 -- shared/models/users/user-video-quota.model.ts | 4 - shared/models/users/user.model.ts | 78 ------------ 22 files changed, 469 deletions(-) delete mode 100644 shared/models/users/index.ts delete mode 100644 shared/models/users/registration/index.ts delete mode 100644 shared/models/users/registration/user-register.model.ts delete mode 100644 shared/models/users/registration/user-registration-request.model.ts delete mode 100644 shared/models/users/registration/user-registration-state.model.ts delete mode 100644 shared/models/users/registration/user-registration-update-state.model.ts delete mode 100644 shared/models/users/registration/user-registration.model.ts delete mode 100644 shared/models/users/two-factor-enable-result.model.ts delete mode 100644 shared/models/users/user-create-result.model.ts delete mode 100644 shared/models/users/user-create.model.ts delete mode 100644 shared/models/users/user-flag.model.ts delete mode 100644 shared/models/users/user-login.model.ts delete mode 100644 shared/models/users/user-notification-setting.model.ts delete mode 100644 shared/models/users/user-notification.model.ts delete mode 100644 shared/models/users/user-refresh-token.model.ts delete mode 100644 shared/models/users/user-right.enum.ts delete mode 100644 shared/models/users/user-role.ts delete mode 100644 shared/models/users/user-scoped-token.ts delete mode 100644 shared/models/users/user-update-me.model.ts delete mode 100644 shared/models/users/user-update.model.ts delete mode 100644 shared/models/users/user-video-quota.model.ts delete mode 100644 shared/models/users/user.model.ts (limited to 'shared/models/users') diff --git a/shared/models/users/index.ts b/shared/models/users/index.ts deleted file mode 100644 index 4a050c870..000000000 --- a/shared/models/users/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -export * from './registration' -export * from './two-factor-enable-result.model' -export * from './user-create-result.model' -export * from './user-create.model' -export * from './user-flag.model' -export * from './user-login.model' -export * from './user-notification-setting.model' -export * from './user-notification.model' -export * from './user-refresh-token.model' -export * from './user-right.enum' -export * from './user-role' -export * from './user-scoped-token' -export * from './user-update-me.model' -export * from './user-update.model' -export * from './user-video-quota.model' -export * from './user.model' diff --git a/shared/models/users/registration/index.ts b/shared/models/users/registration/index.ts deleted file mode 100644 index 593740c4f..000000000 --- a/shared/models/users/registration/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './user-register.model' -export * from './user-registration-request.model' -export * from './user-registration-state.model' -export * from './user-registration-update-state.model' -export * from './user-registration.model' diff --git a/shared/models/users/registration/user-register.model.ts b/shared/models/users/registration/user-register.model.ts deleted file mode 100644 index cf9a43a67..000000000 --- a/shared/models/users/registration/user-register.model.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface UserRegister { - username: string - password: string - email: string - - displayName?: string - - channel?: { - name: string - displayName: string - } -} diff --git a/shared/models/users/registration/user-registration-request.model.ts b/shared/models/users/registration/user-registration-request.model.ts deleted file mode 100644 index 6c38817e0..000000000 --- a/shared/models/users/registration/user-registration-request.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { UserRegister } from './user-register.model' - -export interface UserRegistrationRequest extends UserRegister { - registrationReason: string -} diff --git a/shared/models/users/registration/user-registration-state.model.ts b/shared/models/users/registration/user-registration-state.model.ts deleted file mode 100644 index e4c835f78..000000000 --- a/shared/models/users/registration/user-registration-state.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const enum UserRegistrationState { - PENDING = 1, - REJECTED = 2, - ACCEPTED = 3 -} diff --git a/shared/models/users/registration/user-registration-update-state.model.ts b/shared/models/users/registration/user-registration-update-state.model.ts deleted file mode 100644 index a1740dcca..000000000 --- a/shared/models/users/registration/user-registration-update-state.model.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface UserRegistrationUpdateState { - moderationResponse: string - preventEmailDelivery?: boolean -} diff --git a/shared/models/users/registration/user-registration.model.ts b/shared/models/users/registration/user-registration.model.ts deleted file mode 100644 index 0d74dc28b..000000000 --- a/shared/models/users/registration/user-registration.model.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { UserRegistrationState } from './user-registration-state.model' - -export interface UserRegistration { - id: number - - state: { - id: UserRegistrationState - label: string - } - - registrationReason: string - moderationResponse: string - - username: string - email: string - emailVerified: boolean - - accountDisplayName: string - - channelHandle: string - channelDisplayName: string - - createdAt: Date - updatedAt: Date - - user?: { - id: number - } -} diff --git a/shared/models/users/two-factor-enable-result.model.ts b/shared/models/users/two-factor-enable-result.model.ts deleted file mode 100644 index 1fc801f0a..000000000 --- a/shared/models/users/two-factor-enable-result.model.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface TwoFactorEnableResult { - otpRequest: { - requestToken: string - secret: string - uri: string - } -} diff --git a/shared/models/users/user-create-result.model.ts b/shared/models/users/user-create-result.model.ts deleted file mode 100644 index 835b241ed..000000000 --- a/shared/models/users/user-create-result.model.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface UserCreateResult { - id: number - - account: { - id: number - } -} diff --git a/shared/models/users/user-create.model.ts b/shared/models/users/user-create.model.ts deleted file mode 100644 index ddc71dd59..000000000 --- a/shared/models/users/user-create.model.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { UserRole } from './user-role' -import { UserAdminFlag } from './user-flag.model' - -export interface UserCreate { - username: string - password: string - email: string - videoQuota: number - videoQuotaDaily: number - role: UserRole - adminFlags?: UserAdminFlag - channelName?: string -} diff --git a/shared/models/users/user-flag.model.ts b/shared/models/users/user-flag.model.ts deleted file mode 100644 index b791a1263..000000000 --- a/shared/models/users/user-flag.model.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const enum UserAdminFlag { - NONE = 0, - BYPASS_VIDEO_AUTO_BLACKLIST = 1 << 0 -} diff --git a/shared/models/users/user-login.model.ts b/shared/models/users/user-login.model.ts deleted file mode 100644 index 1e85ab30b..000000000 --- a/shared/models/users/user-login.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface UserLogin { - access_token: string - refresh_token: string - token_type: string -} diff --git a/shared/models/users/user-notification-setting.model.ts b/shared/models/users/user-notification-setting.model.ts deleted file mode 100644 index 278a05e7a..000000000 --- a/shared/models/users/user-notification-setting.model.ts +++ /dev/null @@ -1,32 +0,0 @@ -export const enum UserNotificationSettingValue { - NONE = 0, - WEB = 1 << 0, - EMAIL = 1 << 1 -} - -export interface UserNotificationSetting { - abuseAsModerator: UserNotificationSettingValue - videoAutoBlacklistAsModerator: UserNotificationSettingValue - newUserRegistration: UserNotificationSettingValue - - newVideoFromSubscription: UserNotificationSettingValue - - blacklistOnMyVideo: UserNotificationSettingValue - myVideoPublished: UserNotificationSettingValue - myVideoImportFinished: UserNotificationSettingValue - - commentMention: UserNotificationSettingValue - newCommentOnMyVideo: UserNotificationSettingValue - - newFollow: UserNotificationSettingValue - newInstanceFollower: UserNotificationSettingValue - autoInstanceFollowing: UserNotificationSettingValue - - abuseStateChange: UserNotificationSettingValue - abuseNewMessage: UserNotificationSettingValue - - newPeerTubeVersion: UserNotificationSettingValue - newPluginVersion: UserNotificationSettingValue - - myVideoStudioEditionFinished: UserNotificationSettingValue -} diff --git a/shared/models/users/user-notification.model.ts b/shared/models/users/user-notification.model.ts deleted file mode 100644 index 294c921bd..000000000 --- a/shared/models/users/user-notification.model.ts +++ /dev/null @@ -1,138 +0,0 @@ -import { FollowState } from '../actors' -import { AbuseState } from '../moderation' -import { PluginType } from '../plugins' - -export const enum UserNotificationType { - NEW_VIDEO_FROM_SUBSCRIPTION = 1, - NEW_COMMENT_ON_MY_VIDEO = 2, - NEW_ABUSE_FOR_MODERATORS = 3, - - BLACKLIST_ON_MY_VIDEO = 4, - UNBLACKLIST_ON_MY_VIDEO = 5, - - MY_VIDEO_PUBLISHED = 6, - - MY_VIDEO_IMPORT_SUCCESS = 7, - MY_VIDEO_IMPORT_ERROR = 8, - - NEW_USER_REGISTRATION = 9, - NEW_FOLLOW = 10, - COMMENT_MENTION = 11, - - VIDEO_AUTO_BLACKLIST_FOR_MODERATORS = 12, - - NEW_INSTANCE_FOLLOWER = 13, - - AUTO_INSTANCE_FOLLOWING = 14, - - ABUSE_STATE_CHANGE = 15, - - ABUSE_NEW_MESSAGE = 16, - - NEW_PLUGIN_VERSION = 17, - NEW_PEERTUBE_VERSION = 18, - - MY_VIDEO_STUDIO_EDITION_FINISHED = 19, - - NEW_USER_REGISTRATION_REQUEST = 20 -} - -export interface VideoInfo { - id: number - uuid: string - shortUUID: string - name: string -} - -export interface AvatarInfo { - width: number - path: string -} - -export interface ActorInfo { - id: number - displayName: string - name: string - host: string - - avatars: AvatarInfo[] - avatar: AvatarInfo -} - -export interface UserNotification { - id: number - type: UserNotificationType - read: boolean - - video?: VideoInfo & { - channel: ActorInfo - } - - videoImport?: { - id: number - video?: VideoInfo - torrentName?: string - magnetUri?: string - targetUrl?: string - } - - comment?: { - id: number - threadId: number - account: ActorInfo - video: VideoInfo - } - - abuse?: { - id: number - state: AbuseState - - video?: VideoInfo - - comment?: { - threadId: number - - video: VideoInfo - } - - account?: ActorInfo - } - - videoBlacklist?: { - id: number - video: VideoInfo - } - - account?: ActorInfo - - actorFollow?: { - id: number - follower: ActorInfo - state: FollowState - - following: { - type: 'account' | 'channel' | 'instance' - name: string - displayName: string - host: string - } - } - - plugin?: { - name: string - type: PluginType - latestVersion: string - } - - peertube?: { - latestVersion: string - } - - registration?: { - id: number - username: string - } - - createdAt: string - updatedAt: string -} diff --git a/shared/models/users/user-refresh-token.model.ts b/shared/models/users/user-refresh-token.model.ts deleted file mode 100644 index f528dd961..000000000 --- a/shared/models/users/user-refresh-token.model.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface UserRefreshToken { - access_token: string - refresh_token: string -} diff --git a/shared/models/users/user-right.enum.ts b/shared/models/users/user-right.enum.ts deleted file mode 100644 index a5a770b75..000000000 --- a/shared/models/users/user-right.enum.ts +++ /dev/null @@ -1,51 +0,0 @@ -export const enum UserRight { - ALL = 0, - - MANAGE_USERS = 1, - - MANAGE_SERVER_FOLLOW = 2, - - MANAGE_LOGS = 3, - - MANAGE_DEBUG = 4, - - MANAGE_SERVER_REDUNDANCY = 5, - - MANAGE_ABUSES = 6, - - MANAGE_JOBS = 7, - - MANAGE_CONFIGURATION = 8, - MANAGE_INSTANCE_CUSTOM_PAGE = 9, - - MANAGE_ACCOUNTS_BLOCKLIST = 10, - MANAGE_SERVERS_BLOCKLIST = 11, - - MANAGE_VIDEO_BLACKLIST = 12, - MANAGE_ANY_VIDEO_CHANNEL = 13, - - REMOVE_ANY_VIDEO = 14, - REMOVE_ANY_VIDEO_PLAYLIST = 15, - REMOVE_ANY_VIDEO_COMMENT = 16, - - UPDATE_ANY_VIDEO = 17, - UPDATE_ANY_VIDEO_PLAYLIST = 18, - - GET_ANY_LIVE = 19, - SEE_ALL_VIDEOS = 20, - SEE_ALL_COMMENTS = 21, - CHANGE_VIDEO_OWNERSHIP = 22, - - MANAGE_PLUGINS = 23, - - MANAGE_VIDEOS_REDUNDANCIES = 24, - - MANAGE_VIDEO_FILES = 25, - RUN_VIDEO_TRANSCODING = 26, - - MANAGE_VIDEO_IMPORTS = 27, - - MANAGE_REGISTRATIONS = 28, - - MANAGE_RUNNERS = 29 -} diff --git a/shared/models/users/user-role.ts b/shared/models/users/user-role.ts deleted file mode 100644 index 687a2aa0d..000000000 --- a/shared/models/users/user-role.ts +++ /dev/null @@ -1,6 +0,0 @@ -// Keep the order -export const enum UserRole { - ADMINISTRATOR = 0, - MODERATOR = 1, - USER = 2 -} diff --git a/shared/models/users/user-scoped-token.ts b/shared/models/users/user-scoped-token.ts deleted file mode 100644 index f9d9b0a8b..000000000 --- a/shared/models/users/user-scoped-token.ts +++ /dev/null @@ -1,5 +0,0 @@ -export type ScopedTokenType = 'feedToken' - -export type ScopedToken = { - feedToken: string -} diff --git a/shared/models/users/user-update-me.model.ts b/shared/models/users/user-update-me.model.ts deleted file mode 100644 index c1d5ffba4..000000000 --- a/shared/models/users/user-update-me.model.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { NSFWPolicyType } from '../videos/nsfw-policy.type' - -export interface UserUpdateMe { - displayName?: string - description?: string - nsfwPolicy?: NSFWPolicyType - - p2pEnabled?: boolean - - autoPlayVideo?: boolean - autoPlayNextVideo?: boolean - autoPlayNextVideoPlaylist?: boolean - videosHistoryEnabled?: boolean - videoLanguages?: string[] - - email?: string - emailPublic?: boolean - currentPassword?: string - password?: string - - theme?: string - - noInstanceConfigWarningModal?: boolean - noWelcomeModal?: boolean - noAccountSetupWarningModal?: boolean -} diff --git a/shared/models/users/user-update.model.ts b/shared/models/users/user-update.model.ts deleted file mode 100644 index 158738545..000000000 --- a/shared/models/users/user-update.model.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { UserRole } from './user-role' -import { UserAdminFlag } from './user-flag.model' - -export interface UserUpdate { - password?: string - email?: string - emailVerified?: boolean - videoQuota?: number - videoQuotaDaily?: number - role?: UserRole - adminFlags?: UserAdminFlag - pluginAuth?: string -} diff --git a/shared/models/users/user-video-quota.model.ts b/shared/models/users/user-video-quota.model.ts deleted file mode 100644 index a24871d71..000000000 --- a/shared/models/users/user-video-quota.model.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface UserVideoQuota { - videoQuotaUsed: number - videoQuotaUsedDaily: number -} diff --git a/shared/models/users/user.model.ts b/shared/models/users/user.model.ts deleted file mode 100644 index 9de4118b4..000000000 --- a/shared/models/users/user.model.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { Account } from '../actors' -import { VideoChannel } from '../videos/channel/video-channel.model' -import { UserRole } from './user-role' -import { NSFWPolicyType } from '../videos/nsfw-policy.type' -import { UserNotificationSetting } from './user-notification-setting.model' -import { UserAdminFlag } from './user-flag.model' -import { VideoPlaylistType } from '../videos/playlist/video-playlist-type.model' - -export interface User { - id: number - username: string - email: string - pendingEmail: string | null - - emailVerified: boolean - emailPublic: boolean - nsfwPolicy: NSFWPolicyType - - adminFlags?: UserAdminFlag - - autoPlayVideo: boolean - autoPlayNextVideo: boolean - autoPlayNextVideoPlaylist: boolean - - p2pEnabled: boolean - - videosHistoryEnabled: boolean - videoLanguages: string[] - - role: { - id: UserRole - label: string - } - - videoQuota: number - videoQuotaDaily: number - videoQuotaUsed?: number - videoQuotaUsedDaily?: number - - videosCount?: number - - abusesCount?: number - abusesAcceptedCount?: number - abusesCreatedCount?: number - - videoCommentsCount?: number - - theme: string - - account: Account - notificationSettings?: UserNotificationSetting - videoChannels?: VideoChannel[] - - blocked: boolean - blockedReason?: string - - noInstanceConfigWarningModal: boolean - noWelcomeModal: boolean - noAccountSetupWarningModal: boolean - - createdAt: Date - - pluginAuth: string | null - - lastLoginDate: Date | null - - twoFactorEnabled: boolean -} - -export interface MyUserSpecialPlaylist { - id: number - name: string - type: VideoPlaylistType -} - -export interface MyUser extends User { - specialPlaylists: MyUserSpecialPlaylist[] -} -- cgit v1.2.3