feature(rest) add markdown

This commit is contained in:
coderaiser 2014-03-12 08:05:20 -04:00
parent 351ceac00e
commit 68757ec6fd
3 changed files with 28 additions and 14 deletions

View file

@ -28,19 +28,21 @@ var CloudCmd, Util, DOM;
'#help li {' +
'list-style-type' + ': disc;' +
'}'
'}' +
'img {' +
'max-width: 100%' +
'}'
});
DOM.ajax({
url : '/HELP.md',
success : function (pData) {
var lData = {text: pData};
success : function (data) {
DOM.ajax({
method : 'post',
url : 'https://api.github.com/markdown',
data : Util.stringifyJSON(lData),
success : function(pResult){
method : 'put',
url : '/api/v1/markdown',
data : data,
success : function(pResult) {
var div = DOM.anyload({
name : 'div',
id : 'help',

View file

@ -24,6 +24,7 @@
onFSGet = main.srvrequire('rest/fs/get').onGet,
onFSPut = main.srvrequire('rest/fs/put').onPut,
onDelete = main.srvrequire('rest/fs/delete').onDelete,
markdown = main.srvrequire('rest/markdown/put'),
JSONDIR = main.JSONDIR,
OK = 200,
@ -33,6 +34,8 @@
name:'api.json'
}),
NOT_LOG = true,
fse = main.require('fs-extra') || {
copy : function(from, to, callback) {
pipe.create({
@ -91,13 +94,22 @@
* @param pParams {command, method, body, requrest, response}
*/
function sendData(pParams) {
var p, ret = main.checkParams(pParams);
var p, isFS, isMD,
ret = main.checkParams(pParams);
if (ret) {
p = pParams;
ret = Util.isContainStrAtBegin(p.name, CloudFunc.FS);
isFS = Util.isContainStrAtBegin(p.name, CloudFunc.FS),
isMD = Util.isContainStrAtBegin(p.name, '/markdown');
if (ret)
if (isFS)
onFS(pParams);
else if (isMD)
pipe.getBody(p.request, function(data) {
markdown.parse(data, function(data) {
sendResponse(p, data, NOT_LOG);
});
});
else {
if (p.name[0] === '/')
p.command = Util.removeStrOneTime(p.name, '/');
@ -131,8 +143,7 @@
switch (p.request.method) {
case 'GET':
onFSGet(query, p.name, function(error, data, isFile) {
var str,
NOT_LOG = true;
var str;
if (error)
sendError(params, error);

View file

@ -22,7 +22,8 @@
"socket.io": "0.9.16",
"express": "3.4.x",
"http-auth": "2.1.x",
"fs-extra": "0.8.x"
"fs-extra": "0.8.x",
"marked": "~0.3.2"
},
"license": "MIT",
"engines": {