index.js
2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
const moment = require('moment');
const SeoIndexModel = require('../../models/seo/index');
const BaiduLinkSubmit = require('../../models/seo/baidu-link-submit');
const index = (req, res) => {
if (global.IS_GOODS_XML_RUN) {
return res.json({code: 201, message: '上一个任务正在运行中...'});
}
global.IS_GOODS_XML_RUN = true;
req.ctx(SeoIndexModel).writerGoodsXml(req.params).then(() => {
global.IS_GOODS_XML_RUN = false;
});
return res.json({
code: 200,
data: `${req.protocol}://${req.hostname}/xml-data/goods-xml/goods-${req.params.start || 1}.xml`,
message: '任务创建成功,开始运行...'
});
};
const autoGoodsXml = (req, res) => {
if (global.IS_GOODS_XML_RUN) {
return res.json({code: 201, message: '上一个任务正在运行中...'});
}
global.IS_GOODS_XML_RUN = true;
req.ctx(SeoIndexModel).autoGoodsXml({start: 1});
res.json({code: 200, message: '任务创建成功,开始运行...'});
};
const goodsUrl = (req, res) => {
return req.ctx(BaiduLinkSubmit).goodsUrl().then(result => {
return res.json(result);
});
};
const guangUrl = (req, res) => {
return req.ctx(BaiduLinkSubmit).guangUrl().then(result => {
return res.json(result);
});
};
const setTask = (req, res) => {
return req.ctx(SeoIndexModel).setTask(req.query).then(result => {
return res.json(result);
});
};
const delTask = (req, res) => {
return req.ctx(SeoIndexModel).delTask(req.query).then(result => {
return res.json(result);
});
};
const demoXml = (req, res) => {
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
res.render('seo/demo-xml');
};
const demoXsd = (req, res) => {
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
res.render('seo/demo-xsd');
};
const siteMapXml = (req, res) => {
req.ctx(SeoIndexModel).getGoodsPage().then(result => {
let date = moment(new Date()).format('YYYY-MM-DD');
let sitemap = new Array(result).fill().map((val, k) => {
return {url: `${req.protocol}://${req.hostname}/xml-data/goods-xml/goods-${k + 1}.xml`, date: date};
});
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
return res.render('seo/site-map', {sitemap});
});
};
module.exports = {
index,
autoGoodsXml,
siteMapXml,
goodsUrl,
guangUrl,
setTask,
delTask,
demoXsd,
demoXml
};