aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/model-loaders
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/model-loaders')
-rw-r--r--server/lib/model-loaders/actor.ts17
-rw-r--r--server/lib/model-loaders/index.ts2
-rw-r--r--server/lib/model-loaders/video.ts73
3 files changed, 92 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..1355d8ee2
--- /dev/null
+++ b/server/lib/model-loaders/actor.ts
@@ -0,0 +1,17 @@
1
2import { ActorModel } from '../../models/actor/actor'
3import { MActorAccountChannelId, MActorFull } from '../../types/models'
4
5type ActorLoadByUrlType = 'all' | 'association-ids'
6
7function loadActorByUrl (url: string, fetchType: ActorLoadByUrlType): 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 ActorLoadByUrlType,
15
16 loadActorByUrl
17}
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..0a3c15ad8
--- /dev/null
+++ b/server/lib/model-loaders/video.ts
@@ -0,0 +1,73 @@
1import { VideoModel } from '@server/models/video/video'
2import {
3 MVideoAccountLightBlacklistAllFiles,
4 MVideoFormattableDetails,
5 MVideoFullLight,
6 MVideoId,
7 MVideoImmutable,
8 MVideoThumbnail
9} from '@server/types/models'
10import { Hooks } from '../plugins/hooks'
11
12type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'id' | 'none' | 'only-immutable-attributes'
13
14function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails>
15function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
16function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
17function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
18function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoId>
19function loadVideo (
20 id: number | string,
21 fetchType: VideoLoadType,
22 userId?: number
23): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable>
24function loadVideo (
25 id: number | string,
26 fetchType: VideoLoadType,
27 userId?: number
28): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> {
29
30 if (fetchType === 'for-api') {
31 return Hooks.wrapPromiseFun(
32 VideoModel.loadForGetAPI,
33 { id, userId },
34 'filter:api.video.get.result'
35 )
36 }
37
38 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
39
40 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
41
42 if (fetchType === 'only-video') return VideoModel.load(id)
43
44 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
45}
46
47type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
48
49function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
50function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
51function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
52function loadVideoByUrl (
53 url: string,
54 fetchType: VideoLoadByUrlType
55): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
56function loadVideoByUrl (
57 url: string,
58 fetchType: VideoLoadByUrlType
59): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
60 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
61
62 if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
63
64 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)
65}
66
67export {
68 VideoLoadType,
69 VideoLoadByUrlType,
70
71 loadVideo,
72 loadVideoByUrl
73}