diff options
Diffstat (limited to 'server/lib/model-loaders')
-rw-r--r-- | server/lib/model-loaders/actor.ts | 17 | ||||
-rw-r--r-- | server/lib/model-loaders/index.ts | 2 | ||||
-rw-r--r-- | server/lib/model-loaders/video.ts | 73 |
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 | |||
2 | import { ActorModel } from '../../models/actor/actor' | ||
3 | import { MActorAccountChannelId, MActorFull } from '../../types/models' | ||
4 | |||
5 | type ActorLoadByUrlType = 'all' | 'association-ids' | ||
6 | |||
7 | function 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 | |||
13 | export { | ||
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 @@ | |||
1 | export * from './actor' | ||
2 | export * 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 @@ | |||
1 | import { VideoModel } from '@server/models/video/video' | ||
2 | import { | ||
3 | MVideoAccountLightBlacklistAllFiles, | ||
4 | MVideoFormattableDetails, | ||
5 | MVideoFullLight, | ||
6 | MVideoId, | ||
7 | MVideoImmutable, | ||
8 | MVideoThumbnail | ||
9 | } from '@server/types/models' | ||
10 | import { Hooks } from '../plugins/hooks' | ||
11 | |||
12 | type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'id' | 'none' | 'only-immutable-attributes' | ||
13 | |||
14 | function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails> | ||
15 | function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight> | ||
16 | function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | ||
17 | function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail> | ||
18 | function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoId> | ||
19 | function loadVideo ( | ||
20 | id: number | string, | ||
21 | fetchType: VideoLoadType, | ||
22 | userId?: number | ||
23 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> | ||
24 | function 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 | |||
47 | type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' | ||
48 | |||
49 | function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles> | ||
50 | function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | ||
51 | function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail> | ||
52 | function loadVideoByUrl ( | ||
53 | url: string, | ||
54 | fetchType: VideoLoadByUrlType | ||
55 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> | ||
56 | function 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 | |||
67 | export { | ||
68 | VideoLoadType, | ||
69 | VideoLoadByUrlType, | ||
70 | |||
71 | loadVideo, | ||
72 | loadVideoByUrl | ||
73 | } | ||