]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/custom-page.ts
prevent multiple post-process triggering of upload-resumable (#4175)
[github/Chocobozzz/PeerTube.git] / server / controllers / api / custom-page.ts
CommitLineData
41fb13c3 1import express from 'express'
2539932e
C
2import { ServerConfigManager } from '@server/lib/server-config-manager'
3import { ActorCustomPageModel } from '@server/models/account/actor-custom-page'
4c7e60bc 4import { HttpStatusCode, UserRight } from '@shared/models'
2539932e
C
5import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
6
7const customPageRouter = express.Router()
8
9customPageRouter.get('/homepage/instance',
10 asyncMiddleware(getInstanceHomepage)
11)
12
13customPageRouter.put('/homepage/instance',
14 authenticate,
15 ensureUserHasRight(UserRight.MANAGE_INSTANCE_CUSTOM_PAGE),
16 asyncMiddleware(updateInstanceHomepage)
17)
18
19// ---------------------------------------------------------------------------
20
21export {
22 customPageRouter
23}
24
25// ---------------------------------------------------------------------------
26
27async function getInstanceHomepage (req: express.Request, res: express.Response) {
28 const page = await ActorCustomPageModel.loadInstanceHomepage()
76148b27
RK
29 if (!page) {
30 return res.fail({
31 status: HttpStatusCode.NOT_FOUND_404,
32 message: 'Instance homepage could not be found'
33 })
34 }
2539932e
C
35
36 return res.json(page.toFormattedJSON())
37}
38
39async function updateInstanceHomepage (req: express.Request, res: express.Response) {
40 const content = req.body.content
41
42 await ActorCustomPageModel.updateInstanceHomepage(content)
43 ServerConfigManager.Instance.updateHomepageState(content)
44
76148b27 45 return res.status(HttpStatusCode.NO_CONTENT_204).end()
2539932e 46}