mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Preserve previous-source cards across project switches, require matching credentials before fetching, and bind identifiable legacy mappings before replacing or clearing settings. Reject unknown legacy sources and stale fetched configurations. Verify with nine focused Node suites, nine Chromium scenarios and the local release audit. Concurrent jobs and configuration writes remain nontransactional. Thanks to xet7 !
25 lines
1.1 KiB
JavaScript
25 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
// A provider's item ID is meaningful only within its server and project.
|
|
// Keep this tuple readable and deterministic; it contains no credential.
|
|
function normalizeSyncSource(source) {
|
|
const projectKey = String(source.projectKey || '').trim();
|
|
if (!projectKey) throw new Error('A Sync project is required.');
|
|
let url = source.url || '';
|
|
if (source.type === 'github') url = 'https://api.github.com';
|
|
if (source.type === 'gitlab' && !url) url = 'https://gitlab.com';
|
|
let parsed;
|
|
try { parsed = new URL(url); } catch (error) { throw new Error('A valid Sync server URL is required.'); }
|
|
if (!['http:', 'https:'].includes(parsed.protocol) || parsed.username || parsed.password || parsed.search || parsed.hash) {
|
|
throw new Error('Use a Sync server URL without credentials, query parameters or fragments.');
|
|
}
|
|
return { ...source, url: parsed.href.replace(/\/+$/, ''), projectKey };
|
|
}
|
|
|
|
function syncSourceKey(source) {
|
|
const normalized = normalizeSyncSource(source);
|
|
return JSON.stringify([normalized.type, normalized.url, normalized.projectKey]);
|
|
}
|
|
|
|
module.exports = { normalizeSyncSource, syncSourceKey };
|