From 68757ec6fd0e2626b42ffd14d38c5b7e76fd2591 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 12 Mar 2014 08:05:20 -0400 Subject: [PATCH] feature(rest) add markdown --- lib/client/help.js | 18 ++++++++++-------- lib/server/rest.js | 21 ++++++++++++++++----- package.json | 3 ++- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/client/help.js b/lib/client/help.js index 90262abd..5f1b6eb6 100644 --- a/lib/client/help.js +++ b/lib/client/help.js @@ -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', diff --git a/lib/server/rest.js b/lib/server/rest.js index c9f20d52..a0af8729 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -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); diff --git a/package.json b/package.json index e711216f..67c474df 100644 --- a/package.json +++ b/package.json @@ -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": {