A 页面跟踪并提交索引

master
educoder_weapp 5 years ago
parent 26ddc8d992
commit 0320a78d18

@ -1,3 +1,8 @@
## v0.16.6
* A 支持选用微信头像
* F 兼容Promise.finally
* F 爬虫访问处理
## v0.16.5
* A 头像安全检查
* U 信息安全检查速度

@ -5,11 +5,30 @@ cloud.init()
exports.main = async (event, context) => {
let {name, data} = event;
const wxContext = cloud.getWXContext()
const wxContext = cloud.getWXContext();
let db = cloud.database();
switch (name) {
case 'getOpenData': {
return cloud.getOpenData(data);
}
case "login":{
return {
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
env: wxContext.ENV,
}
}
case "reportPageHistory":{
db.collection("pageHistory").add({
data:{
...data,
time: new Date(),
timestamp: Date.now(),
openid: wxContext.OPENID
}
});
}
default: {
return
}

@ -12,7 +12,7 @@ exports.main = (event, context) => {
const wxContext = cloud.getWXContext()
console.log("call api login", event);
return {
openid: wxContext.OPENID,
appid: wxContext.APPID,

@ -7,7 +7,7 @@ cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV})
exports.main = async (event, context) => {
console.log("调用云函数openapi, 参数event", event);
let {name, data} = event;
switch (event.name||event.action) {
switch (name||event.action) {
case "wxacode.getUnlimited":
case "getWXACodeUnlimited":{
return getWXACodeUnlimited(data)
@ -48,12 +48,12 @@ exports.main = async (event, context) => {
return e;
}
}
case 'getOpenData': {
return cloud.getOpenData(data);
}
case "search.siteSearch":{
return cloud.openapi.search.siteSearch(data);
}
case "search.submitPages":{
return cloud.openapi.search.submitPages(data);
}
default: {
return
}

@ -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"
}
}

@ -10,7 +10,9 @@ App({
globalData: {
versionCode: config.versionCode,
debug: config.debug,
openid:wx.getStorageSync('openid')
openid:wx.getStorageSync('openid'),
isCrawl: false, //是否是爬虫
scene: -1
},
client,
openapi(name){
@ -19,7 +21,7 @@ App({
}
},
cloudapi(name){
return ({success, fail, complete, ...data})=>{
return ({success, fail, complete, ...data}={})=>{
return this.callCloudfunction({
name:"cloudapi", data:{name, data}, success, fail, complete
});
@ -55,15 +57,29 @@ App({
syncUser(options) { return client.syncUser(options) },
updateUserInfo(info){return client.updateUserInfo(info)},
onLaunch: function (options) {
if(options.scene==1129||options["user-agent"]=="mpcrawler"){
this.globalData.scene = options.scene;
if(options.scene==1129){
this.globalData.isCrawl = true;
this.cloudfunction("login")({mpcrawl: true});
this.api("accounts.login")(global.accountManager.testAccount)
.then(res=>{
let account = { ...res, ...global.accountManager.testAccount};
global.accountManager.setCurrentAccount(account);
});
/* 访
wx.reportMonitor('1', 1);
global.realTimeLog.info("爬虫访问", options);
global.realTimeLog.setFilterMsg("mpcrawl");
*/
}else if(!this.globalData.openid){
this.cloudfunction("login")()
.then(res=>{
this.globalData.openid = res.openid;
wx.setStorage({
data: res.openid,
key: 'openid',
})
})
}
if (options.referrerInfo && options.referrerInfo.appId) {
var db = wx.cloud.database();
@ -96,16 +112,7 @@ App({
})
}
}).catch(e=>{});
if(!this.globalData.openid){
this.cloudfunction("login")()
.then(res=>{
this.globalData.openid = res.openid;
wx.setStorage({
data: res.openid,
key: 'openid',
})
})
}
},
onShow() {
@ -159,6 +166,18 @@ App({
}
});
// 兼容finally
if(!Promise.prototype.finally){
Promise.prototype.finally = function (callback) {
let P =this.constructor;
return this.then(
value => P.resolve(callback()).then(() => value),
reason => P.resolve(callback()).then(() => {throw reason })
);
};
}
/*
function getCurrentPath() {
let pages = getCurrentPages();

@ -1,4 +1,4 @@
import { deprecate} from "../../js/utils";
const app = getApp();
Component({
properties: {
@ -29,7 +29,8 @@ Component({
},
methods:{
refresh(){
return app.syncUser().then(res=>{
return app.syncUser()
.then(res=>{
if(this.data.user_id!=res.user.user_id){
if(this.data.user_id!=-1)
this.triggerEvent("change",{});

@ -1,35 +1,37 @@
const cloudDir = "cloud://educoder.6564-educoder-1300855313/";
let { miniProgram:{ envVersion, version}={}} = wx.getAccountInfoSync();
let _version = "0.16.6";
/**
*/
let { miniProgram:{ envVersion="release", version=_version}={}} = wx.getAccountInfoSync();
version = version||_version;
const developUrl = "https://test-newweb.educoder.net";
const trialUrl = "https://pre-newweb.educoder.net";
const releaseUrl = "https://www.educoder.net";
let _version = "0.16.5";
var eduUrl = releaseUrl;
/**
*/
export function switchEnv(env) {
config.env = env;
if (env == "develop") {
eduUrl = developUrl;
config.version = "开发环境 " + _version +"(点击切换)";
config.version = "开发环境 " + version +"(点击切换)";
}
else if (env == "trial") {
eduUrl = trialUrl;
config.version = "体验版 " + _version;
config.version = "体验版 " + version;
}
else {
eduUrl = releaseUrl;
config.version = version||_version;
config.version = version;
}
}
const config = global.config = {
version:version||_version,
version,
envVersion,
env:envVersion,
get apiRoot(){return eduUrl + "/api/"},

@ -1,4 +1,3 @@
export function deprecate(name=""){
try{
throw new Error(name + "这个方法或界面被弃用了");
@ -272,7 +271,7 @@ export function throttle(func, wait, options) {
};
export function RealTimeLogManager(){
const log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null;
const log = wx.getRealtimeLogManager&&global.config.envVersion=='release'? wx.getRealtimeLogManager() : null;
return {
debug(...args) {
console.debug.apply(null, arguments);

@ -74,21 +74,32 @@ Page({
res=>{
if(showLoading)
wx.hideLoading()
});
}
);
wx.setNavigationBarTitle({
title:"实践课程-"+res[0].name
})
app.cloudapi("reportPageHistory")({
page: this.route,
options: this.options,
status: 200,
scene: app.globalData.scene,
isCrawl: app.globalData.isCrawl
})
return res;
}).catch(e=>{
if(e.code==403)
e.message = "您没有权限访问"
wx.hideLoading();
app.showError(e);
return e;
})
},
onShareAppMessage: function () {
let {subject} = this.data;
return app.shareApp({
title: subject.name,
title: "[实践课程]"+subject.name,
imageUrl: global.config.eduUrl + "/" + subject.cover
})
}

@ -22,7 +22,6 @@ Page({
let api_name = is_collect?"collections.cancel":"collections";
app.api(api_name)({container_type:"Shixun", container_id:id})
.then(res=>{
;
this.pullShixun({showLoading: 0});
if(is_collect){
res.message = "已取消收藏";
@ -81,22 +80,35 @@ Page({
if(showLoading)
wx.hideLoading()
});
wx.setNavigationBarTitle({
title: "实训项目-" + shixun.name
});
return shixun;
},
onLoad: function (options) {
console.log(options);
let {identifier,cate_type} = options;
let current = cateTypes[cate_type];
this.setData({identifier, current});
this.pullChallenges().catch(e=>{
});
this.pullShixun().catch(e=>{
this.pullShixun().then(res=>{
app.cloudapi("reportPageHistory")({
page: this.route,
options: this.options,
status: 200,
scene: app.globalData.scene,
isCrawl: app.globalData.isCrawl
})
}).catch(e=>{
app.showError(e);
});
},
onShareAppMessage: function () {
return app.shareApp({
title:this.data.shixun.name,
title:"[实训项目]"+this.data.shixun.name,
imageUrl: global.config.eduImgDir+"avatars/Shixun/"+this.data.shixun.id
})
}

@ -29,6 +29,10 @@
"action":"disallow",
"page":"account/pages/accounts/accounts"
},
{
"action":"disallow",
"page":"account/pages/profile/profile"
},
{
"action":"disallow",
"page":"course/pages/course/course"

@ -42,6 +42,7 @@
"isGameTourist": false,
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"cloudfunctionTemplateRoot": "cloudfunctionTemplate",
"condition": {
"search": {
"current": -1,
@ -130,11 +131,11 @@
"scene": 1129
},
{
"id": 16,
"name": "shixun/pages/shixun/shixun",
"pathName": "shixun/pages/shixun/shixun",
"id": 9,
"name": "markdown/shixun/shixun/shixun",
"pathName": "markdown/shixun/shixun/shixun",
"query": "identifier=8bu9zmjy",
"scene": null
"scene": 1000
},
{
"id": 17,
@ -217,6 +218,7 @@
"id": -1,
"name": "setting/pages/image_crop/image_crop",
"pathName": "setting/pages/image_crop/image_crop",
"query": "",
"scene": null
}
]

Loading…
Cancel
Save