|
|
@ -5,7 +5,9 @@ |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
const DTP_COMPONENT_NAME = 'admin:post'; |
|
|
|
|
|
|
|
const express = require('express'); |
|
|
|
const multer = require('multer'); |
|
|
|
|
|
|
|
const { SiteController, SiteError } = require('../../../lib/site-lib'); |
|
|
|
|
|
|
@ -16,6 +18,8 @@ class PostController extends SiteController { |
|
|
|
} |
|
|
|
|
|
|
|
async start ( ) { |
|
|
|
const upload = multer({ dest: `/tmp/${this.dtp.config.site.domainKey}/uploads/${DTP_COMPONENT_NAME}` }); |
|
|
|
|
|
|
|
const router = express.Router(); |
|
|
|
router.use(async (req, res, next) => { |
|
|
|
res.locals.currentView = 'admin'; |
|
|
@ -25,6 +29,7 @@ class PostController extends SiteController { |
|
|
|
|
|
|
|
router.param('postId', this.populatePostId.bind(this)); |
|
|
|
|
|
|
|
router.post('/:postId/image', upload.single('imageFile'), this.postUpdateImage.bind(this)); |
|
|
|
router.post('/:postId', this.postUpdatePost.bind(this)); |
|
|
|
router.post('/', this.postCreatePost.bind(this)); |
|
|
|
|
|
|
@ -52,6 +57,29 @@ class PostController extends SiteController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async postUpdateImage (req, res, next) { |
|
|
|
const { post: postService } = this.dtp.services; |
|
|
|
try { |
|
|
|
const displayList = this.createDisplayList('post-image'); |
|
|
|
|
|
|
|
await postService.updateImage(req.user, res.locals.post, req.file); |
|
|
|
|
|
|
|
displayList.showNotification( |
|
|
|
'Profile photo updated successfully.', |
|
|
|
'success', |
|
|
|
'bottom-center', |
|
|
|
2000, |
|
|
|
); |
|
|
|
res.status(200).json({ success: true, displayList }); |
|
|
|
} catch (error) { |
|
|
|
this.log.error('failed to update feature image', { error }); |
|
|
|
return res.status(error.statusCode || 500).json({ |
|
|
|
success: false, |
|
|
|
message: error.message, |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async postUpdatePost (req, res, next) { |
|
|
|
const { post: postService } = this.dtp.services; |
|
|
|
try { |
|
|
|