Remove pdf packer

This commit is contained in:
Dolan
2018-08-14 21:56:38 +01:00
parent a38abeb4c2
commit bfa0edeb09
4 changed files with 0 additions and 96 deletions

View File

@ -51,13 +51,11 @@
"@types/express": "^4.0.35",
"@types/image-size": "0.0.29",
"@types/jszip": "^3.1.3",
"@types/request-promise": "^4.1.42",
"archiver": "^2.1.1",
"fast-xml-parser": "^3.3.6",
"image-size": "^0.6.2",
"jszip": "^3.1.5",
"request": "^2.83.0",
"request-promise": "^4.2.2",
"xml": "^1.0.1"
},
"author": "Dolan Miu",

View File

@ -1,2 +1 @@
export * from "./packer/packer";
export * from "./packer/pdf-packer";

View File

@ -1,48 +0,0 @@
/* tslint:disable:typedef space-before-function-paren */
import { assert, expect } from "chai";
import { stub } from "sinon";
import { File, Paragraph } from "../../file";
import { PdfPacker } from "./pdf-packer";
describe("PdfPacker", () => {
let packer: PdfPacker;
let file: File;
beforeEach(() => {
file = new File({
creator: "Dolan Miu",
revision: "1",
lastModifiedBy: "Dolan Miu",
});
const paragraph = new Paragraph("test text");
const heading = new Paragraph("Hello world").heading1();
file.addParagraph(new Paragraph("title").title());
file.addParagraph(heading);
file.addParagraph(new Paragraph("heading 2").heading2());
file.addParagraph(paragraph);
packer = new PdfPacker();
});
describe("#packPdf", () => {
it("should create a standard PDF file", async function() {
this.timeout(99999999);
// tslint:disable-next-line:no-any
const pdfConverterConvert = stub((packer as any).pdfConverter, "convert");
pdfConverterConvert.returns(new Buffer(""));
const buffer = await packer.toBuffer(file);
expect(buffer).is.an.instanceof(Buffer);
});
it("should handle exception if it throws any", () => {
// tslint:disable-next-line:no-any
const compiler = stub((packer as any).packer, "toBuffer");
compiler.throwsException();
return packer.toBuffer(file).catch((error) => {
assert.isDefined(error);
});
});
});
});

View File

@ -1,45 +0,0 @@
import * as request from "request-promise";
import { File } from "file";
import { Packer } from "./packer";
export class PdfPacker {
private readonly packer: Packer;
constructor() {
this.packer = new Packer();
}
public async toBuffer(file: File): Promise<Buffer> {
const buffer = await this.packer.toBuffer(file);
const text = await this.convert(buffer);
return text;
}
private convert(buffer: Buffer): request.RequestPromise {
return request.post({
url: "http://mirror1.convertonlinefree.com",
// tslint:disable-next-line:no-null-keyword
encoding: null,
headers: {
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36",
},
formData: {
__EVENTTARGET: "",
__EVENTARGUMENT: "",
__VIEWSTATE: "",
ctl00$MainContent$fu: {
value: buffer,
options: {
filename: "output.docx",
contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
},
},
ctl00$MainContent$btnConvert: "Convert",
ctl00$MainContent$fuZip: "",
},
});
}
}