mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Extract the pure, security- and correctness-critical logic of the recent features into Meteor-free models/lib/* modules (so production and tests share one implementation) and add plain-Node tests with positive AND negative cases, wired into test:unit:node: - models/lib/mongoSelectorSafety.js hasWhere() — the windowed card publication refuses a client selector carrying $where (server-side JS). Tests: safe selectors pass; $where at top level / in $and / deep in arrays / in $elemMatch is rejected. (was inline in server/publications/cardsWindow.js) - models/lib/cardsLoading.js resolveCardsLoadingMode / parseCardsLoadingEnv / windowCountId — CARDS_LOADING maps to 'lazy' only for exactly "lazy" (garbage never enables the experimental mode); a falsy swimlane id collapses to one count-doc id (listBody uses undefined, listHeader uses ''). (used by server/cards-loading.js, server/models/settings.js, client/lib/lazyCards.js) - models/lib/base64Chunk.js encodeAligned/encodeFinal — streaming an attachment into the JSON export as base64 in any chunk sizes reconstructs exactly the whole-file base64; aligned pieces never carry padding. (used by Exporter.buildStream) - models/lib/backupPaths.js filesRootFrom/scheduleText — WRITABLE_PATH -> files root (no double /files suffix, Windows-safe) and the synced-cron schedule text (daily/weekly/monthly + defaults, unknown frequency falls back to daily). (used by server/methods/backup.js) 41 new assertions across 4 files, all passing; whole test:unit:node suite green.
32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
// Pure, Meteor-free helpers for the Admin Panel / Attachments / Backup feature.
|
|
// Unit-tested in tests/backupPaths.test.cjs. Used by server/methods/backup.js.
|
|
|
|
const path = require('path');
|
|
|
|
// Resolve the files root from a writable-path base. WeKan's WRITABLE_PATH is
|
|
// either the parent of "files" (docker/dev: /data -> /data/files) or already
|
|
// ends in "files" (snap: $SNAP_COMMON/files -> unchanged). Handles both the '/'
|
|
// and '\\' separator so a Windows path is not double-suffixed.
|
|
function filesRootFrom(base) {
|
|
const b = base || '';
|
|
return b.endsWith('/files') || b.endsWith('\\files') ? b : path.join(b, 'files');
|
|
}
|
|
|
|
// Build the synced-cron schedule text for a saved backup schedule.
|
|
// daily -> "every day at HH:MM"
|
|
// weekly -> "on <Day> at HH:MM" (default Sunday)
|
|
// monthly -> "on the <N> day of the month at HH:MM" (default 1)
|
|
// Any other/absent frequency falls back to the daily form.
|
|
function scheduleText(s) {
|
|
const settings = s || {};
|
|
const [hh, mm] = (settings.time || '04:00').split(':');
|
|
const at = `at ${hh}:${mm}`;
|
|
if (settings.frequency === 'weekly') return `on ${settings.dayOfWeek || 'Sunday'} ${at}`;
|
|
if (settings.frequency === 'monthly') return `on the ${settings.dayOfMonth || 1} day of the month ${at}`;
|
|
return `every day ${at}`;
|
|
}
|
|
|
|
module.exports = { filesRootFrom, scheduleText };
|