mirror of https://gitgud.io/fatchan/jschan.git
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.
80 lines
2.0 KiB
80 lines
2.0 KiB
'use strict';
|
|
|
|
const { Boards, Accounts } = require(__dirname+'/../../db/')
|
|
, { Binary } = require(__dirname+'/../../db/db.js')
|
|
, dynamicResponse = require(__dirname+'/../../helpers/dynamic.js')
|
|
, { roles } = require(__dirname+'/../../helpers/roles.js')
|
|
, uploadDirectory = require(__dirname+'/../../helpers/files/uploadDirectory.js')
|
|
, restrictedURIs = new Set(['captcha', 'forms', 'randombanner', 'all'])
|
|
, { ensureDir } = require('fs-extra')
|
|
, config = require(__dirname+'/../../config.js');
|
|
|
|
module.exports = async (req, res, next) => {
|
|
|
|
const { boardDefaults } = config.get;
|
|
|
|
const { name, description } = req.body
|
|
, uri = req.body.uri.toLowerCase()
|
|
, tags = req.body.tags.split(/\r?\n/).filter(n => n)
|
|
, owner = req.session.user;
|
|
|
|
if (restrictedURIs.has(uri)) {
|
|
return dynamicResponse(req, res, 400, 'message', {
|
|
'title': 'Bad Request',
|
|
'message': 'That URI is not available for board creation',
|
|
'redirect': '/create.html'
|
|
});
|
|
}
|
|
|
|
const board = await Boards.findOne(uri);
|
|
|
|
// if board exists reject
|
|
if (board != null) {
|
|
return dynamicResponse(req, res, 409, 'message', {
|
|
'title': 'Conflict',
|
|
'message': 'Board with this URI already exists',
|
|
'redirect': '/create.html'
|
|
});
|
|
}
|
|
|
|
|
|
//todo: add a settings for defaults
|
|
const newBoard = {
|
|
'_id': uri,
|
|
owner,
|
|
tags,
|
|
'banners': [],
|
|
'sequence_value': 1,
|
|
'pph': 0,
|
|
'ppd': 0,
|
|
'ips': 0,
|
|
'lastPostTimestamp': null,
|
|
'webring': false,
|
|
'staff': {
|
|
[owner]: {
|
|
'permissions': Binary(roles.BOARD_OWNER.array),
|
|
'addedDate': new Date(),
|
|
},
|
|
},
|
|
'flags': {},
|
|
'assets': [],
|
|
'settings': {
|
|
name,
|
|
description,
|
|
...boardDefaults
|
|
}
|
|
}
|
|
|
|
await Promise.all([
|
|
Boards.insertOne(newBoard),
|
|
Accounts.addOwnedBoard(owner, uri),
|
|
ensureDir(`${uploadDirectory}/html/${uri}`),
|
|
ensureDir(`${uploadDirectory}/json/${uri}`),
|
|
ensureDir(`${uploadDirectory}/banner/${uri}`),
|
|
ensureDir(`${uploadDirectory}/flag/${uri}`),
|
|
ensureDir(`${uploadDirectory}/asset/${uri}`),
|
|
]);
|
|
|
|
return res.redirect(`/${uri}/index.html`);
|
|
|
|
}
|
|
|