From 67ed6552b831df66713bac9e672738796128d33f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Jun 2020 14:10:17 +0200 Subject: Reorganize client shared modules --- server/controllers/api/users/me.ts | 21 +++--- server/lib/auth.ts | 2 +- server/lib/plugins/plugin-helpers.ts | 2 +- server/lib/plugins/plugin-manager.ts | 28 ++++---- server/lib/plugins/register-helpers-store.ts | 26 +++---- server/models/utils.ts | 18 ----- server/types/index.ts | 3 + server/types/models/account/account-blocklist.ts | 2 +- server/types/models/account/account.ts | 2 +- server/types/models/account/actor-follow.ts | 2 +- server/types/models/account/actor.ts | 2 +- server/types/models/account/avatar.ts | 2 +- server/types/models/oauth/oauth-token.ts | 2 +- server/types/models/server/server-blocklist.ts | 2 +- server/types/models/server/server.ts | 2 +- server/types/models/user/user-notification.ts | 2 +- server/types/models/user/user.ts | 2 +- server/types/models/video/schedule-video-update.ts | 2 +- server/types/models/video/video-abuse.ts | 2 +- server/types/models/video/video-blacklist.ts | 2 +- server/types/models/video/video-caption.ts | 2 +- .../types/models/video/video-change-ownership.ts | 2 +- server/types/models/video/video-channels.ts | 2 +- server/types/models/video/video-comment.ts | 2 +- server/types/models/video/video-file.ts | 2 +- server/types/models/video/video-import.ts | 2 +- .../types/models/video/video-playlist-element.ts | 2 +- server/types/models/video/video-playlist.ts | 2 +- server/types/models/video/video-rate.ts | 2 +- server/types/models/video/video-redundancy.ts | 2 +- server/types/models/video/video-share.ts | 2 +- .../types/models/video/video-streaming-playlist.ts | 2 +- server/types/models/video/video.ts | 2 +- server/types/plugins/index.ts | 3 + server/types/plugins/plugin-library.model.ts | 7 ++ server/types/plugins/register-server-auth.model.ts | 52 ++++++++++++++ .../types/plugins/register-server-option.model.ts | 84 ++++++++++++++++++++++ server/types/utils.ts | 24 ------- server/typings/express/index.d.ts | 28 +++++--- server/typings/plugins/index.d.ts | 2 - server/typings/plugins/plugin-library.model.ts | 7 -- .../plugins/register-server-option.model.ts | 82 --------------------- 42 files changed, 231 insertions(+), 210 deletions(-) create mode 100644 server/types/index.ts create mode 100644 server/types/plugins/index.ts create mode 100644 server/types/plugins/plugin-library.model.ts create mode 100644 server/types/plugins/register-server-auth.model.ts create mode 100644 server/types/plugins/register-server-option.model.ts delete mode 100644 server/types/utils.ts delete mode 100644 server/typings/plugins/index.d.ts delete mode 100644 server/typings/plugins/plugin-library.model.ts delete mode 100644 server/typings/plugins/register-server-option.model.ts (limited to 'server') diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index 23890e20c..914c52e27 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts @@ -1,9 +1,15 @@ -import * as express from 'express' import 'multer' -import { UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../../shared' +import * as express from 'express' +import { UserUpdateMe, UserVideoRate as FormattedUserVideoRate, VideoSortField } from '../../../../shared' +import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model' +import { createReqFiles } from '../../../helpers/express-utils' import { getFormattedObjects } from '../../../helpers/utils' +import { CONFIG } from '../../../initializers/config' import { MIMETYPES } from '../../../initializers/constants' +import { sequelizeTypescript } from '../../../initializers/database' import { sendUpdateActor } from '../../../lib/activitypub/send' +import { updateActorAvatarFile } from '../../../lib/avatar' +import { sendVerifyUserEmail } from '../../../lib/user' import { asyncMiddleware, asyncRetryTransactionMiddleware, @@ -15,19 +21,12 @@ import { usersVideoRatingValidator } from '../../../middlewares' import { deleteMeValidator, videoImportsSortValidator, videosSortValidator } from '../../../middlewares/validators' +import { updateAvatarValidator } from '../../../middlewares/validators/avatar' +import { AccountModel } from '../../../models/account/account' import { AccountVideoRateModel } from '../../../models/account/account-video-rate' import { UserModel } from '../../../models/account/user' import { VideoModel } from '../../../models/video/video' -import { VideoSortField } from '../../../../client/src/app/shared/video/sort-field.type' -import { createReqFiles } from '../../../helpers/express-utils' -import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model' -import { updateAvatarValidator } from '../../../middlewares/validators/avatar' -import { updateActorAvatarFile } from '../../../lib/avatar' import { VideoImportModel } from '../../../models/video/video-import' -import { AccountModel } from '../../../models/account/account' -import { CONFIG } from '../../../initializers/config' -import { sequelizeTypescript } from '../../../initializers/database' -import { sendVerifyUserEmail } from '../../../lib/user' const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) diff --git a/server/lib/auth.ts b/server/lib/auth.ts index 8579bdbb4..3f8e18633 100644 --- a/server/lib/auth.ts +++ b/server/lib/auth.ts @@ -10,7 +10,7 @@ import { RegisterServerAuthenticatedResult, RegisterServerAuthPassOptions, RegisterServerExternalAuthenticatedResult -} from '@shared/models/plugins/register-server-auth.model' +} from '@server/types/plugins/register-server-auth.model' import * as express from 'express' import * as OAuthServer from 'express-oauth-server' diff --git a/server/lib/plugins/plugin-helpers.ts b/server/lib/plugins/plugin-helpers.ts index de82b4918..39773f693 100644 --- a/server/lib/plugins/plugin-helpers.ts +++ b/server/lib/plugins/plugin-helpers.ts @@ -1,4 +1,4 @@ -import { PeerTubeHelpers } from '@server/typings/plugins' +import { PeerTubeHelpers } from '@server/types/plugins' import { sequelizeTypescript } from '@server/initializers/database' import { buildLogger } from '@server/helpers/logger' import { VideoModel } from '@server/models/video/video' diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index 7fda5d9a4..94b5ecc41 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts @@ -1,28 +1,26 @@ -import { PluginModel } from '../../models/server/plugin' -import { logger } from '../../helpers/logger' +import { createReadStream, createWriteStream } from 'fs' +import { outputFile, readJSON } from 'fs-extra' import { basename, join } from 'path' -import { CONFIG } from '../../initializers/config' -import { isLibraryCodeValid, isPackageJSONValid } from '../../helpers/custom-validators/plugins' +import { MOAuthTokenUser, MUser } from '@server/types/models' +import { RegisterServerHookOptions } from '@shared/models/plugins/register-server-hook.model' +import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks' import { ClientScript, PluginPackageJson, PluginTranslationPaths as PackagePluginTranslations } from '../../../shared/models/plugins/plugin-package-json.model' -import { createReadStream, createWriteStream } from 'fs' -import { PLUGIN_GLOBAL_CSS_PATH } from '../../initializers/constants' +import { PluginTranslation } from '../../../shared/models/plugins/plugin-translation.model' import { PluginType } from '../../../shared/models/plugins/plugin.type' -import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn' -import { outputFile, readJSON } from 'fs-extra' import { ServerHook, ServerHookName } from '../../../shared/models/plugins/server-hook.model' -import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks' -import { RegisterServerOptions } from '../../typings/plugins/register-server-option.model' -import { PluginLibrary } from '../../typings/plugins' +import { isLibraryCodeValid, isPackageJSONValid } from '../../helpers/custom-validators/plugins' +import { logger } from '../../helpers/logger' +import { CONFIG } from '../../initializers/config' +import { PLUGIN_GLOBAL_CSS_PATH } from '../../initializers/constants' +import { PluginModel } from '../../models/server/plugin' +import { PluginLibrary, RegisterServerAuthExternalOptions, RegisterServerAuthPassOptions, RegisterServerOptions } from '../../types/plugins' import { ClientHtml } from '../client-html' -import { PluginTranslation } from '../../../shared/models/plugins/plugin-translation.model' import { RegisterHelpersStore } from './register-helpers-store' -import { RegisterServerHookOptions } from '@shared/models/plugins/register-server-hook.model' -import { MOAuthTokenUser, MUser } from '@server/types/models' -import { RegisterServerAuthPassOptions, RegisterServerAuthExternalOptions } from '@shared/models/plugins/register-server-auth.model' +import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn' export interface RegisteredPlugin { npmName: string diff --git a/server/lib/plugins/register-helpers-store.ts b/server/lib/plugins/register-helpers-store.ts index e337b1cb0..c73079302 100644 --- a/server/lib/plugins/register-helpers-store.ts +++ b/server/lib/plugins/register-helpers-store.ts @@ -9,22 +9,24 @@ import { } from '@server/initializers/constants' import { onExternalUserAuthenticated } from '@server/lib/auth' import { PluginModel } from '@server/models/server/plugin' -import { RegisterServerOptions } from '@server/typings/plugins' -import { PluginPlaylistPrivacyManager } from '@shared/models/plugins/plugin-playlist-privacy-manager.model' -import { PluginSettingsManager } from '@shared/models/plugins/plugin-settings-manager.model' -import { PluginStorageManager } from '@shared/models/plugins/plugin-storage-manager.model' -import { PluginVideoCategoryManager } from '@shared/models/plugins/plugin-video-category-manager.model' -import { PluginVideoLanguageManager } from '@shared/models/plugins/plugin-video-language-manager.model' -import { PluginVideoLicenceManager } from '@shared/models/plugins/plugin-video-licence-manager.model' -import { PluginVideoPrivacyManager } from '@shared/models/plugins/plugin-video-privacy-manager.model' import { RegisterServerAuthExternalOptions, RegisterServerAuthExternalResult, RegisterServerAuthPassOptions, - RegisterServerExternalAuthenticatedResult -} from '@shared/models/plugins/register-server-auth.model' -import { RegisterServerHookOptions } from '@shared/models/plugins/register-server-hook.model' -import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' + RegisterServerExternalAuthenticatedResult, + RegisterServerOptions +} from '@server/types/plugins' +import { + PluginPlaylistPrivacyManager, + PluginSettingsManager, + PluginStorageManager, + PluginVideoCategoryManager, + PluginVideoLanguageManager, + PluginVideoLicenceManager, + PluginVideoPrivacyManager, + RegisterServerHookOptions, + RegisterServerSettingOptions +} from '@shared/models' import { serverHookObject } from '@shared/models/plugins/server-hook.model' import { buildPluginHelpers } from './plugin-helpers' diff --git a/server/models/utils.ts b/server/models/utils.ts index 88c9b4adb..d706d9ea8 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -3,23 +3,6 @@ import validator from 'validator' import { Col } from 'sequelize/types/lib/utils' import { literal, OrderItem, Op } from 'sequelize' -type Primitive = string | Function | number | boolean | Symbol | undefined | null -type DeepOmitHelper = { - [P in K]: // extra level of indirection needed to trigger homomorhic behavior - T[P] extends infer TP // distribute over unions - ? TP extends Primitive - ? TP // leave primitives and functions alone - : TP extends any[] - ? DeepOmitArray // Array special handling - : DeepOmit - : never -} -type DeepOmit = T extends Primitive ? T : DeepOmitHelper> - -type DeepOmitArray = { - [P in keyof T]: DeepOmit -} - type SortType = { sortModel: string, sortValue: string } // Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ] @@ -217,7 +200,6 @@ function searchAttribute (sourceField?: string, targetField?: string) { // --------------------------------------------------------------------------- export { - DeepOmit, buildBlockedAccountSQL, buildLocalActorIdsIn, SortType, diff --git a/server/types/index.ts b/server/types/index.ts new file mode 100644 index 000000000..18d3827a5 --- /dev/null +++ b/server/types/index.ts @@ -0,0 +1,3 @@ +export * from './plugins' +export * from './activitypub-processor.model' +export * from './sequelize' diff --git a/server/types/models/account/account-blocklist.ts b/server/types/models/account/account-blocklist.ts index 0d8bf11bd..3126fd0ab 100644 --- a/server/types/models/account/account-blocklist.ts +++ b/server/types/models/account/account-blocklist.ts @@ -1,5 +1,5 @@ import { AccountBlocklistModel } from '../../../models/account/account-blocklist' -import { PickWith } from '../../utils' +import { PickWith } from '@shared/core-utils' import { MAccountDefault, MAccountFormattable } from './account' type Use = PickWith diff --git a/server/types/models/account/account.ts b/server/types/models/account/account.ts index 7b826ee04..d2add9810 100644 --- a/server/types/models/account/account.ts +++ b/server/types/models/account/account.ts @@ -13,7 +13,7 @@ import { MActorSummaryFormattable, MActorUrl } from './actor' -import { FunctionProperties, PickWith } from '../../utils' +import { FunctionProperties, PickWith } from '@shared/core-utils' import { MAccountBlocklistId } from './account-blocklist' import { MChannelDefault } from '../video/video-channels' diff --git a/server/types/models/account/actor-follow.ts b/server/types/models/account/actor-follow.ts index 5d0c03c8d..8c213d09c 100644 --- a/server/types/models/account/actor-follow.ts +++ b/server/types/models/account/actor-follow.ts @@ -8,7 +8,7 @@ import { MActorHost, MActorUsername } from './actor' -import { PickWith } from '../../utils' +import { PickWith } from '@shared/core-utils' import { ActorModel } from '@server/models/activitypub/actor' import { MChannelDefault } from '../video/video-channels' diff --git a/server/types/models/account/actor.ts b/server/types/models/account/actor.ts index 1160e84cb..ee0d05f4e 100644 --- a/server/types/models/account/actor.ts +++ b/server/types/models/account/actor.ts @@ -1,5 +1,5 @@ import { ActorModel } from '../../../models/activitypub/actor' -import { FunctionProperties, PickWith, PickWithOpt } from '../../utils' +import { FunctionProperties, PickWith, PickWithOpt } from '@shared/core-utils' import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from './account' import { MServer, MServerHost, MServerHostBlocks, MServerRedundancyAllowed } from '../server' import { MAvatar, MAvatarFormattable } from './avatar' diff --git a/server/types/models/account/avatar.ts b/server/types/models/account/avatar.ts index 6eba59ee4..0489a8599 100644 --- a/server/types/models/account/avatar.ts +++ b/server/types/models/account/avatar.ts @@ -1,5 +1,5 @@ import { AvatarModel } from '../../../models/avatar/avatar' -import { FunctionProperties } from '@server/types/utils' +import { FunctionProperties } from '@shared/core-utils' export type MAvatar = AvatarModel diff --git a/server/types/models/oauth/oauth-token.ts b/server/types/models/oauth/oauth-token.ts index 396cf6429..8399af8f1 100644 --- a/server/types/models/oauth/oauth-token.ts +++ b/server/types/models/oauth/oauth-token.ts @@ -1,5 +1,5 @@ import { OAuthTokenModel } from '@server/models/oauth/oauth-token' -import { PickWith } from '@server/types/utils' +import { PickWith } from '@shared/core-utils' import { MUserAccountUrl } from '../user/user' type Use = PickWith diff --git a/server/types/models/server/server-blocklist.ts b/server/types/models/server/server-blocklist.ts index cfbf3b73a..801f179fd 100644 --- a/server/types/models/server/server-blocklist.ts +++ b/server/types/models/server/server-blocklist.ts @@ -1,5 +1,5 @@ import { ServerBlocklistModel } from '@server/models/server/server-blocklist' -import { PickWith } from '@server/types/utils' +import { PickWith } from '@shared/core-utils' import { MAccountDefault, MAccountFormattable } from '../account/account' import { MServer, MServerFormattable } from './server' diff --git a/server/types/models/server/server.ts b/server/types/models/server/server.ts index b35e55aeb..f8b053e3b 100644 --- a/server/types/models/server/server.ts +++ b/server/types/models/server/server.ts @@ -1,5 +1,5 @@ import { ServerModel } from '../../../models/server/server' -import { FunctionProperties, PickWith } from '../../utils' +import { FunctionProperties, PickWith } from '@shared/core-utils' import { MAccountBlocklistId } from '../account' type Use = PickWith diff --git a/server/types/models/user/user-notification.ts b/server/types/models/user/user-notification.ts index 2080360e1..dd3de423b 100644 --- a/server/types/models/user/user-notification.ts +++ b/server/types/models/user/user-notification.ts @@ -1,5 +1,5 @@ import { UserNotificationModel } from '../../../models/account/user-notification' -import { PickWith, PickWithOpt } from '../../utils' +import { PickWith, PickWithOpt } from '@shared/core-utils' import { VideoModel } from '../../../models/video/video' import { ActorModel } from '../../../models/activitypub/actor' import { ServerModel } from '../../../models/server/server' diff --git a/server/types/models/user/user.ts b/server/types/models/user/user.ts index 7938ea288..12a68accf 100644 --- a/server/types/models/user/user.ts +++ b/server/types/models/user/user.ts @@ -1,5 +1,5 @@ import { UserModel } from '../../../models/account/user' -import { PickWith, PickWithOpt } from '../../utils' +import { PickWith, PickWithOpt } from '@shared/core-utils' import { MAccount, MAccountDefault, diff --git a/server/types/models/video/schedule-video-update.ts b/server/types/models/video/schedule-video-update.ts index 6336fdabe..5d2936000 100644 --- a/server/types/models/video/schedule-video-update.ts +++ b/server/types/models/video/schedule-video-update.ts @@ -1,5 +1,5 @@ import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' -import { PickWith } from '@server/types/utils' +import { PickWith } from '@shared/core-utils' import { MVideoAPWithoutCaption, MVideoWithBlacklistLight } from './video' type Use = PickWith diff --git a/server/types/models/video/video-abuse.ts b/server/types/models/video/video-abuse.ts index d60f05e4c..279a87cf3 100644 --- a/server/types/models/video/video-abuse.ts +++ b/server/types/models/video/video-abuse.ts @@ -1,5 +1,5 @@ import { VideoAbuseModel } from '../../../models/video/video-abuse' -import { PickWith } from '../../utils' +import { PickWith } from '@shared/core-utils' import { MVideoAccountLightBlacklistAllFiles, MVideo } from './video' import { MAccountDefault, MAccountFormattable } from '../account' diff --git a/server/types/models/video/video-blacklist.ts b/server/types/models/video/video-blacklist.ts index 08e59284a..2ac912405 100644 --- a/server/types/models/video/video-blacklist.ts +++ b/server/types/models/video/video-blacklist.ts @@ -1,5 +1,5 @@ import { VideoBlacklistModel } from '../../../models/video/video-blacklist' -import { PickWith } from '@server/types/utils' +import { PickWith } from '@shared/core-utils' import { MVideo, MVideoFormattable } from './video' type Use = PickWith diff --git a/server/types/models/video/video-caption.ts b/server/types/models/video/video-caption.ts index 9bb067001..ab80ff830 100644 --- a/server/types/models/video/video-caption.ts +++ b/server/types/models/video/video-caption.ts @@ -1,5 +1,5 @@ import { VideoCaptionModel } from '../../../models/video/video-caption' -import { FunctionProperties, PickWith } from '@server/types/utils' +import { FunctionProperties, PickWith } from '@shared/core-utils' import { MVideo, MVideoUUID } from './video' type Use = PickWith diff --git a/server/types/models/video/video-change-ownership.ts b/server/types/models/video/video-change-ownership.ts index 7421e081e..244d1a671 100644 --- a/server/types/models/video/video-change-ownership.ts +++ b/server/types/models/video/video-change-ownership.ts @@ -1,5 +1,5 @@ import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership' -import { PickWith } from '@server/types/utils' +import { PickWith } from '@shared/core-utils' import { MAccountDefault, MAccountFormattable } from '../account/account' import { MVideo, MVideoWithAllFiles } from './video' diff --git a/server/types/models/video/video-channels.ts b/server/types/models/video/video-channels.ts index 50f7c2d8a..2e05d8753 100644 --- a/server/types/models/video/video-channels.ts +++ b/server/types/models/video/video-channels.ts @@ -1,4 +1,4 @@ -import { FunctionProperties, PickWith, PickWithOpt } from '../../utils' +import { FunctionProperties, PickWith, PickWithOpt } from '@shared/core-utils' import { VideoChannelModel } from '../../../models/video/video-channel' import { MAccountActor, diff --git a/server/types/models/video/video-comment.ts b/server/types/models/video/video-comment.ts index d6e0b66f5..f1c50c753 100644 --- a/server/types/models/video/video-comment.ts +++ b/server/types/models/video/video-comment.ts @@ -1,5 +1,5 @@ import { VideoCommentModel } from '../../../models/video/video-comment' -import { PickWith, PickWithOpt } from '../../utils' +import { PickWith, PickWithOpt } from '@shared/core-utils' import { MAccountDefault, MAccountFormattable, MAccountUrl } from '../account' import { MVideoAccountLight, MVideoFeed, MVideoIdUrl, MVideoUrl } from './video' diff --git a/server/types/models/video/video-file.ts b/server/types/models/video/video-file.ts index 3fcaca78f..327a148ce 100644 --- a/server/types/models/video/video-file.ts +++ b/server/types/models/video/video-file.ts @@ -1,5 +1,5 @@ import { VideoFileModel } from '../../../models/video/video-file' -import { PickWith, PickWithOpt } from '../../utils' +import { PickWith, PickWithOpt } from '@shared/core-utils' import { MVideo, MVideoUUID } from './video' import { MVideoRedundancy, MVideoRedundancyFileUrl } from './video-redundancy' import { MStreamingPlaylistVideo, MStreamingPlaylist } from './video-streaming-playlist' diff --git a/server/types/models/video/video-import.ts b/server/types/models/video/video-import.ts index f1385877e..759b13c6e 100644 --- a/server/types/models/video/video-import.ts +++ b/server/types/models/video/video-import.ts @@ -1,5 +1,5 @@ import { VideoImportModel } from '@server/models/video/video-import' -import { PickWith, PickWithOpt } from '@server/types/utils' +import { PickWith, PickWithOpt } from '@shared/core-utils' import { MVideo, MVideoAccountLight, MVideoFormattable, MVideoTag, MVideoThumbnail, MVideoWithFile } from './video' import { MUser } from '../user/user' diff --git a/server/types/models/video/video-playlist-element.ts b/server/types/models/video/video-playlist-element.ts index c50992da7..f46ff4d49 100644 --- a/server/types/models/video/video-playlist-element.ts +++ b/server/types/models/video/video-playlist-element.ts @@ -1,5 +1,5 @@ import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element' -import { PickWith } from '@server/types/utils' +import { PickWith } from '@shared/core-utils' import { MVideoFormattable, MVideoThumbnail, MVideoUrl } from './video' import { MVideoPlaylistPrivacy } from './video-playlist' diff --git a/server/types/models/video/video-playlist.ts b/server/types/models/video/video-playlist.ts index b504d1664..79e2daebf 100644 --- a/server/types/models/video/video-playlist.ts +++ b/server/types/models/video/video-playlist.ts @@ -1,5 +1,5 @@ import { VideoPlaylistModel } from '../../../models/video/video-playlist' -import { PickWith } from '../../utils' +import { PickWith } from '@shared/core-utils' import { MAccount, MAccountDefault, MAccountSummary, MAccountSummaryFormattable } from '../account' import { MThumbnail } from './thumbnail' import { MChannelDefault, MChannelSummary, MChannelSummaryFormattable, MChannelUrl } from './video-channels' diff --git a/server/types/models/video/video-rate.ts b/server/types/models/video/video-rate.ts index a7682ef31..7bd54f7b0 100644 --- a/server/types/models/video/video-rate.ts +++ b/server/types/models/video/video-rate.ts @@ -1,5 +1,5 @@ import { AccountVideoRateModel } from '@server/models/account/account-video-rate' -import { PickWith } from '@server/types/utils' +import { PickWith } from '@shared/core-utils' import { MAccountAudience, MAccountUrl } from '../account/account' import { MVideo, MVideoFormattable } from './video' diff --git a/server/types/models/video/video-redundancy.ts b/server/types/models/video/video-redundancy.ts index 7c7d52035..411375c81 100644 --- a/server/types/models/video/video-redundancy.ts +++ b/server/types/models/video/video-redundancy.ts @@ -1,5 +1,5 @@ import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' -import { PickWith, PickWithOpt } from '@server/types/utils' +import { PickWith, PickWithOpt } from '@shared/core-utils' import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' import { VideoFileModel } from '@server/models/video/video-file' import { MVideoFile, MVideoFileVideo } from './video-file' diff --git a/server/types/models/video/video-share.ts b/server/types/models/video/video-share.ts index 50ca75d26..b7a783bb6 100644 --- a/server/types/models/video/video-share.ts +++ b/server/types/models/video/video-share.ts @@ -1,5 +1,5 @@ import { VideoShareModel } from '../../../models/video/video-share' -import { PickWith } from '../../utils' +import { PickWith } from '@shared/core-utils' import { MActorDefault } from '../account' import { MVideo } from './video' diff --git a/server/types/models/video/video-streaming-playlist.ts b/server/types/models/video/video-streaming-playlist.ts index 3f54aa560..8b3ef51fc 100644 --- a/server/types/models/video/video-streaming-playlist.ts +++ b/server/types/models/video/video-streaming-playlist.ts @@ -1,5 +1,5 @@ import { VideoStreamingPlaylistModel } from '../../../models/video/video-streaming-playlist' -import { PickWith, PickWithOpt } from '../../utils' +import { PickWith, PickWithOpt } from '@shared/core-utils' import { MVideoRedundancyFileUrl, MVideoRedundancy } from './video-redundancy' import { MVideo } from './video' import { MVideoFile } from './video-file' diff --git a/server/types/models/video/video.ts b/server/types/models/video/video.ts index 022a9566d..3d8f85b3d 100644 --- a/server/types/models/video/video.ts +++ b/server/types/models/video/video.ts @@ -1,5 +1,5 @@ import { VideoModel } from '../../../models/video/video' -import { PickWith, PickWithOpt } from '../../utils' +import { PickWith, PickWithOpt } from '@shared/core-utils' import { MChannelAccountDefault, MChannelAccountLight, diff --git a/server/types/plugins/index.ts b/server/types/plugins/index.ts new file mode 100644 index 000000000..de30ff2ab --- /dev/null +++ b/server/types/plugins/index.ts @@ -0,0 +1,3 @@ +export * from './plugin-library.model' +export * from './register-server-auth.model' +export * from './register-server-option.model' diff --git a/server/types/plugins/plugin-library.model.ts b/server/types/plugins/plugin-library.model.ts new file mode 100644 index 000000000..5b517ee9f --- /dev/null +++ b/server/types/plugins/plugin-library.model.ts @@ -0,0 +1,7 @@ +import { RegisterServerOptions } from './register-server-option.model' + +export interface PluginLibrary { + register: (options: RegisterServerOptions) => Promise + + unregister: () => Promise +} diff --git a/server/types/plugins/register-server-auth.model.ts b/server/types/plugins/register-server-auth.model.ts new file mode 100644 index 000000000..31c71b0d0 --- /dev/null +++ b/server/types/plugins/register-server-auth.model.ts @@ -0,0 +1,52 @@ +import * as express from 'express' +import { UserRole } from '@shared/models' +import { MOAuthToken, MUser } from '../models' + +export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions + +export interface RegisterServerAuthenticatedResult { + username: string + email: string + role?: UserRole + displayName?: string +} + +export interface RegisterServerExternalAuthenticatedResult extends RegisterServerAuthenticatedResult { + req: express.Request + res: express.Response +} + +interface RegisterServerAuthBase { + // Authentication name (a plugin can register multiple auth strategies) + authName: string + + // Called by PeerTube when a user from your plugin logged out + onLogout?(user: MUser): void + + // Your plugin can hook PeerTube access/refresh token validity + // So you can control for your plugin the user session lifetime + hookTokenValidity?(options: { token: MOAuthToken, type: 'access' | 'refresh' }): Promise<{ valid: boolean }> +} + +export interface RegisterServerAuthPassOptions extends RegisterServerAuthBase { + // Weight of this authentication so PeerTube tries the auth methods in DESC weight order + getWeight(): number + + // Used by PeerTube to login a user + // Returns null if the login failed, or { username, email } on success + login(body: { + id: string + password: string + }): Promise +} + +export interface RegisterServerAuthExternalOptions extends RegisterServerAuthBase { + // Will be displayed in a block next to the login form + authDisplayName: () => string + + onAuthRequest: (req: express.Request, res: express.Response) => void +} + +export interface RegisterServerAuthExternalResult { + userAuthenticated (options: RegisterServerExternalAuthenticatedResult): void +} diff --git a/server/types/plugins/register-server-option.model.ts b/server/types/plugins/register-server-option.model.ts new file mode 100644 index 000000000..74303d383 --- /dev/null +++ b/server/types/plugins/register-server-option.model.ts @@ -0,0 +1,84 @@ +import * as Bluebird from 'bluebird' +import { Router } from 'express' +import { Logger } from 'winston' +import { ActorModel } from '@server/models/activitypub/actor' +import { + PluginPlaylistPrivacyManager, + PluginSettingsManager, + PluginStorageManager, + PluginVideoCategoryManager, + PluginVideoLanguageManager, + PluginVideoLicenceManager, + PluginVideoPrivacyManager, + RegisterServerHookOptions, + RegisterServerSettingOptions, + VideoBlacklistCreate +} from '@shared/models' +import { MVideoThumbnail } from '../models' +import { + RegisterServerAuthExternalOptions, + RegisterServerAuthExternalResult, + RegisterServerAuthPassOptions +} from './register-server-auth.model' + +export type PeerTubeHelpers = { + logger: Logger + + database: { + query: Function + } + + videos: { + loadByUrl: (url: string) => Bluebird + + removeVideo: (videoId: number) => Promise + } + + config: { + getWebserverUrl: () => string + } + + moderation: { + blockServer: (options: { byAccountId: number, hostToBlock: string }) => Promise + unblockServer: (options: { byAccountId: number, hostToUnblock: string }) => Promise + blockAccount: (options: { byAccountId: number, handleToBlock: string }) => Promise + unblockAccount: (options: { byAccountId: number, handleToUnblock: string }) => Promise + + blacklistVideo: (options: { videoIdOrUUID: number | string, createOptions: VideoBlacklistCreate }) => Promise + unblacklistVideo: (options: { videoIdOrUUID: number | string }) => Promise + } + + server: { + getServerActor: () => Promise + } +} + +export type RegisterServerOptions = { + registerHook: (options: RegisterServerHookOptions) => void + + registerSetting: (options: RegisterServerSettingOptions) => void + + settingsManager: PluginSettingsManager + + storageManager: PluginStorageManager + + videoCategoryManager: PluginVideoCategoryManager + videoLanguageManager: PluginVideoLanguageManager + videoLicenceManager: PluginVideoLicenceManager + + videoPrivacyManager: PluginVideoPrivacyManager + playlistPrivacyManager: PluginPlaylistPrivacyManager + + registerIdAndPassAuth: (options: RegisterServerAuthPassOptions) => void + registerExternalAuth: (options: RegisterServerAuthExternalOptions) => RegisterServerAuthExternalResult + unregisterIdAndPassAuth: (authName: string) => void + unregisterExternalAuth: (authName: string) => void + + // Get plugin router to create custom routes + // Base routes of this router are + // * /plugins/:pluginName/:pluginVersion/router/... + // * /plugins/:pluginName/router/... + getRouter(): Router + + peertubeHelpers: PeerTubeHelpers +} diff --git a/server/types/utils.ts b/server/types/utils.ts deleted file mode 100644 index 55500d8c4..000000000 --- a/server/types/utils.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* eslint-disable @typescript-eslint/array-type */ - -export type FunctionPropertyNames = { - [K in keyof T]: T[K] extends Function ? K : never -}[keyof T] - -export type FunctionProperties = Pick> - -export type PickWith = { - [P in KT]: T[P] extends V ? V : never -} - -export type PickWithOpt = { - [P in KT]?: T[P] extends V ? V : never -} - -// https://github.com/krzkaczor/ts-essentials Rocks! -export type DeepPartial = { - [P in keyof T]?: T[P] extends Array - ? Array> - : T[P] extends ReadonlyArray - ? ReadonlyArray> - : DeepPartial -} diff --git a/server/typings/express/index.d.ts b/server/typings/express/index.d.ts index ad3212340..cac801e55 100644 --- a/server/typings/express/index.d.ts +++ b/server/typings/express/index.d.ts @@ -1,3 +1,20 @@ +import { RegisterServerAuthExternalOptions } from '@server/types' +import { + MAccountBlocklist, + MActorUrl, + MStreamingPlaylist, + MVideoChangeOwnershipFull, + MVideoFile, + MVideoImmutable, + MVideoPlaylistFull, + MVideoPlaylistFullSummary +} from '@server/types/models' +import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token' +import { MPlugin, MServer, MServerBlocklist } from '@server/types/models/server' +import { MVideoImportDefault } from '@server/types/models/video/video-import' +import { MVideoPlaylistElement, MVideoPlaylistElementVideoUrlPlaylistPrivacy } from '@server/types/models/video/video-playlist-element' +import { MAccountVideoRateAccountVideo } from '@server/types/models/video/video-rate' +import { UserRole } from '@shared/models' import { RegisteredPlugin } from '../../lib/plugins/plugin-manager' import { MAccountDefault, @@ -19,17 +36,6 @@ import { MVideoThumbnail, MVideoWithRights } from '../../types/models' -import { MVideoPlaylistFull, MVideoPlaylistFullSummary } from '../../types/models/video/video-playlist' -import { MVideoImportDefault } from '@server/types/models/video/video-import' -import { MAccountBlocklist, MActorUrl, MStreamingPlaylist, MVideoFile, MVideoImmutable } from '@server/types/models' -import { MVideoPlaylistElement, MVideoPlaylistElementVideoUrlPlaylistPrivacy } from '@server/types/models/video/video-playlist-element' -import { MAccountVideoRateAccountVideo } from '@server/types/models/video/video-rate' -import { MVideoChangeOwnershipFull } from '../../types/models/video/video-change-ownership' -import { MPlugin, MServer } from '@server/types/models/server' -import { MServerBlocklist } from '../../types/models/server/server-blocklist' -import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token' -import { UserRole } from '@shared/models' -import { RegisterServerAuthExternalOptions } from '@shared/models/plugins/register-server-auth.model' declare module 'express' { export interface Request { diff --git a/server/typings/plugins/index.d.ts b/server/typings/plugins/index.d.ts deleted file mode 100644 index 9570579ef..000000000 --- a/server/typings/plugins/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './register-server-option.model' -export * from './plugin-library.model' diff --git a/server/typings/plugins/plugin-library.model.ts b/server/typings/plugins/plugin-library.model.ts deleted file mode 100644 index 5b517ee9f..000000000 --- a/server/typings/plugins/plugin-library.model.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { RegisterServerOptions } from './register-server-option.model' - -export interface PluginLibrary { - register: (options: RegisterServerOptions) => Promise - - unregister: () => Promise -} diff --git a/server/typings/plugins/register-server-option.model.ts b/server/typings/plugins/register-server-option.model.ts deleted file mode 100644 index b4594c6cd..000000000 --- a/server/typings/plugins/register-server-option.model.ts +++ /dev/null @@ -1,82 +0,0 @@ -import * as Bluebird from 'bluebird' -import { Router } from 'express' -import { Logger } from 'winston' -import { ActorModel } from '@server/models/activitypub/actor' -import { VideoBlacklistCreate } from '@shared/models' -import { PluginPlaylistPrivacyManager } from '@shared/models/plugins/plugin-playlist-privacy-manager.model' -import { PluginVideoPrivacyManager } from '@shared/models/plugins/plugin-video-privacy-manager.model' -import { - RegisterServerAuthExternalOptions, - RegisterServerAuthExternalResult, - RegisterServerAuthPassOptions -} from '@shared/models/plugins/register-server-auth.model' -import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model' -import { PluginStorageManager } from '../../../shared/models/plugins/plugin-storage-manager.model' -import { PluginVideoCategoryManager } from '../../../shared/models/plugins/plugin-video-category-manager.model' -import { PluginVideoLanguageManager } from '../../../shared/models/plugins/plugin-video-language-manager.model' -import { PluginVideoLicenceManager } from '../../../shared/models/plugins/plugin-video-licence-manager.model' -import { RegisterServerHookOptions } from '../../../shared/models/plugins/register-server-hook.model' -import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model' -import { MVideoThumbnail } from '../../types/models' - -export type PeerTubeHelpers = { - logger: Logger - - database: { - query: Function - } - - videos: { - loadByUrl: (url: string) => Bluebird - - removeVideo: (videoId: number) => Promise - } - - config: { - getWebserverUrl: () => string - } - - moderation: { - blockServer: (options: { byAccountId: number, hostToBlock: string }) => Promise - unblockServer: (options: { byAccountId: number, hostToUnblock: string }) => Promise - blockAccount: (options: { byAccountId: number, handleToBlock: string }) => Promise - unblockAccount: (options: { byAccountId: number, handleToUnblock: string }) => Promise - - blacklistVideo: (options: { videoIdOrUUID: number | string, createOptions: VideoBlacklistCreate }) => Promise - unblacklistVideo: (options: { videoIdOrUUID: number | string }) => Promise - } - - server: { - getServerActor: () => Promise - } -} - -export type RegisterServerOptions = { - registerHook: (options: RegisterServerHookOptions) => void - - registerSetting: (options: RegisterServerSettingOptions) => void - - settingsManager: PluginSettingsManager - - storageManager: PluginStorageManager - - videoCategoryManager: PluginVideoCategoryManager - videoLanguageManager: PluginVideoLanguageManager - videoLicenceManager: PluginVideoLicenceManager - - videoPrivacyManager: PluginVideoPrivacyManager - playlistPrivacyManager: PluginPlaylistPrivacyManager - - registerIdAndPassAuth: (options: RegisterServerAuthPassOptions) => void - registerExternalAuth: (options: RegisterServerAuthExternalOptions) => RegisterServerAuthExternalResult - unregisterIdAndPassAuth: (authName: string) => void - unregisterExternalAuth: (authName: string) => void - - // Get plugin router to create custom routes - // Base routes of this router are - // * /plugins/:pluginName/:pluginVersion/router/... - // * /plugins/:pluginName/router/... - getRouter(): Router - - peertubeHelpers: PeerTubeHelpers -} -- cgit v1.2.3