1 import * as express from 'express'
2 import { ServerConfigManager } from '@server/lib/server-config-manager'
3 import { ActorCustomPageModel } from '@server/models/account/actor-custom-page'
4 import { HttpStatusCode } from '@shared/models'
5 import { UserRight } from '@shared/models'
6 import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
8 const customPageRouter = express.Router()
10 customPageRouter.get('/homepage/instance',
11 asyncMiddleware(getInstanceHomepage)
14 customPageRouter.put('/homepage/instance',
16 ensureUserHasRight(UserRight.MANAGE_INSTANCE_CUSTOM_PAGE),
17 asyncMiddleware(updateInstanceHomepage)
20 // ---------------------------------------------------------------------------
26 // ---------------------------------------------------------------------------
28 async function getInstanceHomepage (req: express.Request, res: express.Response) {
29 const page = await ActorCustomPageModel.loadInstanceHomepage()
32 status: HttpStatusCode.NOT_FOUND_404,
33 message: 'Instance homepage could not be found'
37 return res.json(page.toFormattedJSON())
40 async function updateInstanceHomepage (req: express.Request, res: express.Response) {
41 const content = req.body.content
43 await ActorCustomPageModel.updateInstanceHomepage(content)
44 ServerConfigManager.Instance.updateHomepageState(content)
46 return res.status(HttpStatusCode.NO_CONTENT_204).end()