diff --git a/server.js b/server.js index 7ef6d72..44591ab 100644 --- a/server.js +++ b/server.js @@ -35,77 +35,6 @@ app.use( }), ); -/** - * @param {string} shortName - * @param {string} publishDate - * @returns {Promise<{ previousMaturity: string, previousPublishDate: string }>} - * @throws {Promise<{ statusCode: number, error: string }>} - */ -function getPreviousVersionInfo(shortName, publishDate) { - return new Promise((resolve, reject) => { - const url = `https://www.w3.org/TR/${shortName}/`; - request.get(url, (error, response, body) => { - if (error) { - // eslint-disable-next-line prefer-promise-reject-errors - return reject({ statusCode: 400, error }); - } - - if ( - response && - response.statusCode >= 400 && - response.statusCode < 500 - ) { - const { statusCode, statusMessage } = response; - // eslint-disable-next-line prefer-promise-reject-errors - return reject({ statusCode, error: statusMessage }); - } - - const { document } = new JSDOM(body).window; - const dl = document.querySelector("body div.head dl"); - - let thisURI; - let previousURI; - if (dl) { - // eslint-disable-next-line no-restricted-syntax - for (const dt of dl.querySelectorAll("dt")) { - const txt = dt.textContent - .toLocaleLowerCase() - .replace(":", "") - .replace("published", "") - .trim(); - const dd = dt.nextElementSibling; - if (txt === "this version") { - thisURI = dd.querySelector("a").href; - } else if (/^previous version(?:s)?$/.test(txt)) { - previousURI = dd.querySelector("a").href; - } - } - } - if (!thisURI) { - // eslint-disable-next-line prefer-promise-reject-errors - return reject({ - statusCode: 5000, - error: `Couldn't find a 'This version' uri in the previous version.`, - }); - } - - const thisDate = thisURI.match(/[1-2][0-9]{7}/)[0]; - const prev = - thisDate === publishDate.replace(/-/g, "") - ? previousURI - : thisURI; - const pDate = prev.match(/[1-2][0-9]{7}/)[0]; - - const previousMaturity = prev.match(/\/TR\/[0-9]{4}\/([A-Z]+)/)[1]; - const previousPublishDate = pDate.replace( - /(\d{4})(\d{2})(\d{2})/, - "$1-$2-$3", - ); - resolve({ previousMaturity, previousPublishDate }); - }); - }); -} - async function extractTar(tarFile) { const extract = tar.extract(); const uploadPath = await mkdtemp("uploads/"); @@ -227,26 +156,11 @@ app.get( }, async (req, res) => { const specURL = new URL(req.query.url); - const shortName = specURL.searchParams.get("shortName"); const publishDate = specURL.searchParams.get("publishDate") || getShortIsoDate(); specURL.searchParams.set("publishDate", publishDate); - if (shortName) { - try { - const { previousMaturity, previousPublishDate } = - await getPreviousVersionInfo(shortName, publishDate); - specURL.searchParams.set("previousMaturity", previousMaturity); - specURL.searchParams.set( - "previousPublishDate", - previousPublishDate, - ); - } catch ({ statusCode, error }) { - return res.status(statusCode).json({ error }); - } - } - // if there's an error we get an err object with status and message, otherwise we get content try { const { html, errors, warnings } = await genMap[req.query.type]( diff --git a/test/test.js b/test/test.js index e47ef07..c116907 100644 --- a/test/test.js +++ b/test/test.js @@ -8,8 +8,6 @@ const BASE_URL = "http://localhost:3000/"; const NO_URL = "?type=foo&URL=notice-that-its-in-uppercase"; const NO_TYPE = "?url=foo&TYPE=notice-that-its-in-uppercase"; const BAD_GENERATOR = "?type=fluxor&url=http://example.com/"; -const BAD_SHORTNAME = - "?type=respec&url=http://example.com/%3FshortName%3Ddiplodocus"; const NO_RESPEC = "?type=respec&url=http://example.com/"; const SUCCESS1 = `?type=respec&url=https://w3c.github.io/manifest/`; const SUCCESS2 = `?type=respec&url=https://w3c.github.io/payment-request/`; @@ -55,11 +53,6 @@ describe("spec-generator", () => { BASE_URL + BAD_GENERATOR, FAILS_WITH(done, '{"error":"Unknown generator: fluxor"}'), )); - it("if the shortname is not valid", done => - REQUEST.get( - BASE_URL + BAD_SHORTNAME, - FAILS_WITH(done, '{"error":"Not Found"}', 404), - )); it("if the URL does not point to a Respec document", done => REQUEST.get( BASE_URL + NO_RESPEC,