2016-03-31 19:28:12 +01:00
|
|
|
import * as express from "express";
|
2017-09-30 18:15:33 +01:00
|
|
|
|
2017-03-08 21:54:52 +00:00
|
|
|
import { Document } from "../../docx/document";
|
2017-03-26 20:57:43 +01:00
|
|
|
import { Media } from "../../media";
|
2017-03-08 21:54:52 +00:00
|
|
|
import { Numbering } from "../../numbering";
|
|
|
|
import { Properties } from "../../properties";
|
2017-03-09 23:32:52 +00:00
|
|
|
import { Styles } from "../../styles";
|
2017-09-30 18:15:33 +01:00
|
|
|
import { IPackOptions } from "./pack-options";
|
2017-03-08 21:54:52 +00:00
|
|
|
import { Packer } from "./packer";
|
|
|
|
|
2016-03-31 19:28:12 +01:00
|
|
|
export class ExpressPacker extends Packer {
|
|
|
|
private res: express.Response;
|
|
|
|
|
2017-03-26 20:57:43 +01:00
|
|
|
constructor(document: Document, res: express.Response, styles?: Styles, properties?: Properties, numbering?: Numbering, media?: Media) {
|
|
|
|
super(document, styles, properties, numbering, media);
|
2016-03-31 19:28:12 +01:00
|
|
|
this.res = res;
|
|
|
|
|
2016-05-26 15:08:34 +01:00
|
|
|
this.res.on("close", () => {
|
|
|
|
return res.status(200).send("OK").end();
|
2016-03-31 19:28:12 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-30 18:15:33 +01:00
|
|
|
public pack(name: string, options: IPackOptions): void {
|
2017-03-12 21:34:49 +00:00
|
|
|
this.res.attachment(`${name}.docx`);
|
2017-05-09 18:03:31 +01:00
|
|
|
super.compile(this.res);
|
2016-03-31 19:28:12 +01:00
|
|
|
}
|
2017-03-08 21:54:52 +00:00
|
|
|
}
|