1 import 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, UserRight } from '@shared/models'
5 import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
7 const customPageRouter = express.Router()
9 customPageRouter.get('/homepage/instance',
10 asyncMiddleware(getInstanceHomepage)
13 customPageRouter.put('/homepage/instance',
15 ensureUserHasRight(UserRight.MANAGE_INSTANCE_CUSTOM_PAGE),
16 asyncMiddleware(updateInstanceHomepage)
19 // ---------------------------------------------------------------------------
25 // ---------------------------------------------------------------------------
27 async function getInstanceHomepage (req: express.Request, res: express.Response) {
28 const page = await ActorCustomPageModel.loadInstanceHomepage()
31 status: HttpStatusCode.NOT_FOUND_404,
32 message: 'Instance homepage could not be found'
36 return res.json(page.toFormattedJSON())
39 async function updateInstanceHomepage (req: express.Request, res: express.Response) {
40 const content = req.body.content
42 await ActorCustomPageModel.updateInstanceHomepage(content)
43 ServerConfigManager.Instance.updateHomepageState(content)
45 return res.status(HttpStatusCode.NO_CONTENT_204).end()