ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

49 lines
1.5 KiB

  1. import express from 'express'
  2. import { ServerConfigManager } from '@server/lib/server-config-manager.js'
  3. import { ActorCustomPageModel } from '@server/models/account/actor-custom-page.js'
  4. import { HttpStatusCode, UserRight } from '@peertube/peertube-models'
  5. import { apiRateLimiter, asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares/index.js'
  6. const customPageRouter = express.Router()
  7. customPageRouter.use(apiRateLimiter)
  8. customPageRouter.get('/homepage/instance',
  9. asyncMiddleware(getInstanceHomepage)
  10. )
  11. customPageRouter.put('/homepage/instance',
  12. authenticate,
  13. ensureUserHasRight(UserRight.MANAGE_INSTANCE_CUSTOM_PAGE),
  14. asyncMiddleware(updateInstanceHomepage)
  15. )
  16. // ---------------------------------------------------------------------------
  17. export {
  18. customPageRouter
  19. }
  20. // ---------------------------------------------------------------------------
  21. async function getInstanceHomepage (req: express.Request, res: express.Response) {
  22. const page = await ActorCustomPageModel.loadInstanceHomepage()
  23. if (!page) {
  24. return res.fail({
  25. status: HttpStatusCode.NOT_FOUND_404,
  26. message: 'Instance homepage could not be found'
  27. })
  28. }
  29. return res.json(page.toFormattedJSON())
  30. }
  31. async function updateInstanceHomepage (req: express.Request, res: express.Response) {
  32. const content = req.body.content
  33. await ActorCustomPageModel.updateInstanceHomepage(content)
  34. ServerConfigManager.Instance.updateHomepageState(content)
  35. return res.status(HttpStatusCode.NO_CONTENT_204).end()
  36. }