Persist user GUI preferences and resize the shared media modal
DC CMS qualification / qualify (push) Successful in 2m22s
DC CMS qualification / qualify (push) Successful in 2m22s
This commit is contained in:
@@ -4,6 +4,7 @@ import { dirname, join, resolve, posix, relative } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { createSiteApplication } from "./site-app.mjs";
|
||||
import { UserPreferencesStore } from "./user-preferences.mjs";
|
||||
|
||||
const cmsRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const projectsRoot = resolve(process.env.CMS_PROJECTS_ROOT || join(cmsRoot, "projects"));
|
||||
@@ -150,6 +151,7 @@ function json(res, status, payload) {
|
||||
}
|
||||
await mkdir(projectsRoot, { recursive: true });
|
||||
const auth = await application(defaultId);
|
||||
const userPreferences = new UserPreferencesStore(projectsRoot);
|
||||
const server = createServer(async (req, res) => {
|
||||
try {
|
||||
const url = new URL(req.url, "http://cms.local");
|
||||
@@ -160,6 +162,12 @@ const server = createServer(async (req, res) => {
|
||||
const expected = new URL(process.env.CMS_BASE_URL || `http://${req.headers.host}`).origin;
|
||||
if (req.headers["sec-fetch-site"] === "cross-site" || (origin && origin !== expected)) throw fail("Недопустимый источник запроса", 403);
|
||||
}
|
||||
if (url.pathname === "/api/user/preferences") {
|
||||
const principal = auth.authEnabled ? (req.cmsUser?.sub ? `oidc:${req.cmsUser.sub}` : null) : 'local:no-auth';
|
||||
if (req.method === 'GET') return json(res, 200, { ok: true, ...await userPreferences.read(principal) });
|
||||
if (req.method === 'PATCH') return json(res, 200, { ok: true, ...await userPreferences.patch(principal, await body(req), { ifAbsent: req.headers['if-none-match'] === '*' }) });
|
||||
throw fail('Метод не поддерживается', 405);
|
||||
}
|
||||
if (url.pathname === "/api/sites") {
|
||||
if (req.method === "GET") return json(res, 200, { ok: true, sites: await siteList() });
|
||||
if (req.method === "POST") return json(res, 201, { ok: true, project: await createSite(await body(req)) });
|
||||
|
||||
Reference in New Issue
Block a user