1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-07 22:45:23 +02:00

Update code style

This commit is contained in:
gohabereg 2019-02-19 17:52:27 +03:00
parent ed3a784518
commit 2c5069c3d8
18 changed files with 59 additions and 60 deletions

View file

@ -20,7 +20,7 @@ require('./utils/twig');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(
path.join(__dirname, '../public'),

View file

@ -3,8 +3,8 @@ const fetch = require('node-fetch');
const fs = require('fs');
const Model = require('../models/file');
const {random16} = require('../utils/crypto');
const {deepMerge} = require('../utils/objects');
const { random16 } = require('../utils/crypto');
const { deepMerge } = require('../utils/objects');
/**
* @class Transport
@ -26,9 +26,9 @@ class Transport {
* @return {Promise<FileData>}
*/
static async save(multerData, map) {
const {originalname: name, filename, path, size, mimetype} = multerData;
const { originalname: name, filename, path, size, mimetype } = multerData;
const file = new Model({name, filename, path, size, mimetype});
const file = new Model({ name, filename, path, size, mimetype });
await file.save();
@ -84,7 +84,7 @@ class Transport {
*/
static composeResponse(file, map) {
const response = {};
const {data} = file;
const { data } = file;
Object.entries(map).forEach(([name, path]) => {
const fields = path.split(':');

View file

@ -1,6 +1,6 @@
import hljs from 'highlight.js/lib/highlight';
import javascript from 'highlight.js/lib/languages/javascript';
import style from 'highlight.js/styles/github-gist.css';
import style from 'highlight.js/styles/github-gist.css'; //eslint-disable-line no-unused-vars
/**
* @class CodeStyles
@ -11,7 +11,7 @@ export default class CodeStyler {
* @param {string} selector - CSS selector for code blocks
* @param {string[]} languages - list of languages to highlight, see hljs.listLanguages()
*/
constructor({selector, languages = [ 'javascript' ]}) {
constructor({ selector, languages = [ 'javascript' ] }) {
this.codeBlocksSelector = selector;
this.languages = languages;
this.langsAvailable = {

View file

@ -14,7 +14,7 @@ export default class Editor {
* Creates Editor instance
* @property {object} initialData - data to start with
*/
constructor({initialData}) {
constructor({ initialData }) {
this.editor = new CodeXEditor({
tools: {
header: {

View file

@ -27,7 +27,7 @@ export default class Writing {
* Init code highlighting
*/
async createCodeStyling() {
const {default: CodeStyler} = await import(/* webpackChunkName: "code-styling" */ './../classes/codeStyler');
const { default: CodeStyler } = await import(/* webpackChunkName: "code-styling" */ './../classes/codeStyler');
return new CodeStyler({
selector: '.block-code'

View file

@ -64,7 +64,7 @@ export default class Writing {
if (this.nodes.removeButton) {
this.nodes.removeButton.addEventListener('click', () => {
const isUserAgree = confirm('Are you sure?');
const isUserAgree = window.confirm('Are you sure?');
if (!isUserAgree) {
return;
@ -84,7 +84,7 @@ export default class Writing {
* @return {Promise<Editor>}
*/
async loadEditor() {
const {default: Editor} = await import(/* webpackChunkName: "editor" */ './../classes/editor');
const { default: Editor } = await import(/* webpackChunkName: "editor" */ './../classes/editor');
return new Editor({
initialData: this.page ? this.page.body : null

View file

@ -1,5 +1,5 @@
const {aliases: aliasesDb} = require('../utils/database/index');
const {binaryMD5} = require('../utils/crypto');
const { aliases: aliasesDb } = require('../utils/database/index');
const { binaryMD5 } = require('../utils/crypto');
/**
* @typedef {Object} AliasData
@ -40,10 +40,10 @@ class Alias {
*/
static async get(aliasName) {
const hash = binaryMD5(aliasName);
let data = await aliasesDb.findOne({hash: hash, deprecated: false});
let data = await aliasesDb.findOne({ hash: hash, deprecated: false });
if (!data) {
data = await aliasesDb.findOne({hash: hash});
data = await aliasesDb.findOne({ hash: hash });
}
return new Alias(data);
@ -79,7 +79,7 @@ class Alias {
this._id = insertedRow._id;
} else {
await aliasesDb.update({_id: this._id}, this.data);
await aliasesDb.update({ _id: this._id }, this.data);
}
return this;
@ -91,7 +91,7 @@ class Alias {
* @param {AliasData} aliasData
*/
set data(aliasData) {
const {id, type, hash, deprecated} = aliasData;
const { id, type, hash, deprecated } = aliasData;
this.id = id || this.id;
this.type = type || this.type;
@ -131,7 +131,7 @@ class Alias {
* @returns {Promise<Alias>}
*/
async destroy() {
await aliasesDb.remove({_id: this._id});
await aliasesDb.remove({ _id: this._id });
delete this._id;

View file

@ -1,4 +1,4 @@
const {files: filesDb} = require('../utils/database/index');
const { files: filesDb } = require('../utils/database/index');
/**
* @typedef {Object} FileData
@ -29,7 +29,7 @@ class File {
* @returns {Promise<File>}
*/
static async get(_id) {
const data = await filesDb.findOne({_id});
const data = await filesDb.findOne({ _id });
return new File(data);
}
@ -40,7 +40,7 @@ class File {
* @returns {Promise<File>}
*/
static async getByFilename(filename) {
const data = await filesDb.findOne({filename});
const data = await filesDb.findOne({ filename });
return new File(data);
}
@ -80,7 +80,7 @@ class File {
* @param {FileData} fileData
*/
set data(fileData) {
const {name, filename, path, mimetype, size} = fileData;
const { name, filename, path, mimetype, size } = fileData;
this.name = name || this.name;
this.filename = filename || this.filename;
@ -116,7 +116,7 @@ class File {
this._id = insertedRow._id;
} else {
await filesDb.update({_id: this._id}, this.data);
await filesDb.update({ _id: this._id }, this.data);
}
return this;
@ -128,7 +128,7 @@ class File {
* @returns {Promise<File>}
*/
async destroy() {
await filesDb.remove({_id: this._id});
await filesDb.remove({ _id: this._id });
delete this._id;

View file

@ -1,4 +1,4 @@
const {pages: pagesDb} = require('../utils/database/index');
const { pages: pagesDb } = require('../utils/database/index');
const translateString = require('../utils/translation');
/**
@ -27,7 +27,7 @@ class Page {
* @returns {Promise<Page>}
*/
static async get(_id) {
const data = await pagesDb.findOne({_id});
const data = await pagesDb.findOne({ _id });
return new Page(data);
}
@ -38,7 +38,7 @@ class Page {
* @returns {Promise<Page>}
*/
static async getByUri(uri) {
const data = await pagesDb.findOne({uri});
const data = await pagesDb.findOne({ uri });
return new Page(data);
}
@ -78,7 +78,7 @@ class Page {
* @param {PageData} pageData
*/
set data(pageData) {
const {body, parent, uri} = pageData;
const { body, parent, uri } = pageData;
this.body = body || this.body;
this.title = this.extractTitleFromBody();
@ -141,7 +141,7 @@ class Page {
* @returns {Promise<Page>}
*/
get parent() {
return pagesDb.findOne({_id: this._parent})
return pagesDb.findOne({ _id: this._parent })
.then(data => new Page(data));
}
@ -151,7 +151,7 @@ class Page {
* @returns {Promise<Page[]>}
*/
get children() {
return pagesDb.find({parent: this._id})
return pagesDb.find({ parent: this._id })
.then(data => data.map(page => new Page(page)));
}
@ -168,7 +168,7 @@ class Page {
this._id = insertedRow._id;
} else {
await pagesDb.update({_id: this._id}, this.data);
await pagesDb.update({ _id: this._id }, this.data);
}
return this;
@ -180,7 +180,7 @@ class Page {
* @returns {Promise<Page>}
*/
async destroy() {
await pagesDb.remove({_id: this._id});
await pagesDb.remove({ _id: this._id });
delete this._id;

View file

@ -1,4 +1,4 @@
const {pagesOrder: db} = require('../utils/database/index');
const { pagesOrder: db } = require('../utils/database/index');
/**
* @typedef {Object} PageOrderData
@ -21,7 +21,7 @@ class PageOrder {
* @returns {PageOrder}
*/
static async get(pageId) {
const order = await db.findOne({page: pageId});
const order = await db.findOne({ page: pageId });
let data = {};
@ -172,7 +172,7 @@ class PageOrder {
this._id = insertedRow._id;
} else {
await db.update({_id: this._id}, this.data);
await db.update({ _id: this._id }, this.data);
}
return this;
@ -182,7 +182,7 @@ class PageOrder {
* Remove page data from the database
*/
async destroy() {
await db.remove({_id: this._id});
await db.remove({ _id: this._id });
delete this._id;

View file

@ -3,13 +3,12 @@ const router = express.Router();
const multer = require('multer')();
const Pages = require('../../controllers/pages');
const PagesOrder = require('../../controllers/pagesOrder');
const Aliases = require('../../controllers/aliases');
/**
* GET /page/:id
*
* Return PageData of page with given id
*/
router.get('/page/:id', async (req, res) => {
try {
const page = await Pages.get(req.params.id);
@ -54,8 +53,8 @@ router.get('/pages', async (req, res) => {
*/
router.put('/page', multer.none(), async (req, res) => {
try {
const {title, body, parent} = req.body;
const page = await Pages.insert({title, body, parent});
const { title, body, parent } = req.body;
const page = await Pages.insert({ title, body, parent });
/** push to the orders array */
await PagesOrder.push(parent, page._id);
@ -78,10 +77,10 @@ router.put('/page', multer.none(), async (req, res) => {
* Update page data in the database
*/
router.post('/page/:id', multer.none(), async (req, res) => {
const {id} = req.params;
const { id } = req.params;
try {
const {title, body, parent, putAbovePageId, uri} = req.body;
const { title, body, parent, putAbovePageId, uri } = req.body;
let page = await Pages.get(id);
if (page._parent !== parent) {
@ -92,7 +91,7 @@ router.post('/page/:id', multer.none(), async (req, res) => {
}
}
page = await Pages.update(id, {title, body, parent, uri});
page = await Pages.update(id, { title, body, parent, uri });
res.json({
success: true,
result: page
@ -134,7 +133,7 @@ router.delete('/page/:id', async (req, res) => {
* @param startFrom
* @returns {Promise<void>}
*/
async function deleteRecursively(startFrom) {
const deleteRecursively = async (startFrom) => {
let order = [];
try {
@ -151,7 +150,7 @@ router.delete('/page/:id', async (req, res) => {
try {
await PagesOrder.remove(startFrom);
} catch (e) {}
}
};
await deleteRecursively(req.params.id);

View file

@ -16,20 +16,20 @@ const imageUploader = multer({
cb(null, true);
}
}).fields([ {name: 'image', maxCount: 1} ]);
}).fields([ { name: 'image', maxCount: 1 } ]);
/**
* Multer middleware for file uploading
*/
const fileUploader = multer({
dest: 'public/uploads/'
}).fields([ {name: 'file', maxCount: 1} ]);
}).fields([ { name: 'file', maxCount: 1 } ]);
/**
* Accepts images to upload
*/
router.post('/transport/image', imageUploader, async (req, res) => {
let response = {success: 0};
let response = { success: 0 };
if (!req.files || !req.files.image) {
res.status(400).json(response);
@ -53,7 +53,7 @@ router.post('/transport/image', imageUploader, async (req, res) => {
* Accepts files to upload
*/
router.post('/transport/file', fileUploader, async (req, res) => {
let response = {success: 0};
let response = { success: 0 };
if (!req.files || !req.files.file) {
res.status(400).json(response);
@ -77,7 +77,7 @@ router.post('/transport/file', fileUploader, async (req, res) => {
* Accept file url to fetch
*/
router.post('/transport/fetch', multer().none(), async (req, res) => {
let response = {success: 0};
let response = { success: 0 };
if (!req.body.url) {
res.status(400).json(response);

View file

@ -11,7 +11,7 @@ const asyncMiddleware = require('../../utils/asyncMiddleware');
* @return {Page[]}
*/
async function createMenuTree(pages, level = 1, currentLevel = 1) {
return await Promise.all(pages.map(async pageId => {
return Promise.all(pages.map(async pageId => {
const parent = await Pages.get(pageId);
/**
@ -51,7 +51,7 @@ async function createMenuTree(pages, level = 1, currentLevel = 1) {
* @param res
* @param next
*/
module.exports = asyncMiddleware(async function (req, res, next) {
module.exports = asyncMiddleware(async (req, res, next) => {
/**
* Pages without parent
* @type {string}

View file

@ -1,6 +1,6 @@
const Datastore = require('nedb');
const config = require('../../../config');
const db = new Datastore({filename: `./${config.database}/aliases.db`, autoload: true});
const db = new Datastore({ filename: `./${config.database}/aliases.db`, autoload: true });
module.exports = db;

View file

@ -1,6 +1,6 @@
const Datastore = require('nedb');
const config = require('../../../config');
const db = new Datastore({filename: `./${config.database}/files.db`, autoload: true});
const db = new Datastore({ filename: `./${config.database}/files.db`, autoload: true });
module.exports = db;

View file

@ -1,6 +1,6 @@
const Datastore = require('nedb');
const config = require('../../../config');
const db = new Datastore({filename: `./${config.database}/pages.db`, autoload: true});
const db = new Datastore({ filename: `./${config.database}/pages.db`, autoload: true });
module.exports = db;

View file

@ -1,7 +1,7 @@
const Datastore = require('nedb');
const config = require('../../../config');
const db = new Datastore({filename: `./${config.database}/pagesOrder.db`, autoload: true});
const db = new Datastore({ filename: `./${config.database}/pagesOrder.db`, autoload: true });
/**
* Current DataStore preparation
@ -18,7 +18,7 @@ const db = new Datastore({filename: `./${config.database}/pagesOrder.db`, autolo
};
const order = await new Promise((resolve, reject) => {
db.findOne({page: parentIdOfRootPages}, cbk(resolve, reject));
db.findOne({ page: parentIdOfRootPages }, cbk(resolve, reject));
});
if (!order) {

View file

@ -40,7 +40,7 @@ module.exports = class RCParser {
return RCParser.DEFAULTS;
}
const file = fs.readFileSync(rcPath, {encoding: 'UTF-8'});
const file = fs.readFileSync(rcPath, { encoding: 'UTF-8' });
const rConfig = {};
let userConfig;
@ -70,7 +70,7 @@ module.exports = class RCParser {
return false;
}
const {title, uri} = option;
const { title, uri } = option;
if (!title || typeof title !== 'string') {
console.log(`Menu option #${i} title must be a string.`);