]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express from 'express' |
2539932e C |
2 | import { ServerConfigManager } from '@server/lib/server-config-manager' |
3 | import { ActorCustomPageModel } from '@server/models/account/actor-custom-page' | |
4c7e60bc | 4 | import { HttpStatusCode, UserRight } from '@shared/models' |
2539932e C |
5 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' |
6 | ||
7 | const customPageRouter = express.Router() | |
8 | ||
9 | customPageRouter.get('/homepage/instance', | |
10 | asyncMiddleware(getInstanceHomepage) | |
11 | ) | |
12 | ||
13 | customPageRouter.put('/homepage/instance', | |
14 | authenticate, | |
15 | ensureUserHasRight(UserRight.MANAGE_INSTANCE_CUSTOM_PAGE), | |
16 | asyncMiddleware(updateInstanceHomepage) | |
17 | ) | |
18 | ||
19 | // --------------------------------------------------------------------------- | |
20 | ||
21 | export { | |
22 | customPageRouter | |
23 | } | |
24 | ||
25 | // --------------------------------------------------------------------------- | |
26 | ||
27 | async 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 | ||
39 | async 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 | } |