diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-03 17:33:44 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-03 18:03:36 +0200 |
commit | 10363c74c1d869f0e0c7bc4d0367b1f34d1bb6a4 (patch) | |
tree | 008f8dad8032684f46105a261b27b2d6f05b36eb /server/helpers/video.ts | |
parent | 5e08989ede1a340b9edb94465a11b1e04bf24094 (diff) | |
download | PeerTube-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/helpers/video.ts')
-rw-r--r-- | server/helpers/video.ts | 65 |
1 files changed, 1 insertions, 64 deletions
diff --git a/server/helpers/video.ts b/server/helpers/video.ts index 7c510f474..d3445bed5 100644 --- a/server/helpers/video.ts +++ b/server/helpers/video.ts | |||
@@ -1,66 +1,7 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import { CONFIG } from '@server/initializers/config' | 2 | import { CONFIG } from '@server/initializers/config' |
3 | import { | 3 | import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models' |
4 | isStreamingPlaylist, | ||
5 | MStreamingPlaylistVideo, | ||
6 | MVideo, | ||
7 | MVideoAccountLightBlacklistAllFiles, | ||
8 | MVideoFullLight, | ||
9 | MVideoIdThumbnail, | ||
10 | MVideoImmutable, | ||
11 | MVideoThumbnail, | ||
12 | MVideoWithRights | ||
13 | } from '@server/types/models' | ||
14 | import { VideoPrivacy, VideoState } from '@shared/models' | 4 | import { VideoPrivacy, VideoState } from '@shared/models' |
15 | import { VideoModel } from '../models/video/video' | ||
16 | |||
17 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' | ||
18 | |||
19 | function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight> | ||
20 | function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | ||
21 | function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail> | ||
22 | function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights> | ||
23 | function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail> | ||
24 | function fetchVideo ( | ||
25 | id: number | string, | ||
26 | fetchType: VideoFetchType, | ||
27 | userId?: number | ||
28 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> | ||
29 | function fetchVideo ( | ||
30 | id: number | string, | ||
31 | fetchType: VideoFetchType, | ||
32 | userId?: number | ||
33 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> { | ||
34 | if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) | ||
35 | |||
36 | if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id) | ||
37 | |||
38 | if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id) | ||
39 | |||
40 | if (fetchType === 'only-video') return VideoModel.load(id) | ||
41 | |||
42 | if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id) | ||
43 | } | ||
44 | |||
45 | type VideoFetchByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' | ||
46 | |||
47 | function fetchVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles> | ||
48 | function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | ||
49 | function fetchVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail> | ||
50 | function fetchVideoByUrl ( | ||
51 | url: string, | ||
52 | fetchType: VideoFetchByUrlType | ||
53 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> | ||
54 | function fetchVideoByUrl ( | ||
55 | url: string, | ||
56 | fetchType: VideoFetchByUrlType | ||
57 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> { | ||
58 | if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) | ||
59 | |||
60 | if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url) | ||
61 | |||
62 | if (fetchType === 'only-video') return VideoModel.loadByUrl(url) | ||
63 | } | ||
64 | 5 | ||
65 | function getVideoWithAttributes (res: Response) { | 6 | function getVideoWithAttributes (res: Response) { |
66 | return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights | 7 | return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights |
@@ -100,11 +41,7 @@ function getExtFromMimetype (mimeTypes: { [id: string]: string | string[] }, mim | |||
100 | } | 41 | } |
101 | 42 | ||
102 | export { | 43 | export { |
103 | VideoFetchType, | ||
104 | VideoFetchByUrlType, | ||
105 | fetchVideo, | ||
106 | getVideoWithAttributes, | 44 | getVideoWithAttributes, |
107 | fetchVideoByUrl, | ||
108 | extractVideo, | 45 | extractVideo, |
109 | getExtFromMimetype, | 46 | getExtFromMimetype, |
110 | isStateForFederation, | 47 | isStateForFederation, |