diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-20 13:52:49 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-20 14:53:42 +0200 |
commit | 0283eaac2a8e73006c66df3cf5bb9012e37450e5 (patch) | |
tree | 1fb73aeef57f984a77f47828ade23c6365ce8eb0 /server/helpers | |
parent | 96ca24f00e5ae5471dee9ee596489fe50af2b46f (diff) | |
download | PeerTube-0283eaac2a8e73006c66df3cf5bb9012e37450e5.tar.gz PeerTube-0283eaac2a8e73006c66df3cf5bb9012e37450e5.tar.zst PeerTube-0283eaac2a8e73006c66df3cf5bb9012e37450e5.zip |
Cleanup model types
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/middlewares/video-channels.ts | 4 | ||||
-rw-r--r-- | server/helpers/middlewares/videos.ts | 4 | ||||
-rw-r--r-- | server/helpers/video.ts | 19 |
3 files changed, 19 insertions, 8 deletions
diff --git a/server/helpers/middlewares/video-channels.ts b/server/helpers/middlewares/video-channels.ts index 17b7692c5..1595ecd94 100644 --- a/server/helpers/middlewares/video-channels.ts +++ b/server/helpers/middlewares/video-channels.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { VideoChannelModel } from '../../models/video/video-channel' | 2 | import { VideoChannelModel } from '../../models/video/video-channel' |
3 | import { MChannelActorAccountDefault } from '../../typings/models' | 3 | import { MChannelAccountDefault } from '@server/typings/models' |
4 | 4 | ||
5 | async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { | 5 | async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { |
6 | const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) | 6 | const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) |
@@ -28,7 +28,7 @@ export { | |||
28 | doesVideoChannelNameWithHostExist | 28 | doesVideoChannelNameWithHostExist |
29 | } | 29 | } |
30 | 30 | ||
31 | function processVideoChannelExist (videoChannel: MChannelActorAccountDefault, res: express.Response) { | 31 | function processVideoChannelExist (videoChannel: MChannelAccountDefault, res: express.Response) { |
32 | if (!videoChannel) { | 32 | if (!videoChannel) { |
33 | res.status(404) | 33 | res.status(404) |
34 | .json({ error: 'Video channel not found' }) | 34 | .json({ error: 'Video channel not found' }) |
diff --git a/server/helpers/middlewares/videos.ts b/server/helpers/middlewares/videos.ts index 964f0c91a..74f529804 100644 --- a/server/helpers/middlewares/videos.ts +++ b/server/helpers/middlewares/videos.ts | |||
@@ -2,7 +2,7 @@ import { Response } from 'express' | |||
2 | import { fetchVideo, VideoFetchType } from '../video' | 2 | import { fetchVideo, VideoFetchType } from '../video' |
3 | import { UserRight } from '../../../shared/models/users' | 3 | import { UserRight } from '../../../shared/models/users' |
4 | import { VideoChannelModel } from '../../models/video/video-channel' | 4 | import { VideoChannelModel } from '../../models/video/video-channel' |
5 | import { MUser, MUserAccountId, MVideoAccountLight, MVideoFullLight, MVideoWithRights } from '@server/typings/models' | 5 | import { MUser, MUserAccountId, MVideoAccountLight, MVideoFullLight, MVideoThumbnail, MVideoWithRights } from '@server/typings/models' |
6 | 6 | ||
7 | async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { | 7 | async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { |
8 | const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined | 8 | const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined |
@@ -27,7 +27,7 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi | |||
27 | break | 27 | break |
28 | 28 | ||
29 | case 'only-video': | 29 | case 'only-video': |
30 | res.locals.onlyVideo = video | 30 | res.locals.onlyVideo = video as MVideoThumbnail |
31 | break | 31 | break |
32 | 32 | ||
33 | case 'only-video-with-rights': | 33 | case 'only-video-with-rights': |
diff --git a/server/helpers/video.ts b/server/helpers/video.ts index 26a72ac5c..d066e2b1f 100644 --- a/server/helpers/video.ts +++ b/server/helpers/video.ts | |||
@@ -1,6 +1,12 @@ | |||
1 | import { VideoModel } from '../models/video/video' | 1 | import { VideoModel } from '../models/video/video' |
2 | import * as Bluebird from 'bluebird' | 2 | import * as Bluebird from 'bluebird' |
3 | import { MVideoAccountAllFiles, MVideoFullLight, MVideoThumbnail, MVideoWithRights, MVideoIdThumbnail } from '@server/typings/models' | 3 | import { |
4 | MVideoAccountLightBlacklistAllFiles, | ||
5 | MVideoFullLight, | ||
6 | MVideoIdThumbnail, | ||
7 | MVideoThumbnail, | ||
8 | MVideoWithRights | ||
9 | } from '@server/typings/models' | ||
4 | import { Response } from 'express' | 10 | import { Response } from 'express' |
5 | 11 | ||
6 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 12 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' |
@@ -30,10 +36,10 @@ function fetchVideo ( | |||
30 | 36 | ||
31 | type VideoFetchByUrlType = 'all' | 'only-video' | 37 | type VideoFetchByUrlType = 'all' | 'only-video' |
32 | 38 | ||
33 | function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird<MVideoAccountAllFiles> | 39 | function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird<MVideoAccountLightBlacklistAllFiles> |
34 | function fetchVideoByUrl (url: string, fetchType: 'only-video'): Bluebird<MVideoThumbnail> | 40 | function fetchVideoByUrl (url: string, fetchType: 'only-video'): Bluebird<MVideoThumbnail> |
35 | function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird<MVideoAccountAllFiles> | Bluebird<MVideoThumbnail> | 41 | function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail> |
36 | function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird<MVideoAccountAllFiles> | Bluebird<MVideoThumbnail> { | 42 | function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail> { |
37 | if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) | 43 | if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) |
38 | 44 | ||
39 | if (fetchType === 'only-video') return VideoModel.loadByUrl(url) | 45 | if (fetchType === 'only-video') return VideoModel.loadByUrl(url) |
@@ -43,10 +49,15 @@ function getVideo (res: Response) { | |||
43 | return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights || res.locals.videoId | 49 | return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights || res.locals.videoId |
44 | } | 50 | } |
45 | 51 | ||
52 | function getVideoWithAttributes (res: Response) { | ||
53 | return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights | ||
54 | } | ||
55 | |||
46 | export { | 56 | export { |
47 | VideoFetchType, | 57 | VideoFetchType, |
48 | VideoFetchByUrlType, | 58 | VideoFetchByUrlType, |
49 | fetchVideo, | 59 | fetchVideo, |
50 | getVideo, | 60 | getVideo, |
61 | getVideoWithAttributes, | ||
51 | fetchVideoByUrl | 62 | fetchVideoByUrl |
52 | } | 63 | } |