From 2730de72cbab63a002a0a27d0df31c19538c1ddd Mon Sep 17 00:00:00 2001 From: asd <374367073@qq.com> Date: Thu, 5 Dec 2019 10:42:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/article.js | 53 +++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/controllers/article.js b/controllers/article.js index dd5da8e..1376c66 100644 --- a/controllers/article.js +++ b/controllers/article.js @@ -10,19 +10,45 @@ var articlefind = async (ctx, next) => { } // 添加文章 var articleadd = async (ctx, next) => { + let articleid=0 let month=parseInt(new Date(Date.now()).getMonth())+1 // 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}) - await dbs.find("idadd").then((res)=>{ - console.log(res.data[res.data.length-1].num_key) + 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}) + await dbs.find("label").then(async (res)=>{ + // console.log(res.data) + await dbs.find("idadd").then((res)=>{ + // console.log(res) + for(let i in res.data){ + // console.log(res.data[i].set) + if(res.data[i].set=='articlelists'){ + console.log(res.data[i].num_key-1,"article") + articleid=res.data[i].num_key-1 + } + } + }) let tags=ctx.request.body.tags.split(",") - console.log(ctx.request.body.tags.split(",")) - for(let i in ctx.request.body.tags.split(",")){ - // console.log(ctx.request.body.tags.split(",")[i]) - await dbs.add("articletag",{articleid:res.data[res.data.length-1].num_key,tagid:ctx.request.body.tags.split(",")[i]}) - console.log("") - + for(let i in tags){ + // console.log(tags[i]) + for(let m in res.data){ + // console.log(res.data[m].num_key,parseInt(tags[i])) + + if(res.data[m].num_key==parseInt(tags[i])){ + console.log(res.data[m].lablename,77774) + await dbs.add("articletag",{articleid:articleid,tagid:parseInt(tags[i])}) + } + } } + + // console.log(res.data.length) + // console.log(res.data[res.data.length-1].num_key) + // let tags=ctx.request.body.tags.split(",") + // console.log(ctx.request.body.tags.split(",")) + // for(let i in ctx.request.body.tags.split(",")){ + // // console.log(ctx.request.body.tags.split(",")[i]) + // await dbs.add("articletag",{articleid:res.data[res.data.length-1].num_key,tagid:ctx.request.body.tags.split(",")[i]}) + // console.log("success") + + // } // await dbs.add("articletag",{articleid:res.data[res.data.length-1].num_key,tagid:ctx.query.tagid}) }) console.log(ctx.request.body) @@ -48,6 +74,15 @@ var articleupdate=async (ctx,next)=>{ // console.log(new Date(Date.now()).getFullYear ()+ '/' + month+ '/' + new Date(Date.now()).getDate() + ' ' + new Date(Date.now()).getHours() + ':' + new Date(Date.now()).getMinutes()) // 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 = { 'POST /articleadd': articleadd, 'GET /articlefind': articlefind,