<commit_before>var express = require('express');
var request = require('superagent');
var app = new express();

var ZOTERO_BASEURL="http://localhost:1234";
var SESSION_ID="foo-123";


app.get('/', function(req, res, next) {
  if (!req.query.url) {
    return next("ERROR: Must specify url");
  }
  var format = 'ris';
  if (req.query.format) {
    format = req.query.format;
  }
  request
      .post(ZOTERO_BASEURL + "/web")
      .send({"url":req.query.url, "sessionid":SESSION_ID})
      .end(function(err, resp){
        if (err) return next(err);
        request
            .post(ZOTERO_BASEURL + "/export?format=" + format)
            .buffer(true)
            .send(resp.body)
            .end(function(err, resp) {
              if (err) return next(err);
              res.set('Content-Type', resp.get('Content-Type'))
              res.send(resp.text);
            });
      });
});

app.use(function errorHandler(err, req, res, next) {
  res.status(406).send(err);
});
app.listen(2000);<commit_msg>Add mode 'doi' which only returns the doi to a URL<commit_after>var express = require('express');
var request = require('superagent');
var app = new express();

var ZOTERO_BASEURL="http://localhost:1234";
var SESSION_ID="foo-123";


app.get('/', function(req, res, next) {
  if (!req.query.url) {
    return next("ERROR: Must specify url");
  }
  var format = 'ris';
  if (req.query.format) {
    format = req.query.format;
  }
  request
      .post(ZOTERO_BASEURL + "/web")
      .send({"url":req.query.url, "sessionid":SESSION_ID})
      .end(function(err, resp){
        if (err) return next(err);
        doiMode = format === 'doi';
        if (doiMode) {
          format = 'ris';
        }
        request
            .post(ZOTERO_BASEURL + "/export?format=" + format)
            .buffer(true)
            .send(resp.body)
            .end(function(err, resp) {
              if (err) return next(err);
              if (doiMode) {
                doiMatch = resp.text.match(/DO\s+-\s+(.*)/);
                if (! doiMatch) {
                  res.statusCode = 404;
                  res.end();
                } else {
                  res.set('Content-Type', "text/plain");
                  res.send(doiMatch[1]);
                }
              } else {
                res.set('Content-Type', resp.get('Content-Type'))
                res.send(resp.text);
              }
            });
      });
});

app.use(function errorHandler(err, req, res, next) {
  res.status(406).send(err);
});
app.listen(2000);
{'fraction_non_alphanumeric': 0.16949822204662188, 'fraction_numerical': 0.012643224022125641, 'mean_word_length': 1.9929078014184398, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6050933', 'n_tokens_mistral': 842, 'n_tokens_neox': 796, 'n_words': 160}