blog-server/controllers/article.js

43 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-12-02 16:08:44 +08:00
// title 文章标题 contern 文章内容
// 获取文章列表
2019-11-13 12:47:16 +08:00
var articlefind = async (ctx, next) => {
let articlelist;
await dbs.find("articlelists").then((res) => {
articlelist = res.data
ctx.body=articlelist
})
2019-12-02 16:08:44 +08:00
next()
2019-11-13 12:47:16 +08:00
}
2019-12-02 16:08:44 +08:00
// 添加文章
2019-11-13 12:47:16 +08:00
var articleadd = async (ctx, next) => {
let month=parseInt(new Date(Date.now()).getMonth())+1
2019-11-19 19:02:28 +08:00
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})
2019-11-13 12:47:16 +08:00
console.log(ctx.query)
ctx.body = "添加成功"
2019-12-02 16:08:44 +08:00
next()
2019-11-13 12:47:16 +08:00
}
2019-12-02 16:08:44 +08:00
// 删除文章
2019-11-13 12:47:16 +08:00
var articledel=async(ctx,next)=>{
2019-11-19 15:12:01 +08:00
await dbs.remove("articlelists",{num_key:parseInt(ctx.query.key)}).then((res)=>{
2019-11-13 12:47:16 +08:00
console.log(res)
console.log(ctx.query)
})
ctx.body="删除成功"
2019-12-02 16:08:44 +08:00
next()
2019-11-13 12:47:16 +08:00
}
2019-12-02 16:08:44 +08:00
// 修改文章
2019-11-13 12:47:16 +08:00
var articleupdate=async (ctx,next)=>{
let month=parseInt(new Date(Date.now()).getMonth())+1
2019-11-19 19:02:28 +08:00
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()})
2019-11-19 15:12:01 +08:00
ctx.body="修改成功"
2019-12-02 16:08:44 +08:00
next()
2019-11-19 15:12:01 +08:00
// 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())
2019-11-13 12:47:16 +08:00
}
module.exports = {
2019-12-02 17:10:38 +08:00
'POST /articleadd': articleadd,
2019-11-13 12:47:16 +08:00
'GET /articlefind': articlefind,
'GET /articledel': articledel,
2019-12-02 17:10:38 +08:00
'POST /articleupdate': articleupdate
2019-11-13 12:47:16 +08:00
};