diff --git a/unfurler/package-lock.json b/unfurler/package-lock.json index 006ef5d0b..c1d977253 100644 --- a/unfurler/package-lock.json +++ b/unfurler/package-lock.json @@ -11,7 +11,7 @@ "@types/node": "^24.10.1", "ejs": "^3.1.10", "express": "^5.1.0", - "node-fetch-commonjs": "^3.3.2", + "node-fetch": "^3.3.2", "puppeteer": "^24.30.0", "puppeteer-cluster": "^0.25.0", "typescript": "~5.8.3" @@ -1531,6 +1531,29 @@ "pend": "~1.2.0" } }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "license": "MIT", + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -1636,6 +1659,18 @@ "integrity": "sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ==", "dev": true }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "license": "MIT", + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -2287,14 +2322,15 @@ "node": ">=10.5.0" } }, - "node_modules/node-fetch-commonjs": { + "node_modules/node-fetch": { "version": "3.3.2", - "resolved": "https://registry.npmjs.org/node-fetch-commonjs/-/node-fetch-commonjs-3.3.2.tgz", - "integrity": "sha512-VBlAiynj3VMLrotgwOS3OyECFxas5y7ltLcK4t41lMUZeaK15Ym4QRkqN0EQKAFL42q9i21EPKjzLUPfltR72A==", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", "license": "MIT", "dependencies": { - "node-domexception": "^1.0.0", - "web-streams-polyfill": "^3.0.3" + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" }, "engines": { "node": "^12.20.0 || ^14.13.1 || >=16.0.0" @@ -2304,6 +2340,15 @@ "url": "https://opencollective.com/node-fetch" } }, + "node_modules/node-fetch/node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "license": "MIT", + "engines": { + "node": ">= 12" + } + }, "node_modules/object-inspect": { "version": "1.13.4", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", @@ -4416,6 +4461,15 @@ "pend": "~1.2.0" } }, + "fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "requires": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + } + }, "file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -4499,6 +4553,14 @@ "integrity": "sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ==", "dev": true }, + "formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "requires": { + "fetch-blob": "^3.1.2" + } + }, "forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -4928,13 +4990,21 @@ "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" }, - "node-fetch-commonjs": { + "node-fetch": { "version": "3.3.2", - "resolved": "https://registry.npmjs.org/node-fetch-commonjs/-/node-fetch-commonjs-3.3.2.tgz", - "integrity": "sha512-VBlAiynj3VMLrotgwOS3OyECFxas5y7ltLcK4t41lMUZeaK15Ym4QRkqN0EQKAFL42q9i21EPKjzLUPfltR72A==", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", "requires": { - "node-domexception": "^1.0.0", - "web-streams-polyfill": "^3.0.3" + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "dependencies": { + "data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==" + } } }, "object-inspect": { diff --git a/unfurler/package.json b/unfurler/package.json index 72bfc997a..e2b44bf5e 100644 --- a/unfurler/package.json +++ b/unfurler/package.json @@ -20,7 +20,7 @@ "@types/node": "^24.10.1", "express": "^5.1.0", "ejs": "^3.1.10", - "node-fetch-commonjs": "^3.3.2", + "node-fetch": "^3.3.2", "puppeteer": "^24.30.0", "puppeteer-cluster": "^0.25.0", "typescript": "~5.8.3" diff --git a/unfurler/src/index.ts b/unfurler/src/index.ts index 661394cb7..268b9f138 100644 --- a/unfurler/src/index.ts +++ b/unfurler/src/index.ts @@ -118,16 +118,16 @@ class Server { this.app.set('view engine', 'ejs'); if (puppeteerEnabled) { - this.app.get('/unfurl/render*', async (req, res) => { return this.renderPreview(req, res) }) - this.app.get('/render*', async (req, res) => { return this.renderPreview(req, res) }) + this.app.get('/unfurl/render{*path}', async (req, res) => { return this.renderPreview(req, res) }) + this.app.get('/render{*path}', async (req, res) => { return this.renderPreview(req, res) }) } else { - this.app.get('/unfurl/render*', async (req, res) => { return this.renderDisabled(req, res) }) - this.app.get('/render*', async (req, res) => { return this.renderDisabled(req, res) }) + this.app.get('/unfurl/render{*path}', async (req, res) => { return this.renderDisabled(req, res) }) + this.app.get('/render{*path}', async (req, res) => { return this.renderDisabled(req, res) }) } - this.app.get('/unfurl*', (req, res) => { return this.renderHTML(req, res, true) }) - this.app.get('/slurp*', (req, res) => { return this.renderHTML(req, res, false) }) - this.app.get('/sip*', (req, res) => { return this.renderSip(req, res) }) - this.app.get('*', (req, res) => { return this.renderHTML(req, res, false) }) + this.app.get('/unfurl{*path}', (req, res) => { return this.renderHTML(req, res, true) }) + this.app.get('/slurp{*path}', (req, res) => { return this.renderHTML(req, res, false) }) + this.app.get('/sip{*path}', (req, res) => { return this.renderSip(req, res) }) + this.app.get('{*path}', (req, res) => { return this.renderHTML(req, res, false) }) } async clusterTask({ page, data: { url, path, action, reqUrl } }) { @@ -239,7 +239,7 @@ class Server { try { this.unfurlQueueLength++; const start = Date.now(); - const rawPath = req.params[0]; + const rawPath = req.params.path.join('/'); let img = null; @@ -263,7 +263,7 @@ class Server { res.send(img); } } catch (e) { - logger.err(e instanceof Error ? e.message : `${e} ${req.params[0]}`); + logger.err(e instanceof Error ? e.message : `${e} ${req.params.path.join('/')}`); res.status(500).send(e instanceof Error ? e.message : e); } finally { this.unfurlQueueLength--; @@ -272,7 +272,7 @@ class Server { async renderHTML(req, res, unfurl: boolean = false) { // drop requests for static files - const rawPath = req.params[0]; + const rawPath = req.params.path.join('/'); const match = rawPath.match(/\.[\w]+$/); if (match?.length && match[0] !== '.html' || rawPath.startsWith('/api/v1/donations/images') @@ -321,7 +321,7 @@ class Server { res.status(500).send(); } } catch (e) { - logger.err(e instanceof Error ? e.message : `${e} ${req.params[0]}`); + logger.err(e instanceof Error ? e.message : `${e} ${req.params.path.join('/')}`); res.status(500).send(e instanceof Error ? e.message : e); } finally { if (!unfurl) { @@ -385,7 +385,7 @@ class Server { async renderSip(req, res): Promise { const start = Date.now(); - const rawPath = req.params[0]; + const rawPath = req.params.path.join('/'); const { lang, path } = parseLanguageUrl(rawPath); const matchedRoute = matchRoute(this.network, path, 'sip'); diff --git a/unfurler/src/routes.ts b/unfurler/src/routes.ts index 3e10bf954..6f8dcc909 100644 --- a/unfurler/src/routes.ts +++ b/unfurler/src/routes.ts @@ -1,4 +1,4 @@ -import fetch from 'node-fetch-commonjs'; +import fetch from 'node-fetch'; import config from './config'; import http from 'node:http'; import https from 'node:https';