diff --git a/src/server.ts b/src/server.ts index b2249ec7..73d04f95 100644 --- a/src/server.ts +++ b/src/server.ts @@ -88,9 +88,7 @@ export class Server extends (EventEmitter as new () => TypedEmitter { + const type = ((): ConvertType => { const queryKeys = Object.keys(query) if (queryKeys.includes('pdf')) return ConvertType.pdf @@ -104,10 +102,14 @@ export class Server extends (EventEmitter as new () => TypedEmitter TypedEmitter { + const response = async (fn: string) => { try { - const ret = await this.convertMarkdown(fn, qs) + const { result, type } = await this.convertMarkdown(fn, qs) - if (!ret.newFile) + if (!result.newFile) throw new Error('Converter must return a converted file to serve.') - const { type } = this.converter.options - // Download pptx document as an attachment if (type === ConvertType.pptx) res.attachment(`${path.basename(fn, path.extname(fn))}.pptx`) - res.type(mimeTypes[type]).end(ret.newFile.buffer) + res.type(mimeTypes[type]).end(result.newFile.buffer) } catch (e: unknown) { let errorString = 'Internal server error'