2
1

video-playlists.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import * as express from 'express'
  2. import { VideoPlaylistModel } from '../../models/video/video-playlist'
  3. import { MVideoPlaylist } from '../../typings/models/video/video-playlist'
  4. export type VideoPlaylistFetchType = 'summary' | 'all'
  5. async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: VideoPlaylistFetchType = 'summary') {
  6. if (fetchType === 'summary') {
  7. const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined)
  8. res.locals.videoPlaylistSummary = videoPlaylist
  9. return handleVideoPlaylist(videoPlaylist, res)
  10. }
  11. const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined)
  12. res.locals.videoPlaylistFull = videoPlaylist
  13. return handleVideoPlaylist(videoPlaylist, res)
  14. }
  15. // ---------------------------------------------------------------------------
  16. export {
  17. doesVideoPlaylistExist
  18. }
  19. // ---------------------------------------------------------------------------
  20. function handleVideoPlaylist (videoPlaylist: MVideoPlaylist, res: express.Response) {
  21. if (!videoPlaylist) {
  22. res.status(404)
  23. .json({ error: 'Video playlist not found' })
  24. .end()
  25. return false
  26. }
  27. return true
  28. }