Commit fc35d083 authored by 谢宇轩's avatar 谢宇轩

fix: make edit --concurrency effective in source-manage

parent 0e739208
......@@ -17,7 +17,7 @@ RECIPE ✅ = `helpers/<id>.md` exists (spec-driven fetcher-helper); — = no rec
## Edit Source
```bash
node scripts/source-manage.js edit <id> --name "New Name" --url https://... --method browser
node scripts/source-manage.js edit <id> --name "New Name" --homepageUrl https://... --method browser
```
Editable fields: `name`, `homepageUrl`, `method`, `articleUrlPattern`, `vaultFolder`, `enabled`, `concurrency`, `paginate`.
......
......@@ -80,13 +80,24 @@ switch (command) {
const source = config.sources.find(s => s.id === id);
if (!source) { console.error(`Source "${id}" not found`); process.exit(1); }
const editableFields = ['name', 'homepageUrl', 'method', 'articleUrlPattern', 'vaultFolder', 'enabled', 'paginate'];
const editableFields = ['name', 'homepageUrl', 'method', 'articleUrlPattern', 'vaultFolder', 'enabled', 'concurrency', 'paginate'];
let changed = false;
for (const field of editableFields) {
if (args[field] !== undefined) {
const oldVal = source[field];
if (field === 'concurrency') {
// parseArgs yields strings; store an integer ≥1 so harvest.js's
// resolveConcurrency sees a real number, not "3".
const n = parseInt(args[field], 10);
if (!Number.isInteger(n) || n < 1) {
console.error(` ⚠️ Invalid concurrency "${args[field]}" (must be an integer ≥ 1) — skipped`);
continue;
}
source[field] = n;
} else {
source[field] = args[field] === 'true' ? true : args[field] === 'false' ? false : args[field];
}
console.log(` ${field}: ${oldVal} → ${source[field]}`);
changed = true;
}
......@@ -175,10 +186,13 @@ switch (command) {
paginate: false // pagination switch — set true in config.json to enable multi-page harvesting
};
if (existing) {
// Preserve user-set paginate across re-installs; entry.paginate stays as-is for new sources.
// Preserve user-set paginate and concurrency across re-installs; both
// stay at their defaults for new sources.
const savedPaginate = existing.paginate;
const savedConcurrency = existing.concurrency;
Object.assign(existing, entry);
if (savedPaginate === true) existing.paginate = true;
if (Number.isInteger(savedConcurrency) && savedConcurrency > 1) existing.concurrency = savedConcurrency;
} else {
config.sources.push(entry);
}
......@@ -206,7 +220,8 @@ switch (command) {
console.log(`
Usage:
node source-manage.js list
node source-manage.js edit <id> --name "New Name" --url https://... --method browser
node source-manage.js edit <id> --name "New Name" --homepageUrl https://... --method browser
node source-manage.js edit <id> --concurrency 3 # parallel article fetching (multi-tab)
node source-manage.js edit <id> --paginate true # enable multi-page list harvesting
node source-manage.js enable <id>
node source-manage.js disable <id>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment