video.ts 921 B

123456789101112131415161718192021222324252627
  1. import { VideoModel } from '../models/video/video'
  2. type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none'
  3. function fetchVideo (id: number | string, fetchType: VideoFetchType, userId?: number) {
  4. if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
  5. if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id)
  6. if (fetchType === 'only-video') return VideoModel.load(id)
  7. if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
  8. }
  9. type VideoFetchByUrlType = 'all' | 'only-video'
  10. function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType) {
  11. if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
  12. if (fetchType === 'only-video') return VideoModel.loadByUrl(url)
  13. }
  14. export {
  15. VideoFetchType,
  16. VideoFetchByUrlType,
  17. fetchVideo,
  18. fetchVideoByUrl
  19. }