~sircmpwn/gemreader

251b178b6b74d61c6a7f48e12a411b8f0dd3dafb — Drew DeVault 2 years ago b8563ce
web2gmi: do some validation on response
1 files changed, 14 insertions(+), 2 deletions(-)

M web2gmi.js
M web2gmi.js => web2gmi.js +14 -2
@@ 120,7 120,19 @@ const convert = (dom, title) => {

const args = process.argv.slice(2);
fetch(args[0])
  .then(res => res.text())
  .then(res => {
    if (!res.ok) {
      throw "Received non-200 response from server: " + res.status;
    }
    let ct = res.headers.get('content-type');
    if (ct.indexOf(';') !== -1) {
      ct = ct.slice(0, ct.indexOf(';'));
    }
    if (ct !== "text/html") {
      throw "Received non-HTML response " + ct;
    }
    return res.text();
  })
  .then(body => {
    const doc = new JSDOM(body, {
      url: args[0],


@@ 130,4 142,4 @@ fetch(args[0])
    const readable = new JSDOM(article.content, {url: args[0]});
    console.log(convert(readable.window.document, article.title));
  })
  .catch(() => console.log("An error occured while fetching this page."));
  .catch(err => console.log("An error occured while fetching this page: " + err));