2
1

config.ts 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import * as express from 'express'
  2. import { body } from 'express-validator/check'
  3. import { isUserNSFWPolicyValid, isUserVideoQuotaValid, isUserVideoQuotaDailyValid } from '../../helpers/custom-validators/users'
  4. import { logger } from '../../helpers/logger'
  5. import { CustomConfig } from '../../../shared/models/server/custom-config.model'
  6. import { Emailer } from '../../lib/emailer'
  7. import { areValidationErrors } from './utils'
  8. const customConfigUpdateValidator = [
  9. body('instance.name').exists().withMessage('Should have a valid instance name'),
  10. body('instance.shortDescription').exists().withMessage('Should have a valid instance short description'),
  11. body('instance.description').exists().withMessage('Should have a valid instance description'),
  12. body('instance.terms').exists().withMessage('Should have a valid instance terms'),
  13. body('instance.defaultClientRoute').exists().withMessage('Should have a valid instance default client route'),
  14. body('instance.defaultNSFWPolicy').custom(isUserNSFWPolicyValid).withMessage('Should have a valid NSFW policy'),
  15. body('instance.customizations.css').exists().withMessage('Should have a valid instance CSS customization'),
  16. body('instance.customizations.javascript').exists().withMessage('Should have a valid instance JavaScript customization'),
  17. body('services.twitter.username').exists().withMessage('Should have a valid twitter username'),
  18. body('services.twitter.whitelisted').isBoolean().withMessage('Should have a valid twitter whitelisted boolean'),
  19. body('cache.previews.size').isInt().withMessage('Should have a valid previews cache size'),
  20. body('cache.captions.size').isInt().withMessage('Should have a valid captions cache size'),
  21. body('signup.enabled').isBoolean().withMessage('Should have a valid signup enabled boolean'),
  22. body('signup.limit').isInt().withMessage('Should have a valid signup limit'),
  23. body('signup.requiresEmailVerification').isBoolean().withMessage('Should have a valid requiresEmailVerification boolean'),
  24. body('admin.email').isEmail().withMessage('Should have a valid administrator email'),
  25. body('contactForm.enabled').isBoolean().withMessage('Should have a valid contact form enabled boolean'),
  26. body('user.videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid video quota'),
  27. body('user.videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily video quota'),
  28. body('transcoding.enabled').isBoolean().withMessage('Should have a valid transcoding enabled boolean'),
  29. body('transcoding.allowAdditionalExtensions').isBoolean().withMessage('Should have a valid additional extensions boolean'),
  30. body('transcoding.threads').isInt().withMessage('Should have a valid transcoding threads number'),
  31. body('transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'),
  32. body('transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'),
  33. body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'),
  34. body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'),
  35. body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'),
  36. body('import.videos.http.enabled').isBoolean().withMessage('Should have a valid import video http enabled boolean'),
  37. body('import.videos.torrent.enabled').isBoolean().withMessage('Should have a valid import video torrent enabled boolean'),
  38. body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'),
  39. body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'),
  40. async (req: express.Request, res: express.Response, next: express.NextFunction) => {
  41. logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body })
  42. if (areValidationErrors(req, res)) return
  43. if (!checkInvalidConfigIfEmailDisabled(req.body as CustomConfig, res)) return
  44. return next()
  45. }
  46. ]
  47. // ---------------------------------------------------------------------------
  48. export {
  49. customConfigUpdateValidator
  50. }
  51. function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) {
  52. if (Emailer.isEnabled()) return true
  53. if (customConfig.signup.requiresEmailVerification === true) {
  54. res.status(400)
  55. .send({ error: 'Emailer is disabled but you require signup email verification.' })
  56. .end()
  57. return false
  58. }
  59. return true
  60. }