You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.7 KiB
66 lines
1.7 KiB
// post.js
|
|
// Copyright (C) 2021 Digital Telepresence, LLC
|
|
// License: Apache-2.0
|
|
|
|
'use strict';
|
|
|
|
const express = require('express');
|
|
// const multer = require('multer');
|
|
|
|
const { SiteController, SiteError } = require('../../lib/site-lib');
|
|
|
|
class AuthorController extends SiteController {
|
|
|
|
constructor (dtp) {
|
|
super(dtp, module.exports);
|
|
}
|
|
|
|
async start ( ) {
|
|
const { dtp } = this;
|
|
const {
|
|
limiter: limiterService,
|
|
} = dtp.services;
|
|
|
|
// const upload = multer({ dest: `/tmp/dtp-sites/${this.dtp.config.site.domainKey}`});
|
|
|
|
const router = express.Router();
|
|
dtp.app.use('/author', router);
|
|
|
|
router.use(
|
|
async (req, res, next) => {
|
|
res.locals.currentView = 'author';
|
|
if (!req.user || !req.user.permissions.canAuthorPages) {
|
|
return next(new SiteError(403, 'Author privileges are required'));
|
|
}
|
|
return next();
|
|
},
|
|
);
|
|
|
|
router.get('/',
|
|
limiterService.createMiddleware(limiterService.config.post.getIndex),
|
|
this.getAuthorHome.bind(this),
|
|
);
|
|
}
|
|
|
|
async getAuthorHome (req, res, next) {
|
|
const { /*comment: commentService,*/ post: postService } = this.dtp.services;
|
|
try {
|
|
res.locals.drafts = await postService.getForAuthor(req.user, 'draft');
|
|
res.locals.posts = await postService.getForAuthor(req.user, 'published', 5);
|
|
res.locals.comments = await postService.getCommentsForAuthor(req.user);
|
|
res.render('author/index');
|
|
} catch (error) {
|
|
this.log.error('failed to render Author dashboard', { error });
|
|
return next(error);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
slug: 'author',
|
|
name: 'author',
|
|
create: async (dtp) => {
|
|
let controller = new AuthorController(dtp);
|
|
return controller;
|
|
},
|
|
}; |