DTP Social Engine
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.
 
 
 
 
 

55 lines
1.4 KiB

// site-controller.js
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';
const path = require('path');
const multer = require('multer');
const { SiteCommon } = require(path.join(__dirname, 'site-common'));
class SiteController extends SiteCommon {
constructor (dtp, component) {
super(dtp, component);
}
async loadChild (filename) {
let component = require(filename);
let child = await component.create(this.dtp);
return await child.start();
}
getPaginationParameters (req, maxPerPage) {
const pagination = {
p: parseInt(req.query.p || '1', 10),
cpp: parseInt(req.query.cpp || maxPerPage.toString(), 10),
};
if (pagination.p < 1) {
pagination.p = 1;
}
if (pagination.cpp > maxPerPage) {
pagination.cpp = maxPerPage;
}
pagination.skip = (pagination.p - 1) * pagination.cpp;
return pagination;
}
createMulter (slug) {
slug = slug || 'uploads';
return multer({ dest: `/tmp/${this.dtp.config.site.domainKey}/${slug}/${this.component.slug}` });
}
createDisplayList (name) {
const { displayEngine: displayEngineService } = this.dtp.services;
return displayEngineService.createDisplayList(name);
}
async createCsrfToken (req, name) {
const { csrfToken } = this.dtp.platform.services;
return csrfToken.create(req, { name });
}
}
module.exports.SiteController = SiteController;