<commit_before>'use strict';

//region Imports

const is = require('./is');
const ld = require('./json-ld');
const log = require('./logger');
const cache = require('./cache');
const config = require('./config');
const util = require('./util');
const template = require('./template');
const factory = require('./factory');
const library = require('./library');
const C = require('./constants');
// route placeholders
const ph = C.route;

//endregion
//region Map

const map = require('./map');
// can be replaced with injection
let google = require('./google');

/**
 * Map screen loads then makes AJAX call to fetch data
 * @param {Post} post
 * @param req
 * @param res
 */
function mapView(post, req, res) {
   if (is.value(post)) {
      const key = post.isPartial ? post.seriesKey : post.key;
      const photoID = req.params[ph.PHOTO_ID];

      res.render(template.page.MAP, {
         layout: template.layout.NONE,
         title: 'Map',
         post,
         key,
         photoID: is.numeric(photoID) ? photoID : 0,
         config
      });
   } else {
      res.notFound();
   }
}

function mapForPost(req, res) {
   mapView(library.postWithKey(req.params[ph.POST_KEY]), req, res);
}

function mapForSeries(req, res) {
   mapView(library.postWithKey(req.params[ph.SERIES_KEY], req.params[ph.PART_KEY]), req, res);
}

/**
 * Compressed GeoJSON as zipped byte array
 */
function mapJSON(req, res) {
   factory.map.forPost(req.params[ph.POST_KEY])
      .then(item => { res.sendCompressed(C.mimeType.JSON, item); })
      .catch(err => {
         log.error(err);
         res.notFound();
      });
}

function mapGPX(req, res) {
   let post = config.map.allowDownload ? library.postWithKey(req.params[ph.POST_KEY]) : null;

   if (is.value(post)) {
      res.setHeader(C.header.content.DISPOSITION, `attachment; filename=${post.key}.gpx`);
      res.setHeader(C.header.content.TYPE, C.mimeType.GPX);
      google.drive.loadGPX(post, res).then(()=> res.end());<commit_msg>catch missing GPX promise error<commit_after>'use strict';

//region Imports

const is = require('./is');
const ld = require('./json-ld');
const log = require('./logger');
const cache = require('./cache');
const config = require('./config');
const util = require('./util');
const template = require('./template');
const factory = require('./factory');
const library = require('./library');
const C = require('./constants');
// route placeholders
const ph = C.route;

//endregion
//region Map

const map = require('./map');
// can be replaced with injection
let google = require('./google');

/**
 * Map screen loads then makes AJAX call to fetch data
 * @param {Post} post
 * @param req
 * @param res
 */
function mapView(post, req, res) {
   if (is.value(post)) {
      const key = post.isPartial ? post.seriesKey : post.key;
      const photoID = req.params[ph.PHOTO_ID];

      res.render(template.page.MAP, {
         layout: template.layout.NONE,
         title: 'Map',
         post,
         key,
         photoID: is.numeric(photoID) ? photoID : 0,
         config
      });
   } else {
      res.notFound();
   }
}

function mapForPost(req, res) {
   mapView(library.postWithKey(req.params[ph.POST_KEY]), req, res);
}

function mapForSeries(req, res) {
   mapView(library.postWithKey(req.params[ph.SERIES_KEY], req.params[ph.PART_KEY]), req, res);
}

/**
 * Compressed GeoJSON as zipped byte array
 */
function mapJSON(req, res) {
   factory.map.forPost(req.params[ph.POST_KEY])
      .then(item => { res.sendCompressed(C.mimeType.JSON, item); })
      .catch(err => {
         log.error(err);
         res.notFound();
      });
}

function mapGPX(req, res) {
   let post = config.map.allowDownload ? library.postWithKey(req.params[ph.POST_KEY]) : null;

   if (is.value(post)) {
      google.drive.loadGPX(post, res)
         .then(()=> {
            res.setHeader(C.header.content.DISPOSITION, `attachment; filename=${post.key}.gpx`);
            res.setHeader(C.header.content.TYPE, C.mimeType.GPX);
            res.end();
         })
         // errors already logged by loadGPX()
         .catch(res.notFound);
{'fraction_non_alphanumeric': 0.16930572472594396, 'fraction_numerical': 0.00048721071863581, 'mean_word_length': 3.0058536585365854, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3051474', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1307, 'n_words': 300}