Merge branch 'zj' of pplokijuhyg/blog-server into master
This commit is contained in:
commit
eda61f9601
@ -8,9 +8,14 @@ var articlefind = async (ctx, next) => {
|
|||||||
let articlelists=res.data
|
let articlelists=res.data
|
||||||
await dbs.find("group").then((res)=>{
|
await dbs.find("group").then((res)=>{
|
||||||
let groups=res.data
|
let groups=res.data
|
||||||
|
// 遍历 group表,检测 传入的groupid是不是在 group表中存在
|
||||||
|
// 如果不在,就返回所有文章
|
||||||
|
// 如果在group表中,就返回该分组的文章
|
||||||
for(let i in groups){
|
for(let i in groups){
|
||||||
if(parseInt(ctx.query.groupid)==groups[i].num_key){
|
if(parseInt(ctx.query.groupid)==groups[i].num_key){
|
||||||
// console.log(groups[i])
|
// console.log(groups[i])
|
||||||
|
// 判断 该分组是不是最后一层的分组 如果不是返回所有文章
|
||||||
|
// 如果是最后一层,(即没有 children),就返回该分组的文章 也就是 articlelist 的初始值
|
||||||
if(groups[i].fuid!=0){
|
if(groups[i].fuid!=0){
|
||||||
for(let m in articlelists){
|
for(let m in articlelists){
|
||||||
if(articlelists[m].groupid==parseInt(ctx.query.groupid)){
|
if(articlelists[m].groupid==parseInt(ctx.query.groupid)){
|
||||||
@ -28,8 +33,9 @@ var articlefind = async (ctx, next) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// articlelist = res.data
|
// articlelist = res.data
|
||||||
|
|
||||||
await dbs.find("articletag").then( async (res)=>{
|
await dbs.find("articletag").then( async (res)=>{
|
||||||
|
// 给articlelist 添加tag字段 从articletag表中取出每个文章的对应tagid
|
||||||
for(let i in articlelist){
|
for(let i in articlelist){
|
||||||
|
|
||||||
for(let m in res.data){
|
for(let m in res.data){
|
||||||
@ -51,11 +57,14 @@ var articlefind = async (ctx, next) => {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// articlelist的tag已经写入 tagid了,根据 label表 把tagid转化成labelname
|
||||||
await dbs.find("label").then((res)=>{
|
await dbs.find("label").then((res)=>{
|
||||||
for(let i in articlelist){
|
for(let i in articlelist){
|
||||||
for(let m in articlelist[i].tag){
|
for(let m in articlelist[i].tag){
|
||||||
console.log(articlelist[i].tag[m])
|
console.log(articlelist[i].tag[m])
|
||||||
for(let n in res.data){
|
for(let n in res.data){
|
||||||
|
// label的num_key 和articlelist 的tagid比对
|
||||||
if(res.data[n].num_key==articlelist[i].tag[m]){
|
if(res.data[n].num_key==articlelist[i].tag[m]){
|
||||||
articlelist[i].tag[m]=res.data[n].lablename
|
articlelist[i].tag[m]=res.data[n].lablename
|
||||||
}
|
}
|
||||||
@ -70,12 +79,14 @@ var articlefind = async (ctx, next) => {
|
|||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
// 添加文章
|
// 添加文章
|
||||||
// 参数: title 文章标题, content 文章内容 tags 选择的标签id 形式: 1,2
|
// 参数: title 文章标题, content 文章内容 tags 选择的标签id 形式: 1,2, group 分组id
|
||||||
var articleadd = async (ctx, next) => {
|
var articleadd = async (ctx, next) => {
|
||||||
let articleid=0
|
let articleid=0
|
||||||
let month=parseInt(new Date(Date.now()).getMonth())+1
|
let month=parseInt(new Date(Date.now()).getMonth())+1
|
||||||
// await dbs.add("articletag",{articleid:ctx.query.articleid,tagid:ctx.query.tagid})
|
// await dbs.add("articletag",{articleid:ctx.query.articleid,tagid:ctx.query.tagid})
|
||||||
await dbs.add("articlelists", { articletitle:ctx.request.body.title, date: new Date(Date.now()).getFullYear ()+ '/' + month+ '/' + new Date(Date.now()).getDate() + ' ' + new Date(Date.now()).getHours() + ':' + new Date(Date.now()).getMinutes() + ':' + new Date(Date.now()).getSeconds(),content:ctx.request.body.content,uid:1,groupid:ctx.request.body.groupid})
|
await dbs.add("articlelists", { articletitle:ctx.request.body.title, date: new Date(Date.now()).getFullYear ()+ '/' + month+ '/' + new Date(Date.now()).getDate() + ' ' + new Date(Date.now()).getHours() + ':' + new Date(Date.now()).getMinutes() + ':' + new Date(Date.now()).getSeconds(),content:ctx.request.body.content,uid:1,groupid:ctx.request.body.groupid})
|
||||||
|
|
||||||
|
|
||||||
await dbs.find("label").then(async (res)=>{
|
await dbs.find("label").then(async (res)=>{
|
||||||
// console.log(res.data)
|
// console.log(res.data)
|
||||||
await dbs.find("idadd").then((res)=>{
|
await dbs.find("idadd").then((res)=>{
|
||||||
@ -85,17 +96,19 @@ var articleadd = async (ctx, next) => {
|
|||||||
if(res.data[i].set=='articlelists'){
|
if(res.data[i].set=='articlelists'){
|
||||||
console.log(res.data[i].num_key-1,"article")
|
console.log(res.data[i].num_key-1,"article")
|
||||||
articleid=res.data[i].num_key-1
|
articleid=res.data[i].num_key-1
|
||||||
|
// 取 文章id: 从 idadd表 取 set=articlelsits 的 numkey-1就是 新文章的id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let tags=ctx.request.body.tags.split(",")
|
let tags=ctx.request.body.tags.split(",")
|
||||||
for(let i in tags){
|
for(let i in tags){
|
||||||
// console.log(tags[i])
|
// console.log(tags[i])
|
||||||
for(let m in res.data){
|
for(let m in res.data){
|
||||||
// console.log(res.data[m].num_key,parseInt(tags[i]))
|
// console.log(res.data[m].num_key,parseInt(tags[i]))
|
||||||
|
|
||||||
if(res.data[m].num_key==parseInt(tags[i])){
|
if(res.data[m].num_key==parseInt(tags[i])){
|
||||||
console.log(res.data[m].lablename,77774)
|
console.log(res.data[m].lablename,77774)
|
||||||
|
// 比对 label的num_key 和 传进来的tagsid 相等就往articletag写入 记录 文章id和标签id
|
||||||
await dbs.add("articletag",{articleid:articleid,tagid:parseInt(tags[i])})
|
await dbs.add("articletag",{articleid:articleid,tagid:parseInt(tags[i])})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,14 +138,6 @@ var articleupdate=async (ctx,next)=>{
|
|||||||
// console.log(new Date(Date.now()).getDate())
|
// console.log(new Date(Date.now()).getDate())
|
||||||
}
|
}
|
||||||
|
|
||||||
function text(s) {
|
|
||||||
var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]");
|
|
||||||
var rs = "";
|
|
||||||
for (var i = 0; i < s.length; i++) {
|
|
||||||
rs = rs+s.substr(i, 1).replace(pattern, '');
|
|
||||||
}
|
|
||||||
return rs;
|
|
||||||
}
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'POST /articleadd': articleadd,
|
'POST /articleadd': articleadd,
|
||||||
'GET /articlefind': articlefind,
|
'GET /articlefind': articlefind,
|
||||||
|
Loading…
Reference in New Issue
Block a user