New per-hoster setting "Links in Log schreiben" (logToFile, default on). When unchecked for a hoster, that hoster's successful upload links are no longer written to fileuploader.log — other hosters keep logging independently. - lib/config-store.js: logToFile: true added to HOSTER_SETTINGS_DEFAULTS; merge-on-load gives every hoster the key (old configs included). - renderer/app.js: checkbox per hoster panel + collection loop now handles type=checkbox (boolean) alongside the numeric fields. The autosave bind already special-cased checkboxes (change event). - lib/log-policy.js (new): hosterLogToFileEnabled() — pure, opt-out semantics. Only an explicit logToFile===false disables; missing/ malformed/non-true values all default ON so links are never silently dropped. - main.js: shouldLogHosterToFile() reads the LIVE uploadManager .hosterSettings (so a mid-batch toggle takes effect at once), falls back to persisted config, then to enabled. Guards appendUploadLog in the done handler; skipped writes get a debugLog line. Tests: 8 log-policy (defaults, opt-out, per-hoster independence, malformed input) + 2 config-store (default true, persisted false survives reload). 147/147 green, eslint clean.
53 lines
2.3 KiB
JavaScript
53 lines
2.3 KiB
JavaScript
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
const { hosterLogToFileEnabled } = require('../lib/log-policy');
|
|
|
|
test('enabled by default when settings missing entirely', () => {
|
|
assert.equal(hosterLogToFileEnabled(null, 'voe.sx'), true);
|
|
assert.equal(hosterLogToFileEnabled(undefined, 'voe.sx'), true);
|
|
assert.equal(hosterLogToFileEnabled('not-an-object', 'voe.sx'), true);
|
|
});
|
|
|
|
test('enabled when hoster has no settings entry', () => {
|
|
assert.equal(hosterLogToFileEnabled({}, 'voe.sx'), true);
|
|
assert.equal(hosterLogToFileEnabled({ 'byse.sx': { logToFile: false } }, 'voe.sx'), true);
|
|
});
|
|
|
|
test('enabled when hoster entry has no logToFile key (back-compat with old configs)', () => {
|
|
assert.equal(hosterLogToFileEnabled({ 'voe.sx': { retries: 3 } }, 'voe.sx'), true);
|
|
});
|
|
|
|
test('enabled when logToFile is explicitly true', () => {
|
|
assert.equal(hosterLogToFileEnabled({ 'voe.sx': { logToFile: true } }, 'voe.sx'), true);
|
|
});
|
|
|
|
test('DISABLED only when logToFile is explicitly false', () => {
|
|
assert.equal(hosterLogToFileEnabled({ 'voe.sx': { logToFile: false } }, 'voe.sx'), false);
|
|
});
|
|
|
|
test('truthy-but-not-true values do not accidentally disable', () => {
|
|
// Only the strict boolean false disables — guards against e.g. a stored 0/""
|
|
assert.equal(hosterLogToFileEnabled({ 'voe.sx': { logToFile: 0 } }, 'voe.sx'), true);
|
|
assert.equal(hosterLogToFileEnabled({ 'voe.sx': { logToFile: '' } }, 'voe.sx'), true);
|
|
assert.equal(hosterLogToFileEnabled({ 'voe.sx': { logToFile: null } }, 'voe.sx'), true);
|
|
assert.equal(hosterLogToFileEnabled({ 'voe.sx': { logToFile: undefined } }, 'voe.sx'), true);
|
|
});
|
|
|
|
test('per-hoster independence: one off, others on', () => {
|
|
const settings = {
|
|
'voe.sx': { logToFile: false },
|
|
'byse.sx': { logToFile: true },
|
|
'doodstream.com': { retries: 3 }
|
|
};
|
|
assert.equal(hosterLogToFileEnabled(settings, 'voe.sx'), false);
|
|
assert.equal(hosterLogToFileEnabled(settings, 'byse.sx'), true);
|
|
assert.equal(hosterLogToFileEnabled(settings, 'doodstream.com'), true);
|
|
assert.equal(hosterLogToFileEnabled(settings, 'clouddrop.cc'), true); // not present → on
|
|
});
|
|
|
|
test('malformed hoster entry (string/number) defaults to on', () => {
|
|
assert.equal(hosterLogToFileEnabled({ 'voe.sx': 'broken' }, 'voe.sx'), true);
|
|
assert.equal(hosterLogToFileEnabled({ 'voe.sx': 42 }, 'voe.sx'), true);
|
|
});
|