2021-08-27 14:32:44 +02:00
|
|
|
import express from 'express'
|
2021-05-27 15:59:55 +02:00
|
|
|
import { ServerConfigManager } from '@server/lib/server-config-manager'
|
|
|
|
import { ActorCustomPageModel } from '@server/models/account/actor-custom-page'
|
2021-07-16 14:27:30 +02:00
|
|
|
import { HttpStatusCode, UserRight } from '@shared/models'
|
2021-05-27 15:59:55 +02:00
|
|
|
import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
|
|
|
|
|
|
|
|
const customPageRouter = express.Router()
|
|
|
|
|
|
|
|
customPageRouter.get('/homepage/instance',
|
|
|
|
asyncMiddleware(getInstanceHomepage)
|
|
|
|
)
|
|
|
|
|
|
|
|
customPageRouter.put('/homepage/instance',
|
|
|
|
authenticate,
|
|
|
|
ensureUserHasRight(UserRight.MANAGE_INSTANCE_CUSTOM_PAGE),
|
|
|
|
asyncMiddleware(updateInstanceHomepage)
|
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
customPageRouter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
async function getInstanceHomepage (req: express.Request, res: express.Response) {
|
|
|
|
const page = await ActorCustomPageModel.loadInstanceHomepage()
|
2021-06-01 01:36:53 +02:00
|
|
|
if (!page) {
|
|
|
|
return res.fail({
|
|
|
|
status: HttpStatusCode.NOT_FOUND_404,
|
|
|
|
message: 'Instance homepage could not be found'
|
|
|
|
})
|
|
|
|
}
|
2021-05-27 15:59:55 +02:00
|
|
|
|
|
|
|
return res.json(page.toFormattedJSON())
|
|
|
|
}
|
|
|
|
|
|
|
|
async function updateInstanceHomepage (req: express.Request, res: express.Response) {
|
|
|
|
const content = req.body.content
|
|
|
|
|
|
|
|
await ActorCustomPageModel.updateInstanceHomepage(content)
|
|
|
|
ServerConfigManager.Instance.updateHomepageState(content)
|
|
|
|
|
2021-06-01 01:36:53 +02:00
|
|
|
return res.status(HttpStatusCode.NO_CONTENT_204).end()
|
2021-05-27 15:59:55 +02:00
|
|
|
}
|