aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-23 14:10:17 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-06-23 16:00:49 +0200
commit67ed6552b831df66713bac9e672738796128d33f (patch)
tree59c97d41e0b49d75a90aa3de987968ab9b1ff447 /server
parent0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff)
downloadPeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz
PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst
PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip
Reorganize client shared modules
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/users/me.ts21
-rw-r--r--server/lib/auth.ts2
-rw-r--r--server/lib/plugins/plugin-helpers.ts2
-rw-r--r--server/lib/plugins/plugin-manager.ts28
-rw-r--r--server/lib/plugins/register-helpers-store.ts26
-rw-r--r--server/models/utils.ts18
-rw-r--r--server/types/index.ts3
-rw-r--r--server/types/models/account/account-blocklist.ts2
-rw-r--r--server/types/models/account/account.ts2
-rw-r--r--server/types/models/account/actor-follow.ts2
-rw-r--r--server/types/models/account/actor.ts2
-rw-r--r--server/types/models/account/avatar.ts2
-rw-r--r--server/types/models/oauth/oauth-token.ts2
-rw-r--r--server/types/models/server/server-blocklist.ts2
-rw-r--r--server/types/models/server/server.ts2
-rw-r--r--server/types/models/user/user-notification.ts2
-rw-r--r--server/types/models/user/user.ts2
-rw-r--r--server/types/models/video/schedule-video-update.ts2
-rw-r--r--server/types/models/video/video-abuse.ts2
-rw-r--r--server/types/models/video/video-blacklist.ts2
-rw-r--r--server/types/models/video/video-caption.ts2
-rw-r--r--server/types/models/video/video-change-ownership.ts2
-rw-r--r--server/types/models/video/video-channels.ts2
-rw-r--r--server/types/models/video/video-comment.ts2
-rw-r--r--server/types/models/video/video-file.ts2
-rw-r--r--server/types/models/video/video-import.ts2
-rw-r--r--server/types/models/video/video-playlist-element.ts2
-rw-r--r--server/types/models/video/video-playlist.ts2
-rw-r--r--server/types/models/video/video-rate.ts2
-rw-r--r--server/types/models/video/video-redundancy.ts2
-rw-r--r--server/types/models/video/video-share.ts2
-rw-r--r--server/types/models/video/video-streaming-playlist.ts2
-rw-r--r--server/types/models/video/video.ts2
-rw-r--r--server/types/plugins/index.ts (renamed from server/typings/plugins/index.d.ts)3
-rw-r--r--server/types/plugins/plugin-library.model.ts (renamed from server/typings/plugins/plugin-library.model.ts)0
-rw-r--r--server/types/plugins/register-server-auth.model.ts52
-rw-r--r--server/types/plugins/register-server-option.model.ts (renamed from server/typings/plugins/register-server-option.model.ts)26
-rw-r--r--server/types/utils.ts24
-rw-r--r--server/typings/express/index.d.ts28
39 files changed, 153 insertions, 132 deletions
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 @@
1import * as express from 'express'
2import 'multer' 1import 'multer'
3import { UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../../shared' 2import * as express from 'express'
3import { UserUpdateMe, UserVideoRate as FormattedUserVideoRate, VideoSortField } from '../../../../shared'
4import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model'
5import { createReqFiles } from '../../../helpers/express-utils'
4import { getFormattedObjects } from '../../../helpers/utils' 6import { getFormattedObjects } from '../../../helpers/utils'
7import { CONFIG } from '../../../initializers/config'
5import { MIMETYPES } from '../../../initializers/constants' 8import { MIMETYPES } from '../../../initializers/constants'
9import { sequelizeTypescript } from '../../../initializers/database'
6import { sendUpdateActor } from '../../../lib/activitypub/send' 10import { sendUpdateActor } from '../../../lib/activitypub/send'
11import { updateActorAvatarFile } from '../../../lib/avatar'
12import { sendVerifyUserEmail } from '../../../lib/user'
7import { 13import {
8 asyncMiddleware, 14 asyncMiddleware,
9 asyncRetryTransactionMiddleware, 15 asyncRetryTransactionMiddleware,
@@ -15,19 +21,12 @@ import {
15 usersVideoRatingValidator 21 usersVideoRatingValidator
16} from '../../../middlewares' 22} from '../../../middlewares'
17import { deleteMeValidator, videoImportsSortValidator, videosSortValidator } from '../../../middlewares/validators' 23import { deleteMeValidator, videoImportsSortValidator, videosSortValidator } from '../../../middlewares/validators'
24import { updateAvatarValidator } from '../../../middlewares/validators/avatar'
25import { AccountModel } from '../../../models/account/account'
18import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 26import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
19import { UserModel } from '../../../models/account/user' 27import { UserModel } from '../../../models/account/user'
20import { VideoModel } from '../../../models/video/video' 28import { VideoModel } from '../../../models/video/video'
21import { VideoSortField } from '../../../../client/src/app/shared/video/sort-field.type'
22import { createReqFiles } from '../../../helpers/express-utils'
23import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model'
24import { updateAvatarValidator } from '../../../middlewares/validators/avatar'
25import { updateActorAvatarFile } from '../../../lib/avatar'
26import { VideoImportModel } from '../../../models/video/video-import' 29import { VideoImportModel } from '../../../models/video/video-import'
27import { AccountModel } from '../../../models/account/account'
28import { CONFIG } from '../../../initializers/config'
29import { sequelizeTypescript } from '../../../initializers/database'
30import { sendVerifyUserEmail } from '../../../lib/user'
31 30
32const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) 31const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR })
33 32
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 {
10 RegisterServerAuthenticatedResult, 10 RegisterServerAuthenticatedResult,
11 RegisterServerAuthPassOptions, 11 RegisterServerAuthPassOptions,
12 RegisterServerExternalAuthenticatedResult 12 RegisterServerExternalAuthenticatedResult
13} from '@shared/models/plugins/register-server-auth.model' 13} from '@server/types/plugins/register-server-auth.model'
14import * as express from 'express' 14import * as express from 'express'
15import * as OAuthServer from 'express-oauth-server' 15import * as OAuthServer from 'express-oauth-server'
16 16
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 @@
1import { PeerTubeHelpers } from '@server/typings/plugins' 1import { PeerTubeHelpers } from '@server/types/plugins'
2import { sequelizeTypescript } from '@server/initializers/database' 2import { sequelizeTypescript } from '@server/initializers/database'
3import { buildLogger } from '@server/helpers/logger' 3import { buildLogger } from '@server/helpers/logger'
4import { VideoModel } from '@server/models/video/video' 4import { 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 @@
1import { PluginModel } from '../../models/server/plugin' 1import { createReadStream, createWriteStream } from 'fs'
2import { logger } from '../../helpers/logger' 2import { outputFile, readJSON } from 'fs-extra'
3import { basename, join } from 'path' 3import { basename, join } from 'path'
4import { CONFIG } from '../../initializers/config' 4import { MOAuthTokenUser, MUser } from '@server/types/models'
5import { isLibraryCodeValid, isPackageJSONValid } from '../../helpers/custom-validators/plugins' 5import { RegisterServerHookOptions } from '@shared/models/plugins/register-server-hook.model'
6import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks'
6import { 7import {
7 ClientScript, 8 ClientScript,
8 PluginPackageJson, 9 PluginPackageJson,
9 PluginTranslationPaths as PackagePluginTranslations 10 PluginTranslationPaths as PackagePluginTranslations
10} from '../../../shared/models/plugins/plugin-package-json.model' 11} from '../../../shared/models/plugins/plugin-package-json.model'
11import { createReadStream, createWriteStream } from 'fs' 12import { PluginTranslation } from '../../../shared/models/plugins/plugin-translation.model'
12import { PLUGIN_GLOBAL_CSS_PATH } from '../../initializers/constants'
13import { PluginType } from '../../../shared/models/plugins/plugin.type' 13import { PluginType } from '../../../shared/models/plugins/plugin.type'
14import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn'
15import { outputFile, readJSON } from 'fs-extra'
16import { ServerHook, ServerHookName } from '../../../shared/models/plugins/server-hook.model' 14import { ServerHook, ServerHookName } from '../../../shared/models/plugins/server-hook.model'
17import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks' 15import { isLibraryCodeValid, isPackageJSONValid } from '../../helpers/custom-validators/plugins'
18import { RegisterServerOptions } from '../../typings/plugins/register-server-option.model' 16import { logger } from '../../helpers/logger'
19import { PluginLibrary } from '../../typings/plugins' 17import { CONFIG } from '../../initializers/config'
18import { PLUGIN_GLOBAL_CSS_PATH } from '../../initializers/constants'
19import { PluginModel } from '../../models/server/plugin'
20import { PluginLibrary, RegisterServerAuthExternalOptions, RegisterServerAuthPassOptions, RegisterServerOptions } from '../../types/plugins'
20import { ClientHtml } from '../client-html' 21import { ClientHtml } from '../client-html'
21import { PluginTranslation } from '../../../shared/models/plugins/plugin-translation.model'
22import { RegisterHelpersStore } from './register-helpers-store' 22import { RegisterHelpersStore } from './register-helpers-store'
23import { RegisterServerHookOptions } from '@shared/models/plugins/register-server-hook.model' 23import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn'
24import { MOAuthTokenUser, MUser } from '@server/types/models'
25import { RegisterServerAuthPassOptions, RegisterServerAuthExternalOptions } from '@shared/models/plugins/register-server-auth.model'
26 24
27export interface RegisteredPlugin { 25export interface RegisteredPlugin {
28 npmName: string 26 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 {
9} from '@server/initializers/constants' 9} from '@server/initializers/constants'
10import { onExternalUserAuthenticated } from '@server/lib/auth' 10import { onExternalUserAuthenticated } from '@server/lib/auth'
11import { PluginModel } from '@server/models/server/plugin' 11import { PluginModel } from '@server/models/server/plugin'
12import { RegisterServerOptions } from '@server/typings/plugins'
13import { PluginPlaylistPrivacyManager } from '@shared/models/plugins/plugin-playlist-privacy-manager.model'
14import { PluginSettingsManager } from '@shared/models/plugins/plugin-settings-manager.model'
15import { PluginStorageManager } from '@shared/models/plugins/plugin-storage-manager.model'
16import { PluginVideoCategoryManager } from '@shared/models/plugins/plugin-video-category-manager.model'
17import { PluginVideoLanguageManager } from '@shared/models/plugins/plugin-video-language-manager.model'
18import { PluginVideoLicenceManager } from '@shared/models/plugins/plugin-video-licence-manager.model'
19import { PluginVideoPrivacyManager } from '@shared/models/plugins/plugin-video-privacy-manager.model'
20import { 12import {
21 RegisterServerAuthExternalOptions, 13 RegisterServerAuthExternalOptions,
22 RegisterServerAuthExternalResult, 14 RegisterServerAuthExternalResult,
23 RegisterServerAuthPassOptions, 15 RegisterServerAuthPassOptions,
24 RegisterServerExternalAuthenticatedResult 16 RegisterServerExternalAuthenticatedResult,
25} from '@shared/models/plugins/register-server-auth.model' 17 RegisterServerOptions
26import { RegisterServerHookOptions } from '@shared/models/plugins/register-server-hook.model' 18} from '@server/types/plugins'
27import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' 19import {
20 PluginPlaylistPrivacyManager,
21 PluginSettingsManager,
22 PluginStorageManager,
23 PluginVideoCategoryManager,
24 PluginVideoLanguageManager,
25 PluginVideoLicenceManager,
26 PluginVideoPrivacyManager,
27 RegisterServerHookOptions,
28 RegisterServerSettingOptions
29} from '@shared/models'
28import { serverHookObject } from '@shared/models/plugins/server-hook.model' 30import { serverHookObject } from '@shared/models/plugins/server-hook.model'
29import { buildPluginHelpers } from './plugin-helpers' 31import { buildPluginHelpers } from './plugin-helpers'
30 32
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'
3import { Col } from 'sequelize/types/lib/utils' 3import { Col } from 'sequelize/types/lib/utils'
4import { literal, OrderItem, Op } from 'sequelize' 4import { literal, OrderItem, Op } from 'sequelize'
5 5
6type Primitive = string | Function | number | boolean | Symbol | undefined | null
7type DeepOmitHelper<T, K extends keyof T> = {
8 [P in K]: // extra level of indirection needed to trigger homomorhic behavior
9 T[P] extends infer TP // distribute over unions
10 ? TP extends Primitive
11 ? TP // leave primitives and functions alone
12 : TP extends any[]
13 ? DeepOmitArray<TP, K> // Array special handling
14 : DeepOmit<TP, K>
15 : never
16}
17type DeepOmit<T, K> = T extends Primitive ? T : DeepOmitHelper<T, Exclude<keyof T, K>>
18
19type DeepOmitArray<T extends any[], K> = {
20 [P in keyof T]: DeepOmit<T[P], K>
21}
22
23type SortType = { sortModel: string, sortValue: string } 6type SortType = { sortModel: string, sortValue: string }
24 7
25// Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ] 8// Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ]
@@ -217,7 +200,6 @@ function searchAttribute (sourceField?: string, targetField?: string) {
217// --------------------------------------------------------------------------- 200// ---------------------------------------------------------------------------
218 201
219export { 202export {
220 DeepOmit,
221 buildBlockedAccountSQL, 203 buildBlockedAccountSQL,
222 buildLocalActorIdsIn, 204 buildLocalActorIdsIn,
223 SortType, 205 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 @@
1export * from './plugins'
2export * from './activitypub-processor.model'
3export * 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 @@
1import { AccountBlocklistModel } from '../../../models/account/account-blocklist' 1import { AccountBlocklistModel } from '../../../models/account/account-blocklist'
2import { PickWith } from '../../utils' 2import { PickWith } from '@shared/core-utils'
3import { MAccountDefault, MAccountFormattable } from './account' 3import { MAccountDefault, MAccountFormattable } from './account'
4 4
5type Use<K extends keyof AccountBlocklistModel, M> = PickWith<AccountBlocklistModel, K, M> 5type Use<K extends keyof AccountBlocklistModel, M> = PickWith<AccountBlocklistModel, K, M>
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 {
13 MActorSummaryFormattable, 13 MActorSummaryFormattable,
14 MActorUrl 14 MActorUrl
15} from './actor' 15} from './actor'
16import { FunctionProperties, PickWith } from '../../utils' 16import { FunctionProperties, PickWith } from '@shared/core-utils'
17import { MAccountBlocklistId } from './account-blocklist' 17import { MAccountBlocklistId } from './account-blocklist'
18import { MChannelDefault } from '../video/video-channels' 18import { MChannelDefault } from '../video/video-channels'
19 19
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 {
8 MActorHost, 8 MActorHost,
9 MActorUsername 9 MActorUsername
10} from './actor' 10} from './actor'
11import { PickWith } from '../../utils' 11import { PickWith } from '@shared/core-utils'
12import { ActorModel } from '@server/models/activitypub/actor' 12import { ActorModel } from '@server/models/activitypub/actor'
13import { MChannelDefault } from '../video/video-channels' 13import { MChannelDefault } from '../video/video-channels'
14 14
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 @@
1import { ActorModel } from '../../../models/activitypub/actor' 1import { ActorModel } from '../../../models/activitypub/actor'
2import { FunctionProperties, PickWith, PickWithOpt } from '../../utils' 2import { FunctionProperties, PickWith, PickWithOpt } from '@shared/core-utils'
3import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from './account' 3import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from './account'
4import { MServer, MServerHost, MServerHostBlocks, MServerRedundancyAllowed } from '../server' 4import { MServer, MServerHost, MServerHostBlocks, MServerRedundancyAllowed } from '../server'
5import { MAvatar, MAvatarFormattable } from './avatar' 5import { 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 @@
1import { AvatarModel } from '../../../models/avatar/avatar' 1import { AvatarModel } from '../../../models/avatar/avatar'
2import { FunctionProperties } from '@server/types/utils' 2import { FunctionProperties } from '@shared/core-utils'
3 3
4export type MAvatar = AvatarModel 4export type MAvatar = AvatarModel
5 5
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 @@
1import { OAuthTokenModel } from '@server/models/oauth/oauth-token' 1import { OAuthTokenModel } from '@server/models/oauth/oauth-token'
2import { PickWith } from '@server/types/utils' 2import { PickWith } from '@shared/core-utils'
3import { MUserAccountUrl } from '../user/user' 3import { MUserAccountUrl } from '../user/user'
4 4
5type Use<K extends keyof OAuthTokenModel, M> = PickWith<OAuthTokenModel, K, M> 5type Use<K extends keyof OAuthTokenModel, M> = PickWith<OAuthTokenModel, K, M>
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 @@
1import { ServerBlocklistModel } from '@server/models/server/server-blocklist' 1import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
2import { PickWith } from '@server/types/utils' 2import { PickWith } from '@shared/core-utils'
3import { MAccountDefault, MAccountFormattable } from '../account/account' 3import { MAccountDefault, MAccountFormattable } from '../account/account'
4import { MServer, MServerFormattable } from './server' 4import { MServer, MServerFormattable } from './server'
5 5
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 @@
1import { ServerModel } from '../../../models/server/server' 1import { ServerModel } from '../../../models/server/server'
2import { FunctionProperties, PickWith } from '../../utils' 2import { FunctionProperties, PickWith } from '@shared/core-utils'
3import { MAccountBlocklistId } from '../account' 3import { MAccountBlocklistId } from '../account'
4 4
5type Use<K extends keyof ServerModel, M> = PickWith<ServerModel, K, M> 5type Use<K extends keyof ServerModel, M> = PickWith<ServerModel, K, M>
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 @@
1import { UserNotificationModel } from '../../../models/account/user-notification' 1import { UserNotificationModel } from '../../../models/account/user-notification'
2import { PickWith, PickWithOpt } from '../../utils' 2import { PickWith, PickWithOpt } from '@shared/core-utils'
3import { VideoModel } from '../../../models/video/video' 3import { VideoModel } from '../../../models/video/video'
4import { ActorModel } from '../../../models/activitypub/actor' 4import { ActorModel } from '../../../models/activitypub/actor'
5import { ServerModel } from '../../../models/server/server' 5import { 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 @@
1import { UserModel } from '../../../models/account/user' 1import { UserModel } from '../../../models/account/user'
2import { PickWith, PickWithOpt } from '../../utils' 2import { PickWith, PickWithOpt } from '@shared/core-utils'
3import { 3import {
4 MAccount, 4 MAccount,
5 MAccountDefault, 5 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 @@
1import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' 1import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update'
2import { PickWith } from '@server/types/utils' 2import { PickWith } from '@shared/core-utils'
3import { MVideoAPWithoutCaption, MVideoWithBlacklistLight } from './video' 3import { MVideoAPWithoutCaption, MVideoWithBlacklistLight } from './video'
4 4
5type Use<K extends keyof ScheduleVideoUpdateModel, M> = PickWith<ScheduleVideoUpdateModel, K, M> 5type Use<K extends keyof ScheduleVideoUpdateModel, M> = PickWith<ScheduleVideoUpdateModel, K, M>
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 @@
1import { VideoAbuseModel } from '../../../models/video/video-abuse' 1import { VideoAbuseModel } from '../../../models/video/video-abuse'
2import { PickWith } from '../../utils' 2import { PickWith } from '@shared/core-utils'
3import { MVideoAccountLightBlacklistAllFiles, MVideo } from './video' 3import { MVideoAccountLightBlacklistAllFiles, MVideo } from './video'
4import { MAccountDefault, MAccountFormattable } from '../account' 4import { MAccountDefault, MAccountFormattable } from '../account'
5 5
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 @@
1import { VideoBlacklistModel } from '../../../models/video/video-blacklist' 1import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
2import { PickWith } from '@server/types/utils' 2import { PickWith } from '@shared/core-utils'
3import { MVideo, MVideoFormattable } from './video' 3import { MVideo, MVideoFormattable } from './video'
4 4
5type Use<K extends keyof VideoBlacklistModel, M> = PickWith<VideoBlacklistModel, K, M> 5type Use<K extends keyof VideoBlacklistModel, M> = PickWith<VideoBlacklistModel, K, M>
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 @@
1import { VideoCaptionModel } from '../../../models/video/video-caption' 1import { VideoCaptionModel } from '../../../models/video/video-caption'
2import { FunctionProperties, PickWith } from '@server/types/utils' 2import { FunctionProperties, PickWith } from '@shared/core-utils'
3import { MVideo, MVideoUUID } from './video' 3import { MVideo, MVideoUUID } from './video'
4 4
5type Use<K extends keyof VideoCaptionModel, M> = PickWith<VideoCaptionModel, K, M> 5type Use<K extends keyof VideoCaptionModel, M> = PickWith<VideoCaptionModel, K, M>
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 @@
1import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership' 1import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership'
2import { PickWith } from '@server/types/utils' 2import { PickWith } from '@shared/core-utils'
3import { MAccountDefault, MAccountFormattable } from '../account/account' 3import { MAccountDefault, MAccountFormattable } from '../account/account'
4import { MVideo, MVideoWithAllFiles } from './video' 4import { MVideo, MVideoWithAllFiles } from './video'
5 5
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 @@
1import { FunctionProperties, PickWith, PickWithOpt } from '../../utils' 1import { FunctionProperties, PickWith, PickWithOpt } from '@shared/core-utils'
2import { VideoChannelModel } from '../../../models/video/video-channel' 2import { VideoChannelModel } from '../../../models/video/video-channel'
3import { 3import {
4 MAccountActor, 4 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 @@
1import { VideoCommentModel } from '../../../models/video/video-comment' 1import { VideoCommentModel } from '../../../models/video/video-comment'
2import { PickWith, PickWithOpt } from '../../utils' 2import { PickWith, PickWithOpt } from '@shared/core-utils'
3import { MAccountDefault, MAccountFormattable, MAccountUrl } from '../account' 3import { MAccountDefault, MAccountFormattable, MAccountUrl } from '../account'
4import { MVideoAccountLight, MVideoFeed, MVideoIdUrl, MVideoUrl } from './video' 4import { MVideoAccountLight, MVideoFeed, MVideoIdUrl, MVideoUrl } from './video'
5 5
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 @@
1import { VideoFileModel } from '../../../models/video/video-file' 1import { VideoFileModel } from '../../../models/video/video-file'
2import { PickWith, PickWithOpt } from '../../utils' 2import { PickWith, PickWithOpt } from '@shared/core-utils'
3import { MVideo, MVideoUUID } from './video' 3import { MVideo, MVideoUUID } from './video'
4import { MVideoRedundancy, MVideoRedundancyFileUrl } from './video-redundancy' 4import { MVideoRedundancy, MVideoRedundancyFileUrl } from './video-redundancy'
5import { MStreamingPlaylistVideo, MStreamingPlaylist } from './video-streaming-playlist' 5import { 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 @@
1import { VideoImportModel } from '@server/models/video/video-import' 1import { VideoImportModel } from '@server/models/video/video-import'
2import { PickWith, PickWithOpt } from '@server/types/utils' 2import { PickWith, PickWithOpt } from '@shared/core-utils'
3import { MVideo, MVideoAccountLight, MVideoFormattable, MVideoTag, MVideoThumbnail, MVideoWithFile } from './video' 3import { MVideo, MVideoAccountLight, MVideoFormattable, MVideoTag, MVideoThumbnail, MVideoWithFile } from './video'
4import { MUser } from '../user/user' 4import { MUser } from '../user/user'
5 5
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 @@
1import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element' 1import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element'
2import { PickWith } from '@server/types/utils' 2import { PickWith } from '@shared/core-utils'
3import { MVideoFormattable, MVideoThumbnail, MVideoUrl } from './video' 3import { MVideoFormattable, MVideoThumbnail, MVideoUrl } from './video'
4import { MVideoPlaylistPrivacy } from './video-playlist' 4import { MVideoPlaylistPrivacy } from './video-playlist'
5 5
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 @@
1import { VideoPlaylistModel } from '../../../models/video/video-playlist' 1import { VideoPlaylistModel } from '../../../models/video/video-playlist'
2import { PickWith } from '../../utils' 2import { PickWith } from '@shared/core-utils'
3import { MAccount, MAccountDefault, MAccountSummary, MAccountSummaryFormattable } from '../account' 3import { MAccount, MAccountDefault, MAccountSummary, MAccountSummaryFormattable } from '../account'
4import { MThumbnail } from './thumbnail' 4import { MThumbnail } from './thumbnail'
5import { MChannelDefault, MChannelSummary, MChannelSummaryFormattable, MChannelUrl } from './video-channels' 5import { 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 @@
1import { AccountVideoRateModel } from '@server/models/account/account-video-rate' 1import { AccountVideoRateModel } from '@server/models/account/account-video-rate'
2import { PickWith } from '@server/types/utils' 2import { PickWith } from '@shared/core-utils'
3import { MAccountAudience, MAccountUrl } from '../account/account' 3import { MAccountAudience, MAccountUrl } from '../account/account'
4import { MVideo, MVideoFormattable } from './video' 4import { MVideo, MVideoFormattable } from './video'
5 5
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 @@
1import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' 1import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
2import { PickWith, PickWithOpt } from '@server/types/utils' 2import { PickWith, PickWithOpt } from '@shared/core-utils'
3import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' 3import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist'
4import { VideoFileModel } from '@server/models/video/video-file' 4import { VideoFileModel } from '@server/models/video/video-file'
5import { MVideoFile, MVideoFileVideo } from './video-file' 5import { 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 @@
1import { VideoShareModel } from '../../../models/video/video-share' 1import { VideoShareModel } from '../../../models/video/video-share'
2import { PickWith } from '../../utils' 2import { PickWith } from '@shared/core-utils'
3import { MActorDefault } from '../account' 3import { MActorDefault } from '../account'
4import { MVideo } from './video' 4import { MVideo } from './video'
5 5
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 @@
1import { VideoStreamingPlaylistModel } from '../../../models/video/video-streaming-playlist' 1import { VideoStreamingPlaylistModel } from '../../../models/video/video-streaming-playlist'
2import { PickWith, PickWithOpt } from '../../utils' 2import { PickWith, PickWithOpt } from '@shared/core-utils'
3import { MVideoRedundancyFileUrl, MVideoRedundancy } from './video-redundancy' 3import { MVideoRedundancyFileUrl, MVideoRedundancy } from './video-redundancy'
4import { MVideo } from './video' 4import { MVideo } from './video'
5import { MVideoFile } from './video-file' 5import { 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 @@
1import { VideoModel } from '../../../models/video/video' 1import { VideoModel } from '../../../models/video/video'
2import { PickWith, PickWithOpt } from '../../utils' 2import { PickWith, PickWithOpt } from '@shared/core-utils'
3import { 3import {
4 MChannelAccountDefault, 4 MChannelAccountDefault,
5 MChannelAccountLight, 5 MChannelAccountLight,
diff --git a/server/typings/plugins/index.d.ts b/server/types/plugins/index.ts
index 9570579ef..de30ff2ab 100644
--- a/server/typings/plugins/index.d.ts
+++ b/server/types/plugins/index.ts
@@ -1,2 +1,3 @@
1export * from './register-server-option.model'
2export * from './plugin-library.model' 1export * from './plugin-library.model'
2export * from './register-server-auth.model'
3export * from './register-server-option.model'
diff --git a/server/typings/plugins/plugin-library.model.ts b/server/types/plugins/plugin-library.model.ts
index 5b517ee9f..5b517ee9f 100644
--- a/server/typings/plugins/plugin-library.model.ts
+++ b/server/types/plugins/plugin-library.model.ts
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 @@
1import * as express from 'express'
2import { UserRole } from '@shared/models'
3import { MOAuthToken, MUser } from '../models'
4
5export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions
6
7export interface RegisterServerAuthenticatedResult {
8 username: string
9 email: string
10 role?: UserRole
11 displayName?: string
12}
13
14export interface RegisterServerExternalAuthenticatedResult extends RegisterServerAuthenticatedResult {
15 req: express.Request
16 res: express.Response
17}
18
19interface RegisterServerAuthBase {
20 // Authentication name (a plugin can register multiple auth strategies)
21 authName: string
22
23 // Called by PeerTube when a user from your plugin logged out
24 onLogout?(user: MUser): void
25
26 // Your plugin can hook PeerTube access/refresh token validity
27 // So you can control for your plugin the user session lifetime
28 hookTokenValidity?(options: { token: MOAuthToken, type: 'access' | 'refresh' }): Promise<{ valid: boolean }>
29}
30
31export interface RegisterServerAuthPassOptions extends RegisterServerAuthBase {
32 // Weight of this authentication so PeerTube tries the auth methods in DESC weight order
33 getWeight(): number
34
35 // Used by PeerTube to login a user
36 // Returns null if the login failed, or { username, email } on success
37 login(body: {
38 id: string
39 password: string
40 }): Promise<RegisterServerAuthenticatedResult | null>
41}
42
43export interface RegisterServerAuthExternalOptions extends RegisterServerAuthBase {
44 // Will be displayed in a block next to the login form
45 authDisplayName: () => string
46
47 onAuthRequest: (req: express.Request, res: express.Response) => void
48}
49
50export interface RegisterServerAuthExternalResult {
51 userAuthenticated (options: RegisterServerExternalAuthenticatedResult): void
52}
diff --git a/server/typings/plugins/register-server-option.model.ts b/server/types/plugins/register-server-option.model.ts
index b4594c6cd..74303d383 100644
--- a/server/typings/plugins/register-server-option.model.ts
+++ b/server/types/plugins/register-server-option.model.ts
@@ -2,22 +2,24 @@ import * as Bluebird from 'bluebird'
2import { Router } from 'express' 2import { Router } from 'express'
3import { Logger } from 'winston' 3import { Logger } from 'winston'
4import { ActorModel } from '@server/models/activitypub/actor' 4import { ActorModel } from '@server/models/activitypub/actor'
5import { VideoBlacklistCreate } from '@shared/models' 5import {
6import { PluginPlaylistPrivacyManager } from '@shared/models/plugins/plugin-playlist-privacy-manager.model' 6 PluginPlaylistPrivacyManager,
7import { PluginVideoPrivacyManager } from '@shared/models/plugins/plugin-video-privacy-manager.model' 7 PluginSettingsManager,
8 PluginStorageManager,
9 PluginVideoCategoryManager,
10 PluginVideoLanguageManager,
11 PluginVideoLicenceManager,
12 PluginVideoPrivacyManager,
13 RegisterServerHookOptions,
14 RegisterServerSettingOptions,
15 VideoBlacklistCreate
16} from '@shared/models'
17import { MVideoThumbnail } from '../models'
8import { 18import {
9 RegisterServerAuthExternalOptions, 19 RegisterServerAuthExternalOptions,
10 RegisterServerAuthExternalResult, 20 RegisterServerAuthExternalResult,
11 RegisterServerAuthPassOptions 21 RegisterServerAuthPassOptions
12} from '@shared/models/plugins/register-server-auth.model' 22} from './register-server-auth.model'
13import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model'
14import { PluginStorageManager } from '../../../shared/models/plugins/plugin-storage-manager.model'
15import { PluginVideoCategoryManager } from '../../../shared/models/plugins/plugin-video-category-manager.model'
16import { PluginVideoLanguageManager } from '../../../shared/models/plugins/plugin-video-language-manager.model'
17import { PluginVideoLicenceManager } from '../../../shared/models/plugins/plugin-video-licence-manager.model'
18import { RegisterServerHookOptions } from '../../../shared/models/plugins/register-server-hook.model'
19import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model'
20import { MVideoThumbnail } from '../../types/models'
21 23
22export type PeerTubeHelpers = { 24export type PeerTubeHelpers = {
23 logger: Logger 25 logger: Logger
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 @@
1/* eslint-disable @typescript-eslint/array-type */
2
3export type FunctionPropertyNames<T> = {
4 [K in keyof T]: T[K] extends Function ? K : never
5}[keyof T]
6
7export type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>
8
9export type PickWith<T, KT extends keyof T, V> = {
10 [P in KT]: T[P] extends V ? V : never
11}
12
13export type PickWithOpt<T, KT extends keyof T, V> = {
14 [P in KT]?: T[P] extends V ? V : never
15}
16
17// https://github.com/krzkaczor/ts-essentials Rocks!
18export type DeepPartial<T> = {
19 [P in keyof T]?: T[P] extends Array<infer U>
20 ? Array<DeepPartial<U>>
21 : T[P] extends ReadonlyArray<infer U>
22 ? ReadonlyArray<DeepPartial<U>>
23 : DeepPartial<T[P]>
24}
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 @@
1import { RegisterServerAuthExternalOptions } from '@server/types'
2import {
3 MAccountBlocklist,
4 MActorUrl,
5 MStreamingPlaylist,
6 MVideoChangeOwnershipFull,
7 MVideoFile,
8 MVideoImmutable,
9 MVideoPlaylistFull,
10 MVideoPlaylistFullSummary
11} from '@server/types/models'
12import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token'
13import { MPlugin, MServer, MServerBlocklist } from '@server/types/models/server'
14import { MVideoImportDefault } from '@server/types/models/video/video-import'
15import { MVideoPlaylistElement, MVideoPlaylistElementVideoUrlPlaylistPrivacy } from '@server/types/models/video/video-playlist-element'
16import { MAccountVideoRateAccountVideo } from '@server/types/models/video/video-rate'
17import { UserRole } from '@shared/models'
1import { RegisteredPlugin } from '../../lib/plugins/plugin-manager' 18import { RegisteredPlugin } from '../../lib/plugins/plugin-manager'
2import { 19import {
3 MAccountDefault, 20 MAccountDefault,
@@ -19,17 +36,6 @@ import {
19 MVideoThumbnail, 36 MVideoThumbnail,
20 MVideoWithRights 37 MVideoWithRights
21} from '../../types/models' 38} from '../../types/models'
22import { MVideoPlaylistFull, MVideoPlaylistFullSummary } from '../../types/models/video/video-playlist'
23import { MVideoImportDefault } from '@server/types/models/video/video-import'
24import { MAccountBlocklist, MActorUrl, MStreamingPlaylist, MVideoFile, MVideoImmutable } from '@server/types/models'
25import { MVideoPlaylistElement, MVideoPlaylistElementVideoUrlPlaylistPrivacy } from '@server/types/models/video/video-playlist-element'
26import { MAccountVideoRateAccountVideo } from '@server/types/models/video/video-rate'
27import { MVideoChangeOwnershipFull } from '../../types/models/video/video-change-ownership'
28import { MPlugin, MServer } from '@server/types/models/server'
29import { MServerBlocklist } from '../../types/models/server/server-blocklist'
30import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token'
31import { UserRole } from '@shared/models'
32import { RegisterServerAuthExternalOptions } from '@shared/models/plugins/register-server-auth.model'
33 39
34declare module 'express' { 40declare module 'express' {
35 export interface Request { 41 export interface Request {