This commit is contained in:
2025-03-28 16:27:26 +08:00
parent f654e16c18
commit a3e6a6d8b8
494 changed files with 4072 additions and 47246 deletions
@@ -4,10 +4,20 @@ const jqb_db = uniCloud.databaseForJQL();
module.exports = {
_before: function () { // 通用预处理器
},
async getDetail(query) {
console.log(query)
const res = await db.collection("uni-cms-articles").doc(query.id).get();
return res;
},
async getInfo(query) {
try {
// const tt = await db.collection("uni-cms-articles").doc("67ba7308bf7490a7f48d3ba3").get();
// console.log(tt);
let user_id = query.user_id;
let article_id = query.article_id;
@@ -48,8 +58,14 @@ module.exports = {
}
}
},
async get() {
const res = await db.collection(dbCollectionName).doc("67ba7308bf7490a7f48d3ba3").field("_id,is_admin,user_id,category_id,title,content,excerpt,article_status,is_sticky,is_essence,comment_status,thumbnail,publish_date").get();
console.log(res);
return res;
},
async getCmsArticleLog(query) {
try {
let article_id = query.article_id;
// cms-articles-log
@@ -0,0 +1,105 @@
const db = uniCloud.database();
const _ = db.command;
module.exports = {
_before: function () { // 通用预处理器
},
async getIsFollow(query) {
try {
const {
uid,
fid
} = query;
let isFollow = false;
console.log(uid)
console.log(fid)
const res = await db.collection("follow").where({
uid: uid,
fid: fid
})
.count();
console.log(res.total);
if (res.total > 0) {
isFollow = true;
}
return {
code: 200,
isFollow: isFollow
}
} catch(e) {
return {
code: 500,
msg: e.message
}
}
},
async follow(query) {
try {
const {
uid,
fid
} = query;
const res = await db.collection("follow").where({
uid: uid,
fid: fid
}).count();
if (res.total > 0) {
return {
code: 201,
msg: "已关注"
}
} else {
let dateTime = new Date();
const add_res = await db.collection("follow").add({
uid: uid,
fid: fid,
create_time: dateTime
})
console.log(add_res)
return {
code: 200,
data: add_res
}
}
} catch(e) {
return {
code: 500,
msg: e.message
}
}
},
async reFollow(query) {
try {
const {
uid,
fid
} = query;
const res = await db.collection("follow").where({
uid: uid,
fid: fid
}).count();
if (res.total < 0) {
return {
code: 201,
msg: "未关注"
}
} else {
const re_res = await db.collection("follow").where({
uid: uid,
fid: fid
}).remove();
console.log(re_res)
return {
code: 200,
data: re_res
}
}
} catch(e) {
return {
code: 500,
msg: e.message
}
}
}
}
@@ -0,0 +1,7 @@
{
"name": "follow",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
}
@@ -1,6 +1,6 @@
const db = uniCloud.database();
const _ = db.command;
const crypto = require('crypto');
let obj = {
isValidIP(ip) {
// ------------------------- IPv4 验证 -------------------------
@@ -39,7 +39,6 @@ let obj = {
return false;
},
isReservedOrLocalIP(ip) {
// ------------------------- IPv4 处理逻辑 -------------------------
if (ip.includes('.')) {
const parts = ip.split('.').map(Number);
// 格式验证
@@ -54,11 +53,11 @@ let obj = {
// 2. 保留地址
return (
parts[0] === 127 || // 127.0.0.0/8(环回地址)[1,4](@ref)
(parts[0] === 169 && parts[1] === 254) || // 169.254.0.0/16(链路本地地址)[4,5](@ref)
(parts[0] >= 224 && parts[0] <= 239) || // 224.0.0.0/4(多播地址)[3,5](@ref)
ip === '0.0.0.0' || // 未指定地址 [1](@ref)
ip === '255.255.255.255' // 广播地址 [1](@ref)
parts[0] === 127 ||
(parts[0] === 169 && parts[1] === 254) ||
(parts[0] >= 224 && parts[0] <= 239) ||
ip === '0.0.0.0' ||
ip === '255.255.255.255'
);
}
@@ -85,61 +84,57 @@ let obj = {
async getIPAddress(ip) {
if (!obj.isValidIP(ip)) return "未知";
if (obj.isReservedOrLocalIP(ip)) return "未知";
let address = "";
const res = await uniCloud.collection("ip").where({
const res = await db.collection("ip").where({
ip: ip
})
.field({
ip:true,
country: true,
economize: true,
market: true,
})
.get();
console.log(res);
if (res.data.length > 0) {
const res = await uniCloud.collection("ip").where({
ip: ip
})
.field({
ip:true,
country: true,
economize: true,
market: true,
})
.get();
if (res.data[0].market === "") address = res.data[0].country + " " + res.data[0].economize;
else {
address = res.data[0].economize + " " + res.data[0].market;
}
return address;
address = res.data.city;
}
let url= "https://62cccca0.api.cn/ipdata?token=7cec107b2f759a84211c74d9d9d6b4c4&datatype=json&ip=" + ip;
let key = "IPUBZ-ZWF6I-PQ4GR-56NKD-BLZYJ-YHFIY";
let requests = "/ws/location/v1/ip?ip=" + ip + "&key="+ key+ "&output=json";
let sk = "1YTD18oU9wjLtVTVJWYupigJjuTPGvae";
const sig = crypto.createHash('md5')
.update(requests+sk)
.digest("hex");
console.log(sig)
let url= "https://apis.map.qq.com"+ requests + "&sig=" + sig;
console.log(url);
const response = await uniCloud.httpclient.request(url, {
method: 'GET',
timeout: 1000
});
console.log(response);
console.log(response.data)
if (response.status === 200) {
await uniCloud.collection("ip").add({
ip: response.data.ip,
country: response.data.data[0]==="台湾"?"中国台湾":response.data.data[0],
economize: response.data.data[1],
market: response.data.data[2],
county: response.data.data[3],
operator: response.data.data[4],
postal_code: response.data.data[5],
area_code: response.data.data[6],
network: response.data.data[7]
});
if (response.data.data[2] === "" ) {
address = response.data.data[0] + " " + response.data.data[1];
}else {
address = response.data.data[1] + " " + response.data.data[2];
}
return address;
let json = JSON.parse(response.data.toString('utf8'));
if (json.message==="Success") {
await db.collection("ip").add({...json.result});
address = json.result.ad_info.province + " " + json.result.ad_info.city;
console.log(address)
return address;
}
}
return address;
return "未知";
}
}
@@ -157,16 +152,17 @@ module.exports = {
let res = await db.collection("uni-id-users")
.doc(uid)
.field({
_id: true,
nickname: true,
avatar_file: true,
last_login_ip:true,
register_date: true,
last_login_date:true,
personal_profile: true,
gender: true
_id: 1,
nickname: 1,
avatar_file: 1,
last_login_ip:1,
register_date: 1,
last_login_date:1,
personal_profile: 1,
gender: 1
})
.get();
console.log(res.data[0].last_login_ip)
res.data[0].last_login_ip = await obj.getIPAddress(res.data[0].last_login_ip);
console.log(res)