You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.2 KiB
84 lines
2.2 KiB
|
|
const cloud = require('wx-server-sdk')
|
|
|
|
cloud.init()
|
|
|
|
|
|
exports.main = async (event, context) => {
|
|
const wxContext = cloud.getWXContext()
|
|
console.log(event);
|
|
let {TriggerName, Time} = event;
|
|
switch(TriggerName){
|
|
case "submitPages":{
|
|
return submitPages({Time});
|
|
}
|
|
}
|
|
}
|
|
|
|
async function submitPages({Time}){
|
|
console.log("start submitPages");
|
|
const db = cloud.database();
|
|
const _ = db.command;
|
|
const pageHistoryCollection = db.collection("pageHistory");
|
|
|
|
let shixunPath = "markdown/shixun/shixun/shixun";
|
|
let pathPath = "markdown/path/path/path";
|
|
let timeEnd = new Date(Time);
|
|
let timeStart = new Date(timeEnd.getTime()-24*60*60*1000);
|
|
|
|
let shixunResult = await pageHistoryCollection.where({
|
|
page: shixunPath,
|
|
status: 200,
|
|
time: _.lt(timeEnd).and(_.gte(timeStart))
|
|
}).get();
|
|
|
|
let pathResult = await pageHistoryCollection.where({
|
|
page: pathPath,
|
|
status:200,
|
|
time:_.lt(timeEnd).and(_.gte(timeStart))
|
|
}).get();
|
|
|
|
let shixunQueries = shixunResult.data.reduce(function(arr, v){
|
|
var query = Object.keys(v.options).map(k=>`${k}=${v.options[k]}`).join("&");
|
|
if(arr.indexOf(query)==-1)
|
|
arr.push(query);
|
|
return arr
|
|
},[]);
|
|
|
|
let pathQueries = pathResult.data.reduce(function(arr, v){
|
|
var query = Object.keys(v.options).map(k=>`${k}=${v.options[k]}`).join("&");
|
|
if(arr.indexOf(query)==-1)
|
|
arr.push(query);
|
|
return arr
|
|
},[]);
|
|
|
|
console.info("shixunQueries", shixunQueries.length, shixunQueries);
|
|
console.info("pathQueries", pathQueries.length, pathQueries);
|
|
|
|
if(shixunQueries.length>0){
|
|
var pages = shixunQueries.map(i=>{
|
|
return {
|
|
path: shixunPath,
|
|
query: i
|
|
}
|
|
});
|
|
var res = await cloud.openapi.search.submitPages({pages});
|
|
console.log("submit shixun pages",pages.length, res);
|
|
console.info("arguments", pages);
|
|
}else{
|
|
console.warn("no shixun history");
|
|
}
|
|
if(pathQueries.length>0){
|
|
var pages = pathQueries.map(i=>{
|
|
return {
|
|
path: pathPath,
|
|
query: i
|
|
}
|
|
});
|
|
var res = await cloud.openapi.search.submitPages({pages});
|
|
console.log("submit path pages success", pages.length, res);
|
|
console.info("arguments", pages);
|
|
}else{
|
|
console.warn("no path history");
|
|
}
|
|
} |