diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:10:17 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 67ed6552b831df66713bac9e672738796128d33f (patch) | |
tree | 59c97d41e0b49d75a90aa3de987968ab9b1ff447 /shared | |
parent | 0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff) | |
download | PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip |
Reorganize client shared modules
Diffstat (limited to 'shared')
25 files changed, 158 insertions, 95 deletions
diff --git a/shared/core-utils/index.ts b/shared/core-utils/index.ts new file mode 100644 index 000000000..54e233522 --- /dev/null +++ b/shared/core-utils/index.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export * from './logs' | ||
2 | export * from './miscs' | ||
3 | export * from './plugins' | ||
diff --git a/shared/core-utils/logs/index.ts b/shared/core-utils/logs/index.ts new file mode 100644 index 000000000..ceb5d7a7f --- /dev/null +++ b/shared/core-utils/logs/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './logs' | |||
diff --git a/shared/core-utils/miscs/index.ts b/shared/core-utils/miscs/index.ts new file mode 100644 index 000000000..afd147f24 --- /dev/null +++ b/shared/core-utils/miscs/index.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export * from './date' | ||
2 | export * from './miscs' | ||
3 | export * from './types' | ||
diff --git a/shared/core-utils/miscs/types.ts b/shared/core-utils/miscs/types.ts new file mode 100644 index 000000000..bb64dc830 --- /dev/null +++ b/shared/core-utils/miscs/types.ts | |||
@@ -0,0 +1,41 @@ | |||
1 | /* eslint-disable @typescript-eslint/array-type */ | ||
2 | |||
3 | export type FunctionPropertyNames<T> = { | ||
4 | [K in keyof T]: T[K] extends Function ? K : never | ||
5 | }[keyof T] | ||
6 | |||
7 | export type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>> | ||
8 | |||
9 | export type PickWith<T, KT extends keyof T, V> = { | ||
10 | [P in KT]: T[P] extends V ? V : never | ||
11 | } | ||
12 | |||
13 | export 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! | ||
18 | export 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 | } | ||
25 | |||
26 | type Primitive = string | Function | number | boolean | Symbol | undefined | null | ||
27 | export type DeepOmitHelper<T, K extends keyof T> = { | ||
28 | [P in K]: // extra level of indirection needed to trigger homomorhic behavior | ||
29 | T[P] extends infer TP // distribute over unions | ||
30 | ? TP extends Primitive | ||
31 | ? TP // leave primitives and functions alone | ||
32 | : TP extends any[] | ||
33 | ? DeepOmitArray<TP, K> // Array special handling | ||
34 | : DeepOmit<TP, K> | ||
35 | : never | ||
36 | } | ||
37 | export type DeepOmit<T, K> = T extends Primitive ? T : DeepOmitHelper<T, Exclude<keyof T, K>> | ||
38 | |||
39 | export type DeepOmitArray<T extends any[], K> = { | ||
40 | [P in keyof T]: DeepOmit<T[P], K> | ||
41 | } | ||
diff --git a/shared/core-utils/plugins/index.ts b/shared/core-utils/plugins/index.ts new file mode 100644 index 000000000..fc78d3512 --- /dev/null +++ b/shared/core-utils/plugins/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './hooks' | |||
diff --git a/shared/extra-utils/server/config.ts b/shared/extra-utils/server/config.ts index 2b04a0396..3ae1c6e67 100644 --- a/shared/extra-utils/server/config.ts +++ b/shared/extra-utils/server/config.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' | 1 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' |
2 | import { CustomConfig } from '../../models/server/custom-config.model' | 2 | import { CustomConfig } from '../../models/server/custom-config.model' |
3 | import { DeepPartial } from '@server/types/utils' | 3 | import { DeepPartial } from '@shared/core-utils' |
4 | import { merge } from 'lodash' | 4 | import { merge } from 'lodash' |
5 | 5 | ||
6 | function getConfig (url: string) { | 6 | function getConfig (url: string) { |
diff --git a/shared/models/actors/index.ts b/shared/models/actors/index.ts index 8fe437b81..c7a92399d 100644 --- a/shared/models/actors/index.ts +++ b/shared/models/actors/index.ts | |||
@@ -1,2 +1,3 @@ | |||
1 | export * from './account.model' | 1 | export * from './account.model' |
2 | export * from './actor.model' | ||
2 | export * from './follow.model' | 3 | export * from './follow.model' |
diff --git a/shared/models/index.ts b/shared/models/index.ts index b562e04a3..3d4bdedde 100644 --- a/shared/models/index.ts +++ b/shared/models/index.ts | |||
@@ -9,8 +9,9 @@ export * from './videos' | |||
9 | export * from './feeds' | 9 | export * from './feeds' |
10 | export * from './i18n' | 10 | export * from './i18n' |
11 | export * from './overviews' | 11 | export * from './overviews' |
12 | export * from './plugins' | ||
12 | export * from './search' | 13 | export * from './search' |
13 | export * from './server/job.model' | 14 | export * from './server' |
14 | export * from './oauth-client-local.model' | 15 | export * from './oauth-client-local.model' |
15 | export * from './result-list.model' | 16 | export * from './result-list.model' |
16 | export * from './server/server-config.model' | 17 | export * from './server/server-config.model' |
diff --git a/shared/models/plugins/index.ts b/shared/models/plugins/index.ts new file mode 100644 index 000000000..209fca791 --- /dev/null +++ b/shared/models/plugins/index.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | export * from './client-hook.model' | ||
2 | export * from './hook-type.enum' | ||
3 | export * from './install-plugin.model' | ||
4 | export * from './manage-plugin.model' | ||
5 | export * from './peertube-plugin-index-list.model' | ||
6 | export * from './peertube-plugin-index.model' | ||
7 | export * from './peertube-plugin-latest-version.model' | ||
8 | export * from './peertube-plugin.model' | ||
9 | export * from './plugin-client-scope.type' | ||
10 | export * from './plugin-package-json.model' | ||
11 | export * from './plugin-playlist-privacy-manager.model' | ||
12 | export * from './plugin-settings-manager.model' | ||
13 | export * from './plugin-storage-manager.model' | ||
14 | export * from './plugin-translation.model' | ||
15 | export * from './plugin-video-category-manager.model' | ||
16 | export * from './plugin-video-language-manager.model' | ||
17 | export * from './plugin-video-licence-manager.model' | ||
18 | export * from './plugin-video-privacy-manager.model' | ||
19 | export * from './plugin.type' | ||
20 | export * from './public-server.setting' | ||
21 | export * from './register-client-hook.model' | ||
22 | export * from './register-server-hook.model' | ||
23 | export * from './register-server-setting.model' | ||
24 | export * from './server-hook.model' | ||
diff --git a/shared/models/plugins/plugin-playlist-privacy-manager.model.ts b/shared/models/plugins/plugin-playlist-privacy-manager.model.ts index f9630c77f..d1823ef4e 100644 --- a/shared/models/plugins/plugin-playlist-privacy-manager.model.ts +++ b/shared/models/plugins/plugin-playlist-privacy-manager.model.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { VideoPlaylistPrivacy } from '@shared/models' | 1 | import { VideoPlaylistPrivacy } from '../videos/playlist/video-playlist-privacy.model' |
2 | 2 | ||
3 | export interface PluginPlaylistPrivacyManager { | 3 | export interface PluginPlaylistPrivacyManager { |
4 | // PUBLIC = 1, | 4 | // PUBLIC = 1, |
diff --git a/shared/models/plugins/plugin-video-privacy-manager.model.ts b/shared/models/plugins/plugin-video-privacy-manager.model.ts index d602ba297..c0e8117b5 100644 --- a/shared/models/plugins/plugin-video-privacy-manager.model.ts +++ b/shared/models/plugins/plugin-video-privacy-manager.model.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { VideoPrivacy } from '@shared/models' | 1 | import { VideoPrivacy } from '@shared/models/videos/video-privacy.enum' |
2 | 2 | ||
3 | export interface PluginVideoPrivacyManager { | 3 | export interface PluginVideoPrivacyManager { |
4 | // PUBLIC = 1 | 4 | // PUBLIC = 1 |
diff --git a/shared/models/plugins/register-server-auth.model.ts b/shared/models/plugins/register-server-auth.model.ts deleted file mode 100644 index fc6f0f258..000000000 --- a/shared/models/plugins/register-server-auth.model.ts +++ /dev/null | |||
@@ -1,52 +0,0 @@ | |||
1 | import { UserRole } from '@shared/models' | ||
2 | import { MOAuthToken, MUser } from '@server/types/models' | ||
3 | import * as express from 'express' | ||
4 | |||
5 | export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions | ||
6 | |||
7 | export interface RegisterServerAuthenticatedResult { | ||
8 | username: string | ||
9 | email: string | ||
10 | role?: UserRole | ||
11 | displayName?: string | ||
12 | } | ||
13 | |||
14 | export interface RegisterServerExternalAuthenticatedResult extends RegisterServerAuthenticatedResult { | ||
15 | req: express.Request | ||
16 | res: express.Response | ||
17 | } | ||
18 | |||
19 | interface 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 | |||
31 | export 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 | |||
43 | export 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 | |||
50 | export interface RegisterServerAuthExternalResult { | ||
51 | userAuthenticated (options: RegisterServerExternalAuthenticatedResult): void | ||
52 | } | ||
diff --git a/shared/models/search/index.ts b/shared/models/search/index.ts index 28dd95443..e2d0ab620 100644 --- a/shared/models/search/index.ts +++ b/shared/models/search/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | export * from './nsfw-query.model' | 1 | export * from './nsfw-query.model' |
2 | export * from './search-target-query.model' | ||
2 | export * from './videos-search-query.model' | 3 | export * from './videos-search-query.model' |
3 | export * from './video-channels-search-query.model' | 4 | export * from './video-channels-search-query.model' |
diff --git a/shared/models/server/index.ts b/shared/models/server/index.ts index 2bb443d46..b079bc9a0 100644 --- a/shared/models/server/index.ts +++ b/shared/models/server/index.ts | |||
@@ -5,5 +5,6 @@ export * from './custom-config.model' | |||
5 | export * from './debug.model' | 5 | export * from './debug.model' |
6 | export * from './emailer.model' | 6 | export * from './emailer.model' |
7 | export * from './job.model' | 7 | export * from './job.model' |
8 | export * from './log-level.type' | ||
8 | export * from './server-config.model' | 9 | export * from './server-config.model' |
9 | export * from './server-stats.model' | 10 | export * from './server-stats.model' |
diff --git a/shared/models/users/index.ts b/shared/models/users/index.ts index cd07cf320..a9d578054 100644 --- a/shared/models/users/index.ts +++ b/shared/models/users/index.ts | |||
@@ -1,12 +1,14 @@ | |||
1 | export * from './user.model' | ||
2 | export * from './user-create.model' | 1 | export * from './user-create.model' |
2 | export * from './user-flag.model' | ||
3 | export * from './user-login.model' | 3 | export * from './user-login.model' |
4 | export * from './user-notification.model' | ||
5 | export * from './user-notification-setting.model' | 4 | export * from './user-notification-setting.model' |
5 | export * from './user-notification.model' | ||
6 | export * from './user-refresh-token.model' | 6 | export * from './user-refresh-token.model' |
7 | export * from './user-update.model' | 7 | export * from './user-register.model' |
8 | export * from './user-update-me.model' | ||
9 | export * from './user-right.enum' | 8 | export * from './user-right.enum' |
10 | export * from './user-role' | 9 | export * from './user-role' |
10 | export * from './user-update-me.model' | ||
11 | export * from './user-update.model' | ||
11 | export * from './user-video-quota.model' | 12 | export * from './user-video-quota.model' |
12 | export * from './user-watching-video.model' | 13 | export * from './user-watching-video.model' |
14 | export * from './user.model' | ||
diff --git a/shared/models/videos/abuse/index.ts b/shared/models/videos/abuse/index.ts new file mode 100644 index 000000000..bdeef1dad --- /dev/null +++ b/shared/models/videos/abuse/index.ts | |||
@@ -0,0 +1,5 @@ | |||
1 | export * from './video-abuse-create.model' | ||
2 | export * from './video-abuse-state.model' | ||
3 | export * from './video-abuse-update.model' | ||
4 | export * from './video-abuse-video-is.type' | ||
5 | export * from './video-abuse.model' | ||
diff --git a/shared/models/videos/blacklist/index.ts b/shared/models/videos/blacklist/index.ts new file mode 100644 index 000000000..66082be34 --- /dev/null +++ b/shared/models/videos/blacklist/index.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export * from './video-blacklist.model' | ||
2 | export * from './video-blacklist-create.model' | ||
3 | export * from './video-blacklist-update.model' | ||
diff --git a/shared/models/videos/caption/index.ts b/shared/models/videos/caption/index.ts new file mode 100644 index 000000000..2a5ff512d --- /dev/null +++ b/shared/models/videos/caption/index.ts | |||
@@ -0,0 +1,2 @@ | |||
1 | export * from './video-caption.model' | ||
2 | export * from './video-caption-update.model' | ||
diff --git a/shared/models/videos/channel/index.ts b/shared/models/videos/channel/index.ts new file mode 100644 index 000000000..9dbaa42da --- /dev/null +++ b/shared/models/videos/channel/index.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export * from './video-channel-create.model' | ||
2 | export * from './video-channel-update.model' | ||
3 | export * from './video-channel.model' | ||
diff --git a/shared/models/videos/import/index.ts b/shared/models/videos/import/index.ts new file mode 100644 index 000000000..8884ee8f2 --- /dev/null +++ b/shared/models/videos/import/index.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export * from './video-import-create.model' | ||
2 | export * from './video-import-state.enum' | ||
3 | export * from './video-import.model' | ||
diff --git a/shared/models/videos/index.ts b/shared/models/videos/index.ts index 58bd1ebd7..e1d96b40a 100644 --- a/shared/models/videos/index.ts +++ b/shared/models/videos/index.ts | |||
@@ -1,41 +1,38 @@ | |||
1 | export * from './rate/user-video-rate-update.model' | 1 | export * from './abuse' |
2 | export * from './rate/user-video-rate.model' | 2 | export * from './blacklist' |
3 | export * from './rate/account-video-rate.model' | 3 | export * from './caption' |
4 | export * from './rate/user-video-rate.type' | 4 | export * from './channel' |
5 | export * from './abuse/video-abuse-state.model' | 5 | export * from './import' |
6 | export * from './abuse/video-abuse-create.model' | 6 | export * from './playlist' |
7 | export * from './abuse/video-abuse-reason.model' | 7 | export * from './rate' |
8 | export * from './abuse/video-abuse.model' | 8 | |
9 | export * from './abuse/video-abuse-update.model' | 9 | export * from './nsfw-policy.type' |
10 | export * from './blacklist/video-blacklist.model' | 10 | |
11 | export * from './blacklist/video-blacklist-create.model' | 11 | export * from './thumbnail.type' |
12 | export * from './blacklist/video-blacklist-update.model' | 12 | |
13 | export * from './channel/video-channel-create.model' | 13 | export * from './video-change-ownership-accept.model' |
14 | export * from './channel/video-channel-update.model' | ||
15 | export * from './channel/video-channel.model' | ||
16 | export * from './playlist/video-playlist-create.model' | ||
17 | export * from './playlist/video-playlist-element-create.model' | ||
18 | export * from './playlist/video-playlist-element-update.model' | ||
19 | export * from './playlist/video-playlist-privacy.model' | ||
20 | export * from './playlist/video-playlist-type.model' | ||
21 | export * from './playlist/video-playlist-update.model' | ||
22 | export * from './playlist/video-playlist.model' | ||
23 | export * from './playlist/video-playlist-element.model' | ||
24 | export * from './video-change-ownership.model' | ||
25 | export * from './video-change-ownership-create.model' | 14 | export * from './video-change-ownership-create.model' |
15 | export * from './video-change-ownership.model' | ||
16 | |||
17 | export * from './video-comment.model' | ||
18 | export * from './video-constant.model' | ||
26 | export * from './video-create.model' | 19 | export * from './video-create.model' |
20 | export * from './video-file-metadata' | ||
27 | export * from './video-file.model' | 21 | export * from './video-file.model' |
22 | |||
28 | export * from './video-privacy.enum' | 23 | export * from './video-privacy.enum' |
24 | export * from './video-query.type' | ||
29 | export * from './video-rate.type' | 25 | export * from './video-rate.type' |
30 | export * from './video-resolution.enum' | 26 | export * from './video-resolution.enum' |
31 | export * from './video-update.model' | 27 | |
32 | export * from './video.model' | 28 | export * from './video-schedule-update.model' |
33 | export * from './video-query.type' | 29 | export * from './video-sort-field.type' |
34 | export * from './video-state.enum' | 30 | export * from './video-state.enum' |
31 | |||
32 | export * from './video-streaming-playlist.model' | ||
33 | export * from './video-streaming-playlist.type' | ||
34 | |||
35 | export * from './video-transcoding-fps.model' | 35 | export * from './video-transcoding-fps.model' |
36 | export * from './caption/video-caption.model' | 36 | |
37 | export * from './caption/video-caption-update.model' | 37 | export * from './video-update.model' |
38 | export * from './import/video-import-create.model' | 38 | export * from './video.model' |
39 | export * from './import/video-import-state.enum' | ||
40 | export * from './import/video-import.model' | ||
41 | export * from './video-constant.model' | ||
diff --git a/shared/models/videos/playlist/index.ts b/shared/models/videos/playlist/index.ts new file mode 100644 index 000000000..99f7e9bab --- /dev/null +++ b/shared/models/videos/playlist/index.ts | |||
@@ -0,0 +1,10 @@ | |||
1 | export * from './video-exist-in-playlist.model' | ||
2 | export * from './video-playlist-create.model' | ||
3 | export * from './video-playlist-element-create.model' | ||
4 | export * from './video-playlist-element-update.model' | ||
5 | export * from './video-playlist-element.model' | ||
6 | export * from './video-playlist-privacy.model' | ||
7 | export * from './video-playlist-reorder.model' | ||
8 | export * from './video-playlist-type.model' | ||
9 | export * from './video-playlist-update.model' | ||
10 | export * from './video-playlist.model' | ||
diff --git a/shared/models/videos/rate/index.ts b/shared/models/videos/rate/index.ts new file mode 100644 index 000000000..06aa691bd --- /dev/null +++ b/shared/models/videos/rate/index.ts | |||
@@ -0,0 +1,5 @@ | |||
1 | |||
2 | export * from './user-video-rate-update.model' | ||
3 | export * from './user-video-rate.model' | ||
4 | export * from './account-video-rate.model' | ||
5 | export * from './user-video-rate.type' | ||
diff --git a/shared/models/videos/video-file-metadata.ts b/shared/models/videos/video-file-metadata.ts index 15683cacf..010bf7cf5 100644 --- a/shared/models/videos/video-file-metadata.ts +++ b/shared/models/videos/video-file-metadata.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { FfprobeData } from "fluent-ffmpeg" | 1 | import { FfprobeData } from 'fluent-ffmpeg' |
2 | import { DeepOmit } from "@server/models/utils" | 2 | import { DeepOmit } from '../../core-utils' |
3 | 3 | ||
4 | export type VideoFileMetadataModel = DeepOmit<FfprobeData, 'filename'> | 4 | export type VideoFileMetadataModel = DeepOmit<FfprobeData, 'filename'> |
5 | 5 | ||
diff --git a/shared/models/videos/video-sort-field.type.ts b/shared/models/videos/video-sort-field.type.ts new file mode 100644 index 000000000..f2e70f5fa --- /dev/null +++ b/shared/models/videos/video-sort-field.type.ts | |||
@@ -0,0 +1,8 @@ | |||
1 | export type VideoSortField = | ||
2 | 'name' | '-name' | | ||
3 | 'duration' | '-duration' | | ||
4 | 'publishedAt' | '-publishedAt' | | ||
5 | 'createdAt' | '-createdAt' | | ||
6 | 'views' | '-views' | | ||
7 | 'likes' | '-likes' | | ||
8 | 'trending' | '-trending' | ||