2 Star 11 Fork 3

emu/looking4help

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
query.js 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
'use strict';
const app = require("tcb-admin-node");
function times33(str){
for(var i = 0, len = str.length,hash = 5381; i < len; ++i){
hash += (hash << 5) + str.charCodeAt(i);
};
return hash & 0x7fffffff;
}
exports.main = async (event, context, callback) => {
app.init({env: process.env.ENV})
const db = app.database();
const _ = db.command;
let DB = process.env.DB
let callbackfunciton = "callback"
var accessHash = times33("wu"+process.env.accessKey).toString(36)+times33("han"+process.env.accessKey).toString(36);
var accessHash2 = times33("wu"+process.env.accessKey2).toString(36)+times33("han"+process.env.accessKey2).toString(36);
console.log(accessHash2)
var collection;
if(event.path && (event.path.indexOf(accessHash)>-1 || event.path.indexOf(accessHash2)>-1)){
DB = process.env.CASE_DB
callbackfunciton = "detailCallback"
collection=db.collection(DB);
}else{
DB = process.env.CASE_DB
callbackfunciton = "caseCallback"
collection = db.collection(DB).field({ 'lng': true,'lat': true,"types":true })
}
let limit = 999,skip=0;
let all = [],t=new Array(limit);
for(;(t.length == limit);skip+=limit){
t=(await collection.skip(skip).limit(limit).get()).data;
all = all.concat(t);
}
for(var i=0;i<all.length;i++){
delete all[i]._id
}
return {
'isBase64Encoded': false,
'statusCode' : 200,
'headers' : {'Content-Type':'application/x-javascript; charset=utf-8'},
'body' : callbackfunciton+"("+JSON.stringify(all)+")"
};
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
HTML
1
https://gitee.com/stonelf/looking4help.git
git@gitee.com:stonelf/looking4help.git
stonelf
looking4help
looking4help
master

搜索帮助