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);
|
||||
|
||||
|
||||
+22
-1
@@ -1947,7 +1947,14 @@ process.on('uncaughtException', err => {
|
||||
enable_comments: cfg.enable_comments !== false,
|
||||
public_nsfw: !!cfg.websrv.public_nsfw,
|
||||
public_untagged: !!cfg.websrv.public_untagged,
|
||||
onara: !!(cfg.onara !== undefined ? cfg.onara : cfg.websrv?.onara),
|
||||
get onara() {
|
||||
const c = cfg.onara !== undefined ? cfg.onara : cfg.websrv?.onara;
|
||||
return !!c;
|
||||
},
|
||||
get onara_cfg() {
|
||||
const c = cfg.onara !== undefined ? cfg.onara : cfg.websrv?.onara;
|
||||
return (c !== undefined && c !== null) ? !!c : null;
|
||||
},
|
||||
is_onara_item: false,
|
||||
enable_private_uploads: cfg.enable_private_uploads !== false,
|
||||
get enable_expiring_uploads() { return getEnableExpiringUploads(); },
|
||||
@@ -2147,12 +2154,26 @@ process.on('uncaughtException', err => {
|
||||
data.max_file_size = lib.formatSize(cfg.main.maxfilesize * (activeReq.session?.admin ? cfg.main.adminmultiplier : 1));
|
||||
data.max_file_size_bytes = Math.floor(cfg.main.maxfilesize * (activeReq.session?.admin ? cfg.main.adminmultiplier : 1));
|
||||
data.web_url_upload = data.web_url_upload !== undefined ? data.web_url_upload : !!cfg.websrv.web_url_upload;
|
||||
|
||||
const cfgOnara = cfg.onara !== undefined ? cfg.onara : cfg.websrv?.onara;
|
||||
const cookieOnara = activeReq.cookies?.f0ck_onara !== undefined
|
||||
? (activeReq.cookies.f0ck_onara === '1' || activeReq.cookies.f0ck_onara === 'true')
|
||||
: (activeReq.cookies?.onara !== undefined ? (activeReq.cookies.onara === '1' || activeReq.cookies.onara === 'true') : null);
|
||||
const effectiveOnara = (cfgOnara !== undefined && cfgOnara !== null)
|
||||
? !!cfgOnara
|
||||
: (cookieOnara !== null ? cookieOnara : !!activeReq.session?.onara);
|
||||
data.onara = effectiveOnara;
|
||||
data.onara_cfg = (cfgOnara !== undefined && cfgOnara !== null) ? !!cfgOnara : null;
|
||||
} else {
|
||||
data.recaptcha_enabled = perRequestRecaptcha;
|
||||
data.theme = data.theme || cfg.websrv.theme || 'f0ck';
|
||||
data.user_strict_bool = false;
|
||||
data.user_logged_in_bool = false;
|
||||
globals.csrf_token = data.csrf_token || '';
|
||||
|
||||
const cfgOnara = cfg.onara !== undefined ? cfg.onara : cfg.websrv?.onara;
|
||||
data.onara = !!cfgOnara;
|
||||
data.onara_cfg = (cfgOnara !== undefined && cfgOnara !== null) ? !!cfgOnara : null;
|
||||
}
|
||||
|
||||
return originalRender.call(tpl, view, data, (data.url && data.url !== req?.url) ? undefined : req);
|
||||
|
||||
Reference in New Issue
Block a user