From 01fdf162137562325ee66647f3170d9877090ecc Mon Sep 17 00:00:00 2001 From: luk Date: Wed, 7 Oct 2026 10:29:19 +0800 Subject: [PATCH] =?UTF-8?q?seafile=5Fignore=5Ffind2merge.js=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E7=95=99=E7=A9=BA=20globalPath=20=E4=B8=8D=E5=9B=9E?= =?UTF-8?q?=E9=80=80=E9=BB=98=E8=AE=A4=20URL=EF=BC=8C=E5=8A=A0=E5=9B=BA=20?= =?UTF-8?q?fetch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 交互留空 globalPath 时回退默认 URL(与 .sh 一致);初版漏掉了这步回退, 导致留空时把空串传给路径检查,报 "Not found [[]]" - ask() 处理 stdin EOF(非 TTY 无输入时按留空处理,不再卡住) - fetch 默认 URL 加长超时至 30s 并失败重试一次(git.tic.cc 的 TCP 连接 有时超过 node 默认 10s 连接超时,实测时通时断) Co-Authored-By: AtomCode (qwen3.8-27b) --- seafile_ignore_find2merge.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/seafile_ignore_find2merge.js b/seafile_ignore_find2merge.js index 7e04fd2..a1cab26 100644 --- a/seafile_ignore_find2merge.js +++ b/seafile_ignore_find2merge.js @@ -20,6 +20,7 @@ // - the root dir itself is processed too (the .sh's find -name '[^.]*' never matched the root dir) // - a dir is updated iff it has seafile-ignore.txt OR seafile-ignore.local.txt (the .sh's `.git` check was dropped) // - tree search is max depth 3, skipping hidden dirs and the known build/dep dirs +// - blank globalPath falls back to the default URL, as in the .sh (first draft missed this → "Not found [[]]") // - the .sh does `cat $GLOBALPATH` which fails when the default is a URL; here http(s) is fetched with fetch(), // a local file / parent-dir keeps the original behavior. @@ -41,7 +42,12 @@ function resolveHome (p) { async function ask (question) { const rl = readline.createInterface({ input: process.stdin, output: process.stdout }) - const answer = await new Promise(resolve => rl.question(question, resolve)) + const answer = await new Promise(resolve => { + let settled = false + const finish = value => { if (!settled) { settled = true; resolve(value) } } + rl.question(question, a => finish(a)) + rl.on('close', () => finish('')) // stdin ended without input (EOF): treat as blank, like the .sh's `read` + }) rl.close() return answer.trim() } @@ -75,12 +81,20 @@ async function loadGlobalContent (globalPathInput) { const globalPath = resolveHome(globalPathInput) if (/^https?:\/\//i.test(globalPath)) { console.log('√√√ GLOBALPATH (url) = [[' + globalPath + ']]') - const response = await fetch(globalPath) - if (!response.ok) { - console.log('××× Fetch failed: HTTP ' + response.status + ' for [[' + globalPath + ']]. Exit now...') - process.exit(1) + // git.tic.cc's TCP connect can exceed node's default 10s connect timeout; allow 30s and retry once. + let lastError + for (let attempt = 1; attempt <= 2; attempt++) { + try { + const response = await fetch(globalPath, { signal: AbortSignal.timeout(30000) }) + if (!response.ok) throw new Error('HTTP ' + response.status) + return await response.text() + } catch (error) { + lastError = error + console.log('... fetch attempt ' + attempt + ' failed: ' + (error.cause?.code || error.message)) + } } - return response.text() + console.log('××× Fetch failed: ' + (lastError.cause?.code || lastError.message) + ' for [[' + globalPath + ']]. Exit now...') + process.exit(1) } let globalFile = globalPath if (fs.existsSync(globalPath) && fs.statSync(globalPath).isDirectory()) { @@ -119,6 +133,7 @@ async function main () { if (!globalPathInput) { console.log('::*** Enter [path to seafile-ignore.global.txt] or [leave blank] for default [[' + DEFAULT_GLOBAL_URL + ']]') globalPathInput = await ask('***:: ') + if (!globalPathInput) globalPathInput = DEFAULT_GLOBAL_URL // blank → default URL, as in the .sh } const globalContent = await loadGlobalContent(globalPathInput) console.log('')