Files
docx-js/src/export/packer/express.ts
2017-12-30 20:25:16 +00:00

28 lines
681 B
TypeScript

import * as express from "express";
import { File } from "file";
import { Compiler } from "./compiler";
import { IPacker } from "./packer";
export class ExpressPacker implements IPacker {
private res: express.Response;
private packer: Compiler;
constructor(file: File, res: express.Response) {
this.packer = new Compiler(file);
this.res = res;
this.res.on("close", () => {
return res.status(200).send("OK").end();
});
}
public async pack(name: string): Promise<void> {
name = name.replace(/.docx$/, "");
this.res.attachment(`${name}.docx`);
await this.packer.compile(this.res);
}
}