2021-06-03 10:33:44 -05:00
|
|
|
import { VideoModel } from '@server/models/video/video'
|
|
|
|
import {
|
|
|
|
MVideoAccountLightBlacklistAllFiles,
|
2021-06-11 02:57:19 -05:00
|
|
|
MVideoFormattableDetails,
|
2021-06-03 10:33:44 -05:00
|
|
|
MVideoFullLight,
|
2021-06-11 07:09:33 -05:00
|
|
|
MVideoId,
|
2021-06-03 10:33:44 -05:00
|
|
|
MVideoImmutable,
|
|
|
|
MVideoThumbnail,
|
|
|
|
MVideoWithRights
|
|
|
|
} from '@server/types/models'
|
2021-06-11 02:57:19 -05:00
|
|
|
import { Hooks } from '../plugins/hooks'
|
2021-06-03 10:33:44 -05:00
|
|
|
|
2021-06-11 07:09:33 -05:00
|
|
|
type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'id' | 'none' | 'only-immutable-attributes'
|
2021-06-03 10:33:44 -05:00
|
|
|
|
2021-06-11 02:57:19 -05:00
|
|
|
function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails>
|
2021-06-03 11:10:56 -05:00
|
|
|
function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
|
|
|
|
function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
|
|
|
|
function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
|
2021-06-11 07:09:33 -05:00
|
|
|
function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoId>
|
2021-06-03 11:10:56 -05:00
|
|
|
function loadVideo (
|
2021-06-03 10:33:44 -05:00
|
|
|
id: number | string,
|
2021-06-03 11:10:56 -05:00
|
|
|
fetchType: VideoLoadType,
|
2021-06-03 10:33:44 -05:00
|
|
|
userId?: number
|
2021-06-11 07:09:33 -05:00
|
|
|
): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable>
|
2021-06-03 11:10:56 -05:00
|
|
|
function loadVideo (
|
2021-06-03 10:33:44 -05:00
|
|
|
id: number | string,
|
2021-06-03 11:10:56 -05:00
|
|
|
fetchType: VideoLoadType,
|
2021-06-03 10:33:44 -05:00
|
|
|
userId?: number
|
2021-06-11 07:09:33 -05:00
|
|
|
): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> {
|
2021-06-11 02:57:19 -05:00
|
|
|
|
|
|
|
if (fetchType === 'for-api') {
|
|
|
|
return Hooks.wrapPromiseFun(
|
|
|
|
VideoModel.loadForGetAPI,
|
|
|
|
{ id, userId },
|
|
|
|
'filter:api.video.get.result'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-06-03 10:33:44 -05:00
|
|
|
if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
|
|
|
|
|
|
|
|
if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
|
|
|
|
|
|
|
|
if (fetchType === 'only-video') return VideoModel.load(id)
|
|
|
|
|
|
|
|
if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
|
|
|
|
}
|
|
|
|
|
2021-06-03 11:10:56 -05:00
|
|
|
type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
|
2021-06-03 10:33:44 -05:00
|
|
|
|
2021-06-03 11:10:56 -05:00
|
|
|
function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
|
|
|
|
function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
|
|
|
|
function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
|
|
|
|
function loadVideoByUrl (
|
2021-06-03 10:33:44 -05:00
|
|
|
url: string,
|
2021-06-03 11:10:56 -05:00
|
|
|
fetchType: VideoLoadByUrlType
|
2021-06-03 10:33:44 -05:00
|
|
|
): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
|
2021-06-03 11:10:56 -05:00
|
|
|
function loadVideoByUrl (
|
2021-06-03 10:33:44 -05:00
|
|
|
url: string,
|
2021-06-03 11:10:56 -05:00
|
|
|
fetchType: VideoLoadByUrlType
|
2021-06-03 10:33:44 -05:00
|
|
|
): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
|
|
|
|
if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
|
|
|
|
|
|
|
|
if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
|
|
|
|
|
|
|
|
if (fetchType === 'only-video') return VideoModel.loadByUrl(url)
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
2021-06-03 11:10:56 -05:00
|
|
|
VideoLoadType,
|
|
|
|
VideoLoadByUrlType,
|
|
|
|
|
|
|
|
loadVideo,
|
|
|
|
loadVideoByUrl
|
2021-06-03 10:33:44 -05:00
|
|
|
}
|