diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/config.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/custom-page.ts | 42 | ||||
-rw-r--r-- | server/controllers/api/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/videos/import.ts | 4 | ||||
-rw-r--r-- | server/controllers/static.ts | 10 |
5 files changed, 53 insertions, 9 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 5ce7adc35..c9b5c8047 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import { ServerConfigManager } from '@server/lib/server-config-manager' | ||
1 | import * as express from 'express' | 2 | import * as express from 'express' |
2 | import { remove, writeJSON } from 'fs-extra' | 3 | import { remove, writeJSON } from 'fs-extra' |
3 | import { snakeCase } from 'lodash' | 4 | import { snakeCase } from 'lodash' |
4 | import validator from 'validator' | 5 | import validator from 'validator' |
5 | import { getServerConfig } from '@server/lib/config' | ||
6 | import { UserRight } from '../../../shared' | 6 | import { UserRight } from '../../../shared' |
7 | import { About } from '../../../shared/models/server/about.model' | 7 | import { About } from '../../../shared/models/server/about.model' |
8 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | 8 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
@@ -43,7 +43,7 @@ configRouter.delete('/custom', | |||
43 | ) | 43 | ) |
44 | 44 | ||
45 | async function getConfig (req: express.Request, res: express.Response) { | 45 | async function getConfig (req: express.Request, res: express.Response) { |
46 | const json = await getServerConfig(req.ip) | 46 | const json = await ServerConfigManager.Instance.getServerConfig(req.ip) |
47 | 47 | ||
48 | return res.json(json) | 48 | return res.json(json) |
49 | } | 49 | } |
diff --git a/server/controllers/api/custom-page.ts b/server/controllers/api/custom-page.ts new file mode 100644 index 000000000..3c47f7b9a --- /dev/null +++ b/server/controllers/api/custom-page.ts | |||
@@ -0,0 +1,42 @@ | |||
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 | } | ||
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index 7ade1df3a..28378654a 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts | |||
@@ -8,6 +8,7 @@ import { abuseRouter } from './abuse' | |||
8 | import { accountsRouter } from './accounts' | 8 | import { accountsRouter } from './accounts' |
9 | import { bulkRouter } from './bulk' | 9 | import { bulkRouter } from './bulk' |
10 | import { configRouter } from './config' | 10 | import { configRouter } from './config' |
11 | import { customPageRouter } from './custom-page' | ||
11 | import { jobsRouter } from './jobs' | 12 | import { jobsRouter } from './jobs' |
12 | import { oauthClientsRouter } from './oauth-clients' | 13 | import { oauthClientsRouter } from './oauth-clients' |
13 | import { overviewsRouter } from './overviews' | 14 | import { overviewsRouter } from './overviews' |
@@ -47,6 +48,7 @@ apiRouter.use('/jobs', jobsRouter) | |||
47 | apiRouter.use('/search', searchRouter) | 48 | apiRouter.use('/search', searchRouter) |
48 | apiRouter.use('/overviews', overviewsRouter) | 49 | apiRouter.use('/overviews', overviewsRouter) |
49 | apiRouter.use('/plugins', pluginRouter) | 50 | apiRouter.use('/plugins', pluginRouter) |
51 | apiRouter.use('/custom-pages', customPageRouter) | ||
50 | apiRouter.use('/ping', pong) | 52 | apiRouter.use('/ping', pong) |
51 | apiRouter.use('/*', badRequest) | 53 | apiRouter.use('/*', badRequest) |
52 | 54 | ||
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index ee63c7b77..0d5d7a962 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts | |||
@@ -3,7 +3,7 @@ import { move, readFile } from 'fs-extra' | |||
3 | import * as magnetUtil from 'magnet-uri' | 3 | import * as magnetUtil from 'magnet-uri' |
4 | import * as parseTorrent from 'parse-torrent' | 4 | import * as parseTorrent from 'parse-torrent' |
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import { getEnabledResolutions } from '@server/lib/config' | 6 | import { ServerConfigManager } from '@server/lib/server-config-manager' |
7 | import { setVideoTags } from '@server/lib/video' | 7 | import { setVideoTags } from '@server/lib/video' |
8 | import { FilteredModelAttributes } from '@server/types' | 8 | import { FilteredModelAttributes } from '@server/types' |
9 | import { | 9 | import { |
@@ -134,7 +134,7 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) | |||
134 | const targetUrl = body.targetUrl | 134 | const targetUrl = body.targetUrl |
135 | const user = res.locals.oauth.token.User | 135 | const user = res.locals.oauth.token.User |
136 | 136 | ||
137 | const youtubeDL = new YoutubeDL(targetUrl, getEnabledResolutions('vod')) | 137 | const youtubeDL = new YoutubeDL(targetUrl, ServerConfigManager.Instance.getEnabledResolutions('vod')) |
138 | 138 | ||
139 | // Get video infos | 139 | // Get video infos |
140 | let youtubeDLInfo: YoutubeDLInfo | 140 | let youtubeDLInfo: YoutubeDLInfo |
diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 8a747ec52..3870ebfe9 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts | |||
@@ -2,7 +2,7 @@ import * as cors from 'cors' | |||
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { serveIndexHTML } from '@server/lib/client-html' | 4 | import { serveIndexHTML } from '@server/lib/client-html' |
5 | import { getEnabledResolutions, getRegisteredPlugins, getRegisteredThemes } from '@server/lib/config' | 5 | import { ServerConfigManager } from '@server/lib/server-config-manager' |
6 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 6 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' |
7 | import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo/nodeinfo.model' | 7 | import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo/nodeinfo.model' |
8 | import { root } from '../helpers/core-utils' | 8 | import { root } from '../helpers/core-utils' |
@@ -203,10 +203,10 @@ async function generateNodeinfo (req: express.Request, res: express.Response) { | |||
203 | } | 203 | } |
204 | }, | 204 | }, |
205 | plugin: { | 205 | plugin: { |
206 | registered: getRegisteredPlugins() | 206 | registered: ServerConfigManager.Instance.getRegisteredPlugins() |
207 | }, | 207 | }, |
208 | theme: { | 208 | theme: { |
209 | registered: getRegisteredThemes(), | 209 | registered: ServerConfigManager.Instance.getRegisteredThemes(), |
210 | default: getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) | 210 | default: getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) |
211 | }, | 211 | }, |
212 | email: { | 212 | email: { |
@@ -222,13 +222,13 @@ async function generateNodeinfo (req: express.Request, res: express.Response) { | |||
222 | webtorrent: { | 222 | webtorrent: { |
223 | enabled: CONFIG.TRANSCODING.WEBTORRENT.ENABLED | 223 | enabled: CONFIG.TRANSCODING.WEBTORRENT.ENABLED |
224 | }, | 224 | }, |
225 | enabledResolutions: getEnabledResolutions('vod') | 225 | enabledResolutions: ServerConfigManager.Instance.getEnabledResolutions('vod') |
226 | }, | 226 | }, |
227 | live: { | 227 | live: { |
228 | enabled: CONFIG.LIVE.ENABLED, | 228 | enabled: CONFIG.LIVE.ENABLED, |
229 | transcoding: { | 229 | transcoding: { |
230 | enabled: CONFIG.LIVE.TRANSCODING.ENABLED, | 230 | enabled: CONFIG.LIVE.TRANSCODING.ENABLED, |
231 | enabledResolutions: getEnabledResolutions('live') | 231 | enabledResolutions: ServerConfigManager.Instance.getEnabledResolutions('live') |
232 | } | 232 | } |
233 | }, | 233 | }, |
234 | import: { | 234 | import: { |