-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathraw.ts
36 lines (36 loc) · 996 Bytes
/
raw.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Request, Response } from 'express';
import { BundleResponseData } from '@docs.page/server';
import { Bundle, BundleError } from '../utils/bundle.js';
/**
* Gets the API information.
*
* @param {Request} req
* @param {Response} res
*/
export const bundleRaw = async (
req: Request,
res: Response,
): Promise<Response<BundleResponseData>> => {
const path = (req?.query.path as string) || 'index';
const headerDepth = req?.query?.headerDepth ? parseInt(req?.query?.headerDepth as string) : 3;
const { md: markdown, config: sourceConfig } = req.body;
const bundleInstance = new Bundle({
owner: 'n/a',
repository: 'n/a',
path,
headerDepth,
markdown,
});
if (sourceConfig) {
bundleInstance.formatConfigLocales(sourceConfig);
}
try {
const data = await bundleInstance.build();
return res.status(200).send(data);
} catch (e) {
if (e instanceof BundleError) {
return res.status(e.statusCode).send(e);
}
throw e;
}
};