blog-server/controllers/article.js
2019-12-02 16:08:44 +08:00

43 lines
1.8 KiB
JavaScript

// title 文章标题 contern 文章内容
// 获取文章列表
var articlefind = async (ctx, next) => {
let articlelist;
await dbs.find("articlelists").then((res) => {
articlelist = res.data
ctx.body=articlelist
})
next()
}
// 添加文章
var articleadd = async (ctx, next) => {
let month=parseInt(new Date(Date.now()).getMonth())+1
await dbs.add("articlelists", { articletitle:ctx.query.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.query.content,uid:1})
console.log(ctx.query)
ctx.body = "添加成功"
next()
}
// 删除文章
var articledel=async(ctx,next)=>{
await dbs.remove("articlelists",{num_key:parseInt(ctx.query.key)}).then((res)=>{
console.log(res)
console.log(ctx.query)
})
ctx.body="删除成功"
next()
}
// 修改文章
var articleupdate=async (ctx,next)=>{
let month=parseInt(new Date(Date.now()).getMonth())+1
await dbs.update("articlelists",{num_key:parseInt(ctx.query.key)},{articletitle:ctx.query.title, udate: 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()})
ctx.body="修改成功"
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())
}
module.exports = {
'GET /articleadd': articleadd,
'GET /articlefind': articlefind,
'GET /articledel': articledel,
'GET /articleupdate': articleupdate
};