2016-03-31 19:28:12 +01:00
|
|
|
import {Packer} from "./packer";
|
|
|
|
import * as fs from "fs";
|
|
|
|
import * as express from "express";
|
2016-03-31 23:36:42 +01:00
|
|
|
import {Document} from "../../docx/document";
|
2016-05-18 17:09:50 +01:00
|
|
|
import {Properties} from "../../properties";
|
|
|
|
import {DefaultStylesFactory} from "../../styles/factory"
|
2016-05-23 22:23:05 +01:00
|
|
|
import {Numbering} from "../../numbering";
|
2016-03-31 19:28:12 +01:00
|
|
|
|
|
|
|
export class ExpressPacker extends Packer {
|
|
|
|
private res: express.Response;
|
|
|
|
|
2016-05-23 22:23:05 +01:00
|
|
|
constructor(document: Document, res: express.Response, styles?: any, properties?: Properties, numbering?: Numbering) {
|
2016-05-18 17:09:50 +01:00
|
|
|
if (!styles) {
|
|
|
|
var stylesFactory = new DefaultStylesFactory();
|
|
|
|
styles = stylesFactory.newInstance()
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!properties) {
|
|
|
|
properties = new Properties({
|
|
|
|
creator: "Shan Fu",
|
|
|
|
revision: "1",
|
|
|
|
lastModifiedBy: "Shan Fu"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-23 22:23:05 +01:00
|
|
|
if (!numbering) {
|
|
|
|
numbering = new Numbering();
|
|
|
|
}
|
|
|
|
|
|
|
|
super(document, styles, properties, numbering);
|
2016-03-31 19:28:12 +01:00
|
|
|
this.res = res;
|
|
|
|
|
|
|
|
this.res.on('close', () => {
|
|
|
|
return res.status(200).send('OK').end();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-18 17:09:50 +01:00
|
|
|
pack(name: string): void {
|
2016-03-31 19:28:12 +01:00
|
|
|
this.res.attachment(name + ".docx");
|
|
|
|
super.pack(this.res);
|
|
|
|
}
|
|
|
|
}
|