Files
docx-js/src/export/packer/express.ts

30 lines
723 B
TypeScript
Raw Normal View History

2016-03-31 19:28:12 +01:00
import * as express from "express";
2017-09-30 18:15:33 +01:00
import { File } from "file";
2017-12-06 01:03:14 +00:00
import { Compiler } from "./compiler";
import { IPacker } from "./packer";
2017-03-08 21:54:52 +00:00
2017-12-06 01:03:14 +00:00
export class ExpressPacker implements IPacker {
2018-01-29 01:55:25 +00:00
private readonly packer: Compiler;
2016-03-31 19:28:12 +01:00
2018-01-29 01:55:25 +00:00
constructor(file: File, private readonly res: express.Response) {
2017-12-15 02:15:44 +00:00
this.packer = new Compiler(file);
2017-12-06 01:03:14 +00:00
2016-03-31 19:28:12 +01:00
this.res = res;
2016-05-26 15:08:34 +01:00
this.res.on("close", () => {
2018-01-23 01:33:12 +00:00
return res
.status(200)
.send("OK")
.end();
2016-03-31 19:28:12 +01:00
});
}
2017-12-06 01:32:57 +00:00
public async pack(name: string): Promise<void> {
2017-12-05 00:16:21 +00:00
name = name.replace(/.docx$/, "");
2017-03-12 21:34:49 +00:00
this.res.attachment(`${name}.docx`);
2017-12-06 01:32:57 +00:00
await this.packer.compile(this.res);
2016-03-31 19:28:12 +01:00
}
2017-03-08 21:54:52 +00:00
}