diff --git a/index.js b/index.js index 99e7b63..aba4a46 100644 --- a/index.js +++ b/index.js @@ -71,7 +71,7 @@ router.get('/edit/:id', async ctx => { router.post('/edit', koaBody, async ctx => await editPost(ctx, dbName)) -router.get('/categories/:tag', async ctx => await categoriesTagGet(ctx, dbName)) +router.get('/:tag', async ctx => await categoriesTagGet(ctx, dbName)) /** * The user registration page. diff --git a/public/articleImages/4.png b/public/articleImages/4.png new file mode 100644 index 0000000..13a80aa Binary files /dev/null and b/public/articleImages/4.png differ diff --git a/routes/categories.tag.get.js b/routes/categories.tag.get.js index 842ffc8..04c8b66 100644 --- a/routes/categories.tag.get.js +++ b/routes/categories.tag.get.js @@ -1,25 +1,15 @@ 'use strict' const Article = require('../modules/article') -const ifs = require('../modules/imagefs') -const Image = require('../modules/image') const categoriesTagGet = async(ctx, dbName) => { try { - const body = ctx.request.body - const id = body.id - console.log(id) - console.log(body) + const tag = ctx.params.tag const article = await new Article(dbName) - await article.reupload(id, body.title, body.summary, body.content, body.tag) - const {path, type} = ctx.request.files.image - const image = await new Image(dbName) - await ifs.deletePicture(`public/articleImages/${id}.png`) - await ifs.uploadPicture(path, type, `${id}`, 'public/articleImages/' ) - await image.replace(`public/articleImages/${id}.png`) - ctx.redirect(`/?msg=new "${body.title}" uploaded`) + const data = await article.getByTag(tag) + await ctx.render('homepage', {articles: data}) } catch(err) { - await ctx.render('error', {message: err.message}) + ctx.body = err.message } } diff --git a/views/accountpage.handlebars b/views/accountpage.handlebars index b4cae32..ec4f21c 100644 --- a/views/accountpage.handlebars +++ b/views/accountpage.handlebars @@ -11,7 +11,6 @@