video-blacklist.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { Response } from 'express'
  2. import * as validator from 'validator'
  3. import { exists } from './misc'
  4. import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
  5. import { VideoBlacklistModel } from '../../models/video/video-blacklist'
  6. import { VideoBlacklistType } from '../../../shared/models/videos'
  7. const VIDEO_BLACKLIST_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_BLACKLIST
  8. function isVideoBlacklistReasonValid (value: string) {
  9. return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON)
  10. }
  11. async function doesVideoBlacklistExist (videoId: number, res: Response) {
  12. const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId)
  13. if (videoBlacklist === null) {
  14. res.status(404)
  15. .json({ error: 'Blacklisted video not found' })
  16. .end()
  17. return false
  18. }
  19. res.locals.videoBlacklist = videoBlacklist
  20. return true
  21. }
  22. function isVideoBlacklistTypeValid (value: any) {
  23. return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined
  24. }
  25. // ---------------------------------------------------------------------------
  26. export {
  27. isVideoBlacklistReasonValid,
  28. isVideoBlacklistTypeValid,
  29. doesVideoBlacklistExist
  30. }