hgfd
This commit is contained in:
@@ -100,4 +100,33 @@ config.paths = {
|
||||
import: resolveImportPath()
|
||||
};
|
||||
|
||||
const configFilePath = path.resolve(base, "config.json");
|
||||
let watchDebounceTimer = null;
|
||||
try {
|
||||
if (fs.existsSync(configFilePath)) {
|
||||
const watcher = fs.watch(configFilePath, (eventType) => {
|
||||
if (eventType === 'change' || eventType === 'rename') {
|
||||
if (watchDebounceTimer) clearTimeout(watchDebounceTimer);
|
||||
watchDebounceTimer = setTimeout(() => {
|
||||
try {
|
||||
const raw = fs.readFileSync(configFilePath, 'utf8');
|
||||
const updated = JSON.parse(raw);
|
||||
Object.assign(config, updated);
|
||||
if (config.sql) {
|
||||
config.sql.host = process.env.DB_HOST || process.env.POSTGRES_HOST || process.env.PGHOST || config.sql.host;
|
||||
config.sql.port = parseInt(process.env.DB_PORT || process.env.POSTGRES_PORT || process.env.PGPORT || config.sql.port, 10);
|
||||
config.sql.user = process.env.DB_USER || process.env.POSTGRES_USER || process.env.PGUSER || config.sql.user;
|
||||
config.sql.password = process.env.DB_PASS || process.env.POSTGRES_PASSWORD || process.env.PGPASSWORD || config.sql.password;
|
||||
config.sql.database = process.env.DB_NAME || process.env.POSTGRES_DB || process.env.PGDATABASE || config.sql.database;
|
||||
}
|
||||
console.log('[CONFIG] config.json reloaded dynamically');
|
||||
} catch (_) {}
|
||||
}, 100);
|
||||
if (watchDebounceTimer.unref) watchDebounceTimer.unref();
|
||||
}
|
||||
});
|
||||
if (watcher.unref) watcher.unref();
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
export default config;
|
||||
|
||||
@@ -12,6 +12,7 @@ import cfg from "../config.mjs";
|
||||
import security from "../security.mjs";
|
||||
import crypto from "crypto";
|
||||
import path from "path";
|
||||
import YAML from "yaml";
|
||||
import { getManualApproval, setManualApproval, getMinTags, setMinTags, getRegistrationOpen, setRegistrationOpen, getTrustedUploads, setTrustedUploads, getEnablePdf, setEnablePdf, getLogUserIps, setLogUserIps, getHashUserIps, setHashUserIps, getEnableCleanup, setEnableCleanup, getCleanupStartDate, setCleanupStartDate, getCleanupEndDate, setCleanupEndDate, getCleanupIncludeEngaged, setCleanupIncludeEngaged, getShitpostMode, ensureAllItemsHaveSlugs, getEnableItemSlugs, getBrandImageUrl } from "../settings.mjs";
|
||||
|
||||
export default (router, tpl) => {
|
||||
@@ -939,6 +940,15 @@ export default (router, tpl) => {
|
||||
// Write formatted JSON to config.json on disk
|
||||
await fs.writeFile(configPath, JSON.stringify(updatedConfig, null, 2) + "\n", "utf-8");
|
||||
|
||||
// Also update config.yaml if it exists
|
||||
const configYamlPath = path.resolve(process.cwd(), "config.yaml");
|
||||
try {
|
||||
const yamlDoc = new YAML.Document(updatedConfig);
|
||||
await fs.writeFile(configYamlPath, String(yamlDoc), "utf-8");
|
||||
} catch (yamlErr) {
|
||||
console.warn('[ADMIN] Could not sync config.yaml:', yamlErr.message);
|
||||
}
|
||||
|
||||
// Mutate in-memory cfg object so changes apply immediately
|
||||
Object.assign(cfg, updatedConfig);
|
||||
|
||||
|
||||
+16
-2
@@ -221,7 +221,14 @@ export default (router, tpl) => {
|
||||
console.log(`[AJAX-RANDOM] ${itemid} total=${tAjaxRender - tAjaxStart}ms | getRandom=${tRandom - tAjaxStart}ms | getf0ck=${tAjaxFetch - tRandom}ms | aux=${tAjaxAux - tAjaxFetch}ms | render=${tAjaxRender - tAjaxAux}ms`);
|
||||
|
||||
let itemPage = null;
|
||||
if (query.onara === '1' || req.cookies?.onara === '1' || req.cookies?.f0ck_onara === '1' || cfg.onara) {
|
||||
const cfgOnara = cfg.onara !== undefined ? cfg.onara : cfg.websrv?.onara;
|
||||
const cookieOnara = req.cookies?.f0ck_onara !== undefined
|
||||
? (req.cookies.f0ck_onara === '1' || req.cookies.f0ck_onara === 'true')
|
||||
: (req.cookies?.onara !== undefined ? (req.cookies.onara === '1' || req.cookies.onara === 'true') : null);
|
||||
const effectiveOnara = (cfgOnara !== undefined && cfgOnara !== null)
|
||||
? !!cfgOnara
|
||||
: (query.onara === '1' || cookieOnara === true);
|
||||
if (effectiveOnara) {
|
||||
try {
|
||||
itemPage = await f0cklib.getItemPage({
|
||||
targetItemId: data.item?.id || itemid,
|
||||
@@ -487,7 +494,14 @@ export default (router, tpl) => {
|
||||
- Render: ${tAjaxRender - tAjaxAux}ms`);
|
||||
|
||||
let itemPage = null;
|
||||
if (query.onara === '1' || req.cookies?.onara === '1' || req.cookies?.f0ck_onara === '1' || cfg.onara || query.get_page === '1') {
|
||||
const cfgOnara = cfg.onara !== undefined ? cfg.onara : cfg.websrv?.onara;
|
||||
const cookieOnara = req.cookies?.f0ck_onara !== undefined
|
||||
? (req.cookies.f0ck_onara === '1' || req.cookies.f0ck_onara === 'true')
|
||||
: (req.cookies?.onara !== undefined ? (req.cookies.onara === '1' || req.cookies.onara === 'true') : null);
|
||||
const effectiveOnara = (cfgOnara !== undefined && cfgOnara !== null)
|
||||
? !!cfgOnara
|
||||
: (query.onara === '1' || cookieOnara === true);
|
||||
if (effectiveOnara || query.get_page === '1') {
|
||||
try {
|
||||
itemPage = await f0cklib.getItemPage({
|
||||
targetItemId: data.item?.id || itemid,
|
||||
|
||||
@@ -494,12 +494,14 @@ export default (router, tpl) => {
|
||||
return res.reply({ body });
|
||||
}
|
||||
|
||||
const cfgOnara = cfg.onara !== undefined ? cfg.onara : cfg.websrv?.onara;
|
||||
const cookieOnara = req.cookies?.f0ck_onara !== undefined
|
||||
? (req.cookies.f0ck_onara === '1' || req.cookies.f0ck_onara === 'true')
|
||||
: (req.cookies?.onara !== undefined ? (req.cookies.onara === '1' || req.cookies.onara === 'true') : null);
|
||||
const isOnara = cookieOnara !== null
|
||||
? cookieOnara
|
||||
: !!(req.session?.onara || (cfg.onara !== undefined ? cfg.onara : cfg.websrv?.onara));
|
||||
// Global config onara overweighs always the user pref
|
||||
const isOnara = (cfgOnara !== undefined && cfgOnara !== null)
|
||||
? !!cfgOnara
|
||||
: (cookieOnara !== null ? cookieOnara : !!req.session?.onara);
|
||||
if (mode === 'item' && isOnara) {
|
||||
const itemHtml = tpl.render('ajax-item', data, req);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user