mirror of
https://github.com/mediacms-io/mediacms.git
synced 2026-03-22 04:33:09 -04:00
chore(frontend): harden settings parsing and update store imports
This commit is contained in:
@@ -21,8 +21,9 @@ export function pagesConfig(
|
|||||||
|
|
||||||
ret[key].enabled = settings[key]?.enabled === false ? false : true;
|
ret[key].enabled = settings[key]?.enabled === false ? false : true;
|
||||||
|
|
||||||
if (settings[key]?.title !== undefined) {
|
const title = settings[key]?.title;
|
||||||
ret[key].title = settings[key].title.trim();
|
if (typeof title === 'string') {
|
||||||
|
ret[key].title = title.trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ export function taxonomiesConfig(settings?: DeepPartial<GlobalMediaCMS['site']['
|
|||||||
|
|
||||||
ret[key].enabled = settings[key]?.enabled === false ? false : true; // @todo: Check this again
|
ret[key].enabled = settings[key]?.enabled === false ? false : true; // @todo: Check this again
|
||||||
|
|
||||||
if (settings[key]?.title !== undefined) {
|
const title = settings[key]?.title;
|
||||||
ret[key].title = settings[key].title.trim();
|
if (typeof title === 'string') {
|
||||||
|
ret[key].title = title.trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
import { BrowserCache } from '../classes/';
|
import { BrowserCache } from '../classes/';
|
||||||
import { BrowserEvents, exportStore } from '../helpers';
|
import { BrowserEvents, exportStore } from '../helpers';
|
||||||
import { config as mediaCmsConfig } from '../settings/config.js';
|
import { config as mediaCmsConfig } from '../settings/config';
|
||||||
|
|
||||||
function uniqid() {
|
function uniqid() {
|
||||||
let a = new Uint32Array(3);
|
let a = new Uint32Array(3);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
import { publishedOnDate, exportStore, getRequest, postRequest, deleteRequest, csrfToken } from '../helpers';
|
import { publishedOnDate, exportStore, getRequest, postRequest, deleteRequest, csrfToken } from '../helpers';
|
||||||
|
|
||||||
import { config as mediacmsConfig } from '../settings/config.js';
|
import { config as mediacmsConfig } from '../settings/config';
|
||||||
|
|
||||||
const PlaylistPageStoreData = {};
|
const PlaylistPageStoreData = {};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
import { exportStore, getRequest, deleteRequest, csrfToken } from '../helpers';
|
import { exportStore, getRequest, deleteRequest, csrfToken } from '../helpers';
|
||||||
|
|
||||||
import { config as mediacmsConfig } from '../settings/config.js';
|
import { config as mediacmsConfig } from '../settings/config';
|
||||||
|
|
||||||
class ProfilePageStore extends EventEmitter {
|
class ProfilePageStore extends EventEmitter {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
import { exportStore, getRequest } from '../helpers';
|
import { exportStore, getRequest } from '../helpers';
|
||||||
import { config as mediacmsConfig } from '../settings/config.js';
|
import { config as mediacmsConfig } from '../settings/config';
|
||||||
|
|
||||||
function getUrlVars() {
|
function getUrlVars() {
|
||||||
var vars = {};
|
var vars = {};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import EventEmitter from 'events';
|
|||||||
import { exportStore } from '../helpers/';
|
import { exportStore } from '../helpers/';
|
||||||
import { BrowserCache } from '../classes/';
|
import { BrowserCache } from '../classes/';
|
||||||
|
|
||||||
import { config as mediacmsConfig } from '../settings/config.js';
|
import { config as mediacmsConfig } from '../settings/config';
|
||||||
|
|
||||||
let browserCache;
|
let browserCache;
|
||||||
|
|
||||||
|
|||||||
@@ -14,4 +14,4 @@ export {
|
|||||||
ProfilePageStore,
|
ProfilePageStore,
|
||||||
SearchFieldStore,
|
SearchFieldStore,
|
||||||
VideoViewerStore,
|
VideoViewerStore,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -44,6 +44,18 @@ describe('utils/settings', () => {
|
|||||||
expect(cfg.recommended.title).toBe('Recommended');
|
expect(cfg.recommended.title).toBe('Recommended');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Ignores non-string titles and keeps defaults', () => {
|
||||||
|
const cfg = pagesConfig({
|
||||||
|
latest: { title: null as any },
|
||||||
|
featured: { title: 123 as any },
|
||||||
|
recommended: { title: true as any },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(cfg.latest.title).toBe('Recent uploads');
|
||||||
|
expect(cfg.featured.title).toBe('Featured');
|
||||||
|
expect(cfg.recommended.title).toBe('Recommended');
|
||||||
|
});
|
||||||
|
|
||||||
test('Ignores unknown keys in settings', () => {
|
test('Ignores unknown keys in settings', () => {
|
||||||
const cfg = pagesConfig({
|
const cfg = pagesConfig({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@@ -30,6 +30,16 @@ describe('utils/settings', () => {
|
|||||||
expect(res.tags).toStrictEqual({ enabled: true, title: 'My Tags' });
|
expect(res.tags).toStrictEqual({ enabled: true, title: 'My Tags' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Should ignore non-string title values and keep defaults', () => {
|
||||||
|
const res = taxonomiesConfig({
|
||||||
|
tags: { title: null as any },
|
||||||
|
categories: { title: 123 as any },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.tags).toStrictEqual({ enabled: true, title: 'Tags' });
|
||||||
|
expect(res.categories).toStrictEqual({ enabled: true, title: 'Categories' });
|
||||||
|
});
|
||||||
|
|
||||||
test('Should ignore unknown taxonomy keys', () => {
|
test('Should ignore unknown taxonomy keys', () => {
|
||||||
const input = {
|
const input = {
|
||||||
unknownKey: { enabled: true, title: 'X' },
|
unknownKey: { enabled: true, title: 'X' },
|
||||||
|
|||||||
Reference in New Issue
Block a user