mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(cloudcmd) add abilit to parse markdown inside zip archives
This commit is contained in:
parent
6182f621d6
commit
f261a0ea08
4 changed files with 46 additions and 9 deletions
|
|
@ -121,7 +121,7 @@
|
|||
"ponse": "^5.0.0",
|
||||
"pullout": "^4.0.0",
|
||||
"putout": "^13.0.0",
|
||||
"redzip": "^1.0.2",
|
||||
"redzip": "^1.3.0",
|
||||
"rendy": "^3.0.0",
|
||||
"restafary": "^9.1.0",
|
||||
"restbox": "^2.0.0",
|
||||
|
|
|
|||
BIN
server/markdown/fixture/markdown.zip
Normal file
BIN
server/markdown/fixture/markdown.zip
Normal file
Binary file not shown.
|
|
@ -1,12 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
const {readFile} = require('fs/promises');
|
||||
const {join} = require('path');
|
||||
const {callbackify} = require('util');
|
||||
|
||||
const pullout = require('pullout');
|
||||
const ponse = require('ponse');
|
||||
const threadIt = require('thread-it');
|
||||
const {read} = require('redzip');
|
||||
|
||||
const parse = threadIt(join(__dirname, 'worker'));
|
||||
|
||||
|
|
@ -45,7 +45,8 @@ function parseName(query, name, rootDir) {
|
|||
async function onGET(request, name, root) {
|
||||
const query = ponse.getQuery(request);
|
||||
const fileName = parseName(query, name, root);
|
||||
const data = await readFile(fileName, 'utf8');
|
||||
const stream = await read(fileName);
|
||||
const data = await pullout(stream);
|
||||
|
||||
return parse(data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const test = require('supertape');
|
||||
const {join} = require('path');
|
||||
const {promisify} = require('util');
|
||||
|
||||
const tryToCatch = require('try-to-catch');
|
||||
const serveOnce = require('serve-once');
|
||||
const test = require('supertape');
|
||||
|
||||
const markdown = require('.');
|
||||
|
||||
const _markdown = promisify(markdown);
|
||||
const fixtureDir = path.join(__dirname, 'fixture');
|
||||
const fixtureDir = join(__dirname, 'fixture');
|
||||
const cloudcmd = require('../..');
|
||||
const config = {
|
||||
auth: false,
|
||||
|
|
@ -45,8 +46,8 @@ test('cloudcmd: markdown: relative', async (t) => {
|
|||
});
|
||||
|
||||
test('cloudcmd: markdown: put', async (t) => {
|
||||
const md = path.join(fixtureDir, 'markdown.md');
|
||||
const html = path.join(fixtureDir, 'markdown.html');
|
||||
const md = join(fixtureDir, 'markdown.md');
|
||||
const html = join(fixtureDir, 'markdown.html');
|
||||
|
||||
const mdStream = fs.createReadStream(md);
|
||||
const htmlFile = fs.readFileSync(html, 'utf8');
|
||||
|
|
@ -60,7 +61,7 @@ test('cloudcmd: markdown: put', async (t) => {
|
|||
});
|
||||
|
||||
test('cloudcmd: markdown: put: error', async (t) => {
|
||||
const md = path.join(fixtureDir, 'markdown-not-exist.md');
|
||||
const md = join(fixtureDir, 'markdown-not-exist.md');
|
||||
|
||||
const name = 'hello';
|
||||
const mdStream = fs.createReadStream(md);
|
||||
|
|
@ -88,3 +89,38 @@ test('cloudcmd: markdown: no request', async (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: markdown: zip', async (t) => {
|
||||
const configManager = cloudcmd.createConfigManager();
|
||||
const fixtureDir = join(__dirname, 'fixture');
|
||||
const config = {
|
||||
auth: false,
|
||||
root: fixtureDir,
|
||||
};
|
||||
|
||||
const {request} = serveOnce(cloudcmd, {
|
||||
config,
|
||||
configManager,
|
||||
});
|
||||
const {body} = await request.get('/api/v1/markdown/markdown.md');
|
||||
|
||||
t.equal(body, '<h1>hello</h1>\n');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: markdown: zip', async (t) => {
|
||||
const configManager = cloudcmd.createConfigManager();
|
||||
const fixtureDir = join(__dirname, 'fixture');
|
||||
const config = {
|
||||
auth: false,
|
||||
root: fixtureDir,
|
||||
};
|
||||
|
||||
const {request} = serveOnce(cloudcmd, {
|
||||
config,
|
||||
configManager,
|
||||
});
|
||||
const {body} = await request.get('/api/v1/markdown/markdown.zip/markdown.md');
|
||||
|
||||
t.equal(body, '<h1>hello</h1>\n');
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue