parent
26ddc8d992
commit
0320a78d18
@ -0,0 +1,15 @@
|
||||
{
|
||||
"permissions": {
|
||||
"openapi": [
|
||||
"search.submitPages"
|
||||
]
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
|
||||
"name": "submitPages",
|
||||
"type": "timer",
|
||||
"config": "0 0 2 * * * *"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "trigger",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"wx-server-sdk": "~2.0.2"
|
||||
}
|
||||
}
|
Loading…
Reference in new issue