mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 10:38:26 +00:00
chore(makrdown) es2015-ify
This commit is contained in:
parent
2c6a2f232d
commit
7bc51655b9
1 changed files with 33 additions and 36 deletions
|
|
@ -1,68 +1,65 @@
|
|||
'use strict';
|
||||
|
||||
var DIR = './',
|
||||
DIR_ROOT = __dirname + '/../../',
|
||||
|
||||
fs = require('fs'),
|
||||
|
||||
root = require(DIR + 'root'),
|
||||
pullout = require('pullout/legacy'),
|
||||
ponse = require('ponse'),
|
||||
markdown = require('markdown-it')();
|
||||
const DIR_ROOT = __dirname + '/../../';
|
||||
const fs = require('fs');
|
||||
|
||||
function check(name, request, callback) {
|
||||
if (typeof name !== 'string')
|
||||
throw Error('name should be string!');
|
||||
|
||||
else if (!request)
|
||||
throw Error('request could not be empty!');
|
||||
|
||||
else if (typeof callback !== 'function')
|
||||
throw Error('callback should be function!');
|
||||
}
|
||||
const pullout = require('pullout/legacy');
|
||||
const ponse = require('ponse');
|
||||
const markdown = require('markdown-it')();
|
||||
|
||||
module.exports = function(name, request, callback) {
|
||||
var query,
|
||||
method = request.method;
|
||||
const root = require('./root');
|
||||
|
||||
module.exports = (name, request, callback) => {
|
||||
const method = request.method;
|
||||
const query = ponse.getQuery(request);
|
||||
|
||||
check(name, request, callback);
|
||||
|
||||
switch(method) {
|
||||
case 'GET':
|
||||
name = name.replace('/markdown', '');
|
||||
query = ponse.getQuery(request);
|
||||
name = name.replace('/markdown', '');
|
||||
|
||||
if (query === 'relative')
|
||||
name = DIR_ROOT + name;
|
||||
else
|
||||
name = root(name);
|
||||
|
||||
fs.readFile(name, 'utf8', function(error, data) {
|
||||
fs.readFile(name, 'utf8', (error, data) => {
|
||||
if (error)
|
||||
callback(error);
|
||||
else
|
||||
parse(data, callback);
|
||||
return callback(error);
|
||||
|
||||
parse(data, callback);
|
||||
});
|
||||
break;
|
||||
|
||||
case 'PUT':
|
||||
pullout(request, 'string', function(error, data) {
|
||||
pullout(request, 'string', (error, data) => {
|
||||
if (error)
|
||||
callback(error);
|
||||
else
|
||||
parse(data, callback);
|
||||
return callback(error);
|
||||
|
||||
parse(data, callback);
|
||||
});
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
function parse(data, callback) {
|
||||
var md;
|
||||
|
||||
process.nextTick(function() {
|
||||
md = markdown.render(data);
|
||||
process.nextTick(() => {
|
||||
const md = markdown.render(data);
|
||||
|
||||
callback(null, md);
|
||||
});
|
||||
}
|
||||
|
||||
function check(name, request, callback) {
|
||||
if (typeof name !== 'string')
|
||||
throw Error('name should be string!');
|
||||
|
||||
if (!request)
|
||||
throw Error('request could not be empty!');
|
||||
|
||||
if (typeof callback !== 'function')
|
||||
throw Error('callback should be function!');
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue