From 807082942c8b4c9d1b2a063fb0d0c2cdbdfaf309 Mon Sep 17 00:00:00 2001 From: kyoto-aircon Date: Sun, 8 Nov 2026 06:10:26 +0000 Subject: [PATCH] fix(server): restore fetch-url and bulk-fetch routes Commit 82962fe removed both routes while refactoring the usage page. The client still calls them, so Add Skill from URL and bulk import fail with 404 Cannot POST /api/fetch-url. Restore the two routes using the global fetch API. --- server/index.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/server/index.js b/server/index.js index c38b9ec..606b621 100644 --- a/server/index.js +++ b/server/index.js @@ -3220,6 +3220,47 @@ app.post('/api/github/autosync', async (req, res) => { res.json({ success: true, enabled }); }); +app.post('/api/fetch-url', async (req, res) => { + const { url } = req.body || {}; + if (!url) return res.status(400).json({ error: 'URL required' }); + + try { + const response = await fetch(url); + if (!response.ok) throw new Error(`Failed to fetch: ${response.statusText}`); + const content = await response.text(); + const filename = path.basename(new URL(url).pathname) || 'file.txt'; + res.json({ content, filename, url }); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + +app.post('/api/bulk-fetch', async (req, res) => { + const { urls } = req.body || {}; + if (!Array.isArray(urls)) return res.status(400).json({ error: 'URLs array required' }); + + const results = []; + for (const url of urls) { + try { + const response = await fetch(url); + if (!response.ok) throw new Error(`Failed to fetch: ${response.statusText}`); + const content = await response.text(); + const filename = path.basename(new URL(url).pathname) || 'file.txt'; + results.push({ + url, + success: true, + content, + filename, + name: filename.replace(/\.(md|js|ts)$/i, ''), + }); + } catch (err) { + results.push({ url, success: false, error: err.message }); + } + } + + res.json({ results }); +}); + const getActiveSkillDir = () => { const cp = getConfigPath(); return cp ? path.join(path.dirname(cp), 'skills') : null;