This commit is contained in:
2025-06-13 20:46:10 +08:00
parent e285692d9c
commit 52e34ffd7c
322 changed files with 3383 additions and 6322 deletions
@@ -2,55 +2,83 @@ const db = uniCloud.database();
const _ = db.command;
const jqb_db = uniCloud.databaseForJQL();
module.exports = {
_before: function () { // 通用预处理器
_before: function() { // 通用预处理器
},
async getDetail(query) {
console.log(query)
const res = await db.collection("uni-cms-articles").doc(query.id).get();
const res = await db.collection("uni-cms-articles").doc(query.id).get();
return res;
},
async isSelectVote(query) {
try {
let {
user_id,
vote_id
} = query;
const res = await db.collection("cms-vote")
.where({
user_id: user_id,
vote_id: vote_id
})
.count();
let isSelectVote = false;
console.log(res.total)
if (res.total > 0) {
isSelectVote = true;
} else {
isSelectVote = false;
}
return {
code: 200,
isSelectVote: isSelectVote
}
} catch(e) {
return {
code: 500,
msg: e.message
}
}
},
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;
let isLike = false;
let isCollect = false;
const likeRes = await db.collection("cms-articles-like").where({
user_id: user_id,
article_id: article_id
})
.count();
user_id: user_id,
article_id: article_id
})
.count();
if (likeRes.total > 0) {
isLike = true;
}
const collectRes = await db.collection("cms-articles-collect").where({
user_id: user_id,
article_id: article_id
})
.count();
user_id: user_id,
article_id: article_id
})
.count();
if (collectRes.total > 0) {
isCollect = true;
}
return {
code: 200,
isLike: isLike,
isCollect: isCollect
}
} catch(e) {
} catch (e) {
console.log(e.message);
return {
code: 500,
@@ -59,40 +87,44 @@ 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();
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
// 生成文章日志临时表(过滤 article_id)
const logTemp = jqb_db.collection("cms-articles-log")
.where({ article_id: article_id })
.field('article_id, user_id, first_view_time')
.getTemp();
.where({
article_id: article_id
})
.field('article_id, user_id, first_view_time')
.getTemp();
// 生成用户信息临时表(仅返回必要字段)
const userTemp = jqb_db.collection("uni-id-users")
.field('_id,avatar_file')
.getTemp();
.field('_id,avatar_file')
.getTemp();
// 联表查询并分页
const collectRes = await jqb_db.collection(logTemp, userTemp)
.orderBy('logTemp.first_view_time asc') // 按时间倒序
.skip(0)
.limit(21)
.get();
.orderBy('logTemp.first_view_time asc') // 按时间倒序
.skip(0)
.limit(21)
.get();
return {
code: 200,
cmsArticleLog: collectRes.data
}
} catch(e) {
} catch (e) {
console.log(e.message);
return {
code: 500,
@@ -100,4 +132,4 @@ module.exports = {
}
}
}
}
}
@@ -1,7 +1,7 @@
{
"name": "cms-article-log",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
"dependencies": {
"quill-delta-converter": "file:../../../uni_modules/uni-cms-article/uniCloud/cloudfunctions/common/quill-delta-converter"
},
"extensions": {}
}
@@ -251,7 +251,7 @@ module.exports = {
code: 200,
data: {
commentList: commentList // 直接返回无需构建树形结构[8](@ref)
commentList: commentList
}
};
@@ -730,7 +730,7 @@ module.exports = {
content: comment.content,
createTime: comment.create_time,
ip_location: comment.ip_location,
// 新增子评论计数字段[4](@ref)
replyCount: comment.reply_count || 0,
children: [],
hasShowMore: false
@@ -1,28 +1,36 @@
const provider = "qiniu";
const extStorageManager = uniCloud.getExtStorageManager({
provider: "qiniu",
domain:"qnycdn.mymoyu.top",
bucketName:"dc-qiniu-alipay-env-00jxt5y29hrd-85e",
bucketSecret:"suyB1I04aREl5shtiow2dJlbUQaxowYX6Juxd4pyy208A8kJ8zdYObFW9YAwpzZg/1H6zsFdH+DgNtSx13l034a/tgoEV6+o1+V/mRp48zVeQraMwD/PaUel8k9bJtFMpIDMVWMrEOhCjq9NRPkR0xFPfIAOMilkJDDSZIr5eaJAR6pQL0A/wAYLVokw9xOBUovH6311FMxzEZWlpceVyA=="
});
module.exports = {
_before: function() {
},
getUploadFileOptions(data = {}) {
let {
cloudPath,
domain,
cloudPath
} = data;
// 可以在此先判断下此路径是否允许上传等逻辑
// ...
// 然后获取 extStorageManager 对象实例
const extStorageManager = uniCloud.getExtStorageManager({
provider, // 扩展存储供应商
domain, // 自定义域名
});
// 最后调用 extStorageManager.getUploadFileOptions
console.log(data);
let uploadFileOptionsRes = extStorageManager.getUploadFileOptions({
cloudPath: `public/${cloudPath}`, // 强制在public目录下
allowUpdate: false, // 是否允许覆盖更新,如果返回前端,建议设置false,代表仅新增,不可覆盖
cloudPath: `${cloudPath}`,
allowUpdate: false,
});
return uploadFileOptionsRes;
},
getTempFileURL(data = {}) {
let {
src
} = data;
let res = extStorageManager.getTempFileURL({
fileList: [src], // 文件地址列表
});
console.log('getTempFileURL: ', res);
return res;
},
// // 下载文件
// async downloadFile(data = {}) {
// let {
@@ -39,20 +47,16 @@ module.exports = {
// return res;
// },
// // 删除文件
// async deleteFile(data = {}) {
// let {
// fileList,
// domain
// } = data;
// const extStorageManager = uniCloud.getExtStorageManager({
// provider, // 扩展存储供应商
// domain, // 自定义域名
// });
// let res = await extStorageManager.deleteFile({
// fileList
// });
// console.log('deleteFile: ', res);
// return res;
// },
async deleteFile(data = {}) {
let {
fileList
} = data;
console.log(fileList)
let res = await extStorageManager.deleteFile({
fileList
});
console.log('deleteFile: ', res);
return res;
}
}
@@ -1,11 +1,12 @@
{
"name": "ext-storage-co",
"dependencies": {},
"extensions": {
"uni-cloud-ext-storage": {}
},
"origin-plugin-dev-name": "uni-template-admin",
"origin-plugin-version": "2.4.25",
"plugin-dev-name": "uni-template-admin",
"plugin-version": "2.4.25"
"type": "module",
"name": "ext-storage-co",
"dependencies": {},
"extensions": {
"uni-cloud-ext-storage": {}
},
"origin-plugin-dev-name": "uni-template-admin",
"origin-plugin-version": "2.4.25",
"plugin-dev-name": "uni-template-admin",
"plugin-version": "2.4.25"
}
@@ -5,6 +5,177 @@ module.exports = {
_before: function () { // 通用预处理器
},
async del_cms_articles(query) {
try {
console.log(query)
let {
id
} = query;
await collection.doc(id).remove();
return {
code: 200,
}
} catch(e) {
return {
code: 500,
msg: e.message
}
}
},
async get_cms_articles_for_userId(query) {
try {
console.log(query)
let {
user_id
} = query;
const res = await collection.where({
user_id: user_id,
"edit_type": "mobile"
}).get();
console.log(res)
return {
code: 200,
data:res.data
}
} catch(e) {
console.error(e.message)
return {
code: 500,
msg: e.message
}
}
},
async update_cms_articles(query) {
try{
let {
id,
title,
user_id,
title_html,
title_delta,
thumbnail,
p_type,
category_id,
temp_id,
edit_type,
excerpt,
view_count,
cmsLst,
last_modify_ip,
article_status
} = query;
let last_modify_date = new Date();
let publish_date = new Date();
const r = await collection.doc(id).update({
title,
user_id,
title_html,
title_delta,
thumbnail,
p_type,
category_id,
temp_id,
edit_type,
excerpt,
view_count,
cmsLst,
publish_date,
last_modify_date,
last_modify_ip,
article_status
});
console.log(r.id)
let res = await collection.doc(r.id)
.get();
return {
code: 200,
res: {
data: res.data[0],
_id: r.id,
user_id: user_id
}
}
} catch(e) {
return {
code:500,
msg: e.message
}
}
},
async add_cms_articles(query) {
try {
let {
title,
user_id,
title_html,
title_delta,
thumbnail,
p_type,
category_id,
temp_id,
edit_type,
excerpt,
view_count,
cmsLst,
last_modify_ip,
article_status
} = query;
let last_modify_date = new Date();
let publish_date = new Date();
const r = await collection.add({
title,
user_id,
title_html,
title_delta,
thumbnail,
p_type,
category_id,
temp_id,
edit_type,
excerpt,
view_count,
cmsLst,
publish_date,
last_modify_date,
last_modify_ip,
article_status
});
console.log(r.id)
let res = await collection.doc(r.id)
.get();
return {
code: 200,
res: {
data: res.data[0],
_id: r.id,
user_id: user_id
}
}
} catch(e) {
return {
code:500,
msg: e.message
}
}
},
async getTemp(query) {
try{
const {
temp_id
} = query;
const res = await db.collection("cms-temp").doc(temp_id).get();
console.log(res)
return {
code: 200,
data: res.data[0]
}
}catch(e) {
return {
code: 500,
msg: e.message
}
}
},
async getTotal() {
try {
@@ -41,17 +41,14 @@ let obj = {
isReservedOrLocalIP(ip) {
if (ip.includes('.')) {
const parts = ip.split('.').map(Number);
// 格式验证
if (parts.length !== 4 || parts.some(n => n < 0 || n > 255)) return false;
// 1. 局域网地址(私有地址)
if (
parts[0] === 10 || // 10.0.0.0/8 [1,2,4](@ref)
(parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31) || // 172.16.0.0/12 [1,2,4](@ref)
(parts[0] === 192 && parts[1] === 168) // 192.168.0.0/16 [1,2,4](@ref)
parts[0] === 10 ||
(parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31) ||
(parts[0] === 192 && parts[1] === 168)
) return true;
// 2. 保留地址
return (
parts[0] === 127 ||
(parts[0] === 169 && parts[1] === 254) ||
@@ -61,15 +58,12 @@ let obj = {
);
}
// ------------------------- IPv6 处理逻辑 -------------------------
// IPv6 处理逻辑
if (ip.includes(':')) {
// 规范化IPv6(展开缩写)
const normalized = ip.replace(/(^:|:$)/g, '::').replace(/::/g, ':0:').split(':')
.map(seg => seg.padStart(4, '0')).join(':').padStart(39, '0:');
if (normalized.startsWith('fc00:') || normalized.startsWith('fd00:')) return true;
// 2. 保留地址
return (
normalized === '0000:0000:0000:0000:0000:0000:0000:0001' ||
normalized.startsWith('fe80:') ||
@@ -142,7 +136,28 @@ module.exports = {
_before: function () { // 通用预处理器
},
async getIP(query) {
try {
let { uid } = query;
let res = await db.collection("uni-id-users")
.doc(uid)
.field({
_id: 1,
last_login_ip: 1
})
.get();
console.log(res.data[0]);
return {
code: 200,
data: res.data[0]
}
} catch(e) {
return {
code: 500,
msg: e.message
}
}
},
async get_user_info(query) {
try {
let uid = query.uid;
@@ -2,6 +2,6 @@
"name": "user-info",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
"uni-cloud-ext-storage": {}
}
}