2021-06-03 11:33:44 -04:00
|
|
|
import { VideoModel } from '@server/models/video/video'
|
|
|
|
import {
|
|
|
|
MVideoAccountLightBlacklistAllFiles,
|
2021-06-11 03:57:19 -04:00
|
|
|
MVideoFormattableDetails,
|
2021-06-03 11:33:44 -04:00
|
|
|
MVideoFullLight,
|
2021-06-11 08:09:33 -04:00
|
|
|
MVideoId,
|
2021-06-03 11:33:44 -04:00
|
|
|
MVideoImmutable,
|
2021-06-11 08:26:37 -04:00
|
|
|
MVideoThumbnail
|
2021-06-03 11:33:44 -04:00
|
|
|
} from '@server/types/models'
|
2021-06-11 03:57:19 -04:00
|
|
|
import { Hooks } from '../plugins/hooks'
|
2021-06-03 11:33:44 -04:00
|
|
|
|
2021-06-11 08:09:33 -04:00
|
|
|
type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'id' | 'none' | 'only-immutable-attributes'
|
2021-06-03 11:33:44 -04:00
|
|
|
|
2021-06-11 03:57:19 -04:00
|
|
|
function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails>
|
2021-06-03 12:10:56 -04: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 08:09:33 -04:00
|
|
|
function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoId>
|
2021-06-03 12:10:56 -04:00
|
|
|
function loadVideo (
|
2021-06-03 11:33:44 -04:00
|
|
|
id: number | string,
|
2021-06-03 12:10:56 -04:00
|
|
|
fetchType: VideoLoadType,
|
2021-06-03 11:33:44 -04:00
|
|
|
userId?: number
|
2021-06-11 08:09:33 -04:00
|
|
|
): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable>
|
2021-06-03 12:10:56 -04:00
|
|
|
function loadVideo (
|
2021-06-03 11:33:44 -04:00
|
|
|
id: number | string,
|
2021-06-03 12:10:56 -04:00
|
|
|
fetchType: VideoLoadType,
|
2021-06-03 11:33:44 -04:00
|
|
|
userId?: number
|
2021-06-11 08:09:33 -04:00
|
|
|
): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> {
|
2021-06-11 03:57:19 -04:00
|
|
|
|
|
|
|
if (fetchType === 'for-api') {
|
|
|
|
return Hooks.wrapPromiseFun(
|
|
|
|
VideoModel.loadForGetAPI,
|
|
|
|
{ id, userId },
|
|
|
|
'filter:api.video.get.result'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-06-03 11:33:44 -04: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 12:10:56 -04:00
|
|
|
type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
|
2021-06-03 11:33:44 -04:00
|
|
|
|
2021-06-03 12:10:56 -04: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 11:33:44 -04:00
|
|
|
url: string,
|
2021-06-03 12:10:56 -04:00
|
|
|
fetchType: VideoLoadByUrlType
|
2021-06-03 11:33:44 -04:00
|
|
|
): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
|
2021-06-03 12:10:56 -04:00
|
|
|
function loadVideoByUrl (
|
2021-06-03 11:33:44 -04:00
|
|
|
url: string,
|
2021-06-03 12:10:56 -04:00
|
|
|
fetchType: VideoLoadByUrlType
|
2021-06-03 11:33:44 -04: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 12:10:56 -04:00
|
|
|
VideoLoadType,
|
|
|
|
VideoLoadByUrlType,
|
|
|
|
|
|
|
|
loadVideo,
|
|
|
|
loadVideoByUrl
|
2021-06-03 11:33:44 -04:00
|
|
|
}
|