sitemap.js 6 KB
const SiteMapService = require('../../models/sitemap/sitemap-service');
const SiteMapServiceH5 = require('../../models/sitemap/sitemap-service-h5');

function indexXmlData(req, res, next) {
  req.ctx(SiteMapService).indexXml()
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function homeXmlData(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapService).homeXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function productXmlData(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapService).productXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function listXmlData(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapService).listXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function shopXmlData(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapService).shopXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function guangXmlData(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapService).guangXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function hotsXmlData(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapService).hotXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function chanpinXmlData(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapService).chanpinXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function indexJsonData(req, res, next) {
  req.ctx(SiteMapService).indexJson()
    .then(xml => {
      res.json(xml);
    })
    .catch(next);
}

function indexXmlDataH5(req, res, next) {
  req.ctx(SiteMapServiceH5).indexXml()
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function homeXmlDataH5(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapServiceH5).homeXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function productXmlDataH5(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapServiceH5).productXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function listXmlDataH5(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapServiceH5).listXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function shopXmlDataH5(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapServiceH5).shopXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function guangXmlDataH5(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapServiceH5).guangXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function hotsXmlDataH5(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapServiceH5).hotXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function chanpinXmlDataH5(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapServiceH5).chanpinXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function indexJsonDataH5(req, res, next) {
  req.ctx(SiteMapServiceH5).indexJson()
    .then(xml => {
      res.json(xml);
    })
    .catch(next);
}

function productIndexXmlData(req, res, next) {
  req.ctx(SiteMapService).productIndexXml()
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function productIndexXmlDataH5(req, res, next) {
  req.ctx(SiteMapServiceH5).productIndexXml()
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

// mip
function shopMipXmlDataH5(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapServiceH5).shopMipXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

function listMipXmlDataH5(req, res, next) {
  let page = +req.params.id || 1;

  if (page <= 0) {
    page = 1;
  }

  req.ctx(SiteMapServiceH5).listXml(page)
    .then(xml => {
      res.header('Content-Type', 'application/xml');
      res.send(xml);
    })
    .catch(next);
}

module.exports = {
  indexXmlData,
  homeXmlData,
  productXmlData,
  listXmlData,
  shopXmlData,
  guangXmlData,
  chanpinXmlData,
  hotsXmlData,
  indexJsonData,
  productIndexXmlData,

  indexXmlDataH5,
  homeXmlDataH5,
  productXmlDataH5,
  listXmlDataH5,
  shopXmlDataH5,
  guangXmlDataH5,
  chanpinXmlDataH5,
  hotsXmlDataH5,
  indexJsonDataH5,
  productIndexXmlDataH5,

  shopMipXmlDataH5,
  listMipXmlDataH5
};