]>
Commit | Line | Data |
---|---|---|
2539932e C |
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/core-utils' | |
5 | import { UserRight } from '@shared/models' | |
6 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' | |
7 | ||
8 | const customPageRouter = express.Router() | |
9 | ||
10 | customPageRouter.get('/homepage/instance', | |
11 | asyncMiddleware(getInstanceHomepage) | |
12 | ) | |
13 | ||
14 | customPageRouter.put('/homepage/instance', | |
15 | authenticate, | |
16 | ensureUserHasRight(UserRight.MANAGE_INSTANCE_CUSTOM_PAGE), | |
17 | asyncMiddleware(updateInstanceHomepage) | |
18 | ) | |
19 | ||
20 | // --------------------------------------------------------------------------- | |
21 | ||
22 | export { | |
23 | customPageRouter | |
24 | } | |
25 | ||
26 | // --------------------------------------------------------------------------- | |
27 | ||
28 | async function getInstanceHomepage (req: express.Request, res: express.Response) { | |
29 | const page = await ActorCustomPageModel.loadInstanceHomepage() | |
30 | if (!page) return res.sendStatus(HttpStatusCode.NOT_FOUND_404) | |
31 | ||
32 | return res.json(page.toFormattedJSON()) | |
33 | } | |
34 | ||
35 | async function updateInstanceHomepage (req: express.Request, res: express.Response) { | |
36 | const content = req.body.content | |
37 | ||
38 | await ActorCustomPageModel.updateInstanceHomepage(content) | |
39 | ServerConfigManager.Instance.updateHomepageState(content) | |
40 | ||
41 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | |
42 | } |