aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/model-loaders
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-03 17:33:44 +0200
committerChocobozzz <me@florianbigard.com>2021-06-03 18:03:36 +0200
commit10363c74c1d869f0e0c7bc4d0367b1f34d1bb6a4 (patch)
tree008f8dad8032684f46105a261b27b2d6f05b36eb /server/lib/model-loaders
parent5e08989ede1a340b9edb94465a11b1e04bf24094 (diff)
downloadPeerTube-10363c74c1d869f0e0c7bc4d0367b1f34d1bb6a4.tar.gz
PeerTube-10363c74c1d869f0e0c7bc4d0367b1f34d1bb6a4.tar.zst
PeerTube-10363c74c1d869f0e0c7bc4d0367b1f34d1bb6a4.zip
Move middleware utils in middlewares
helpers modules should not import models
Diffstat (limited to 'server/lib/model-loaders')
-rw-r--r--server/lib/model-loaders/actor.ts16
-rw-r--r--server/lib/model-loaders/index.ts2
-rw-r--r--server/lib/model-loaders/video.ts64
3 files changed, 82 insertions, 0 deletions
diff --git a/server/lib/model-loaders/actor.ts b/server/lib/model-loaders/actor.ts
new file mode 100644
index 000000000..234cb344f
--- /dev/null
+++ b/server/lib/model-loaders/actor.ts
@@ -0,0 +1,16 @@
1
2import { ActorModel } from '../../models/actor/actor'
3import { MActorAccountChannelId, MActorFull } from '../../types/models'
4
5type ActorFetchByUrlType = 'all' | 'association-ids'
6
7function fetchActorByUrl (url: string, fetchType: ActorFetchByUrlType): Promise<MActorFull | MActorAccountChannelId> {
8 if (fetchType === 'all') return ActorModel.loadByUrlAndPopulateAccountAndChannel(url)
9
10 if (fetchType === 'association-ids') return ActorModel.loadByUrl(url)
11}
12
13export {
14 ActorFetchByUrlType,
15 fetchActorByUrl
16}
diff --git a/server/lib/model-loaders/index.ts b/server/lib/model-loaders/index.ts
new file mode 100644
index 000000000..9e5152cb2
--- /dev/null
+++ b/server/lib/model-loaders/index.ts
@@ -0,0 +1,2 @@
1export * from './actor'
2export * from './video'
diff --git a/server/lib/model-loaders/video.ts b/server/lib/model-loaders/video.ts
new file mode 100644
index 000000000..7aaf00e89
--- /dev/null
+++ b/server/lib/model-loaders/video.ts
@@ -0,0 +1,64 @@
1import { VideoModel } from '@server/models/video/video'
2import {
3 MVideoAccountLightBlacklistAllFiles,
4 MVideoFullLight,
5 MVideoIdThumbnail,
6 MVideoImmutable,
7 MVideoThumbnail,
8 MVideoWithRights
9} from '@server/types/models'
10
11type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes'
12
13function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
14function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
15function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
16function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights>
17function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail>
18function fetchVideo (
19 id: number | string,
20 fetchType: VideoFetchType,
21 userId?: number
22): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable>
23function fetchVideo (
24 id: number | string,
25 fetchType: VideoFetchType,
26 userId?: number
27): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> {
28 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
29
30 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
31
32 if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id)
33
34 if (fetchType === 'only-video') return VideoModel.load(id)
35
36 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
37}
38
39type VideoFetchByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
40
41function fetchVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
42function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
43function fetchVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
44function fetchVideoByUrl (
45 url: string,
46 fetchType: VideoFetchByUrlType
47): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
48function fetchVideoByUrl (
49 url: string,
50 fetchType: VideoFetchByUrlType
51): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
52 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
53
54 if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
55
56 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)
57}
58
59export {
60 VideoFetchType,
61 VideoFetchByUrlType,
62 fetchVideo,
63 fetchVideoByUrl
64}