diff --git a/package.json b/package.json index 4fe76ee5f5..eab1220339 100644 --- a/package.json +++ b/package.json @@ -43,11 +43,8 @@ "@types/archiver": "^2.1.0", "@types/express": "^4.0.35", "@types/image-size": "0.0.29", - "@types/request-promise": "^4.1.41", "archiver": "^2.1.1", "image-size": "^0.6.2", - "request": "^2.83.0", - "request-promise": "^4.2.2", "xml": "^1.0.1" }, "author": "Igor Bulovski", diff --git a/src/export/packer/local.spec.ts b/src/export/packer/local.spec.ts index 16fb99705b..e678c2939f 100644 --- a/src/export/packer/local.spec.ts +++ b/src/export/packer/local.spec.ts @@ -30,13 +30,4 @@ describe("LocalPacker", () => { fs.statSync("build/tests/test.docx"); }); }); - - describe("#packPdf", () => { - it("should create a standard PDF file", async function() { - this.timeout(99999999); - - await packer.packPdf("build/tests/pdf-test"); - fs.statSync("build/tests/pdf-test.pdf"); - }); - }); }); diff --git a/src/export/packer/local.ts b/src/export/packer/local.ts index 5d0c05fe81..b8c88b1b65 100644 --- a/src/export/packer/local.ts +++ b/src/export/packer/local.ts @@ -1,19 +1,14 @@ import * as fs from "fs"; -import * as os from "os"; -import * as path from "path"; import { File } from "../../file"; import { Compiler } from "./compiler"; import { IPacker } from "./packer"; -import { PdfConvertWrapper } from "./pdf-convert-wrapper"; export class LocalPacker implements IPacker { private stream: fs.WriteStream; - private readonly pdfConverter: PdfConvertWrapper; private readonly packer: Compiler; constructor(file: File) { - this.pdfConverter = new PdfConvertWrapper(); this.packer = new Compiler(file); } @@ -23,25 +18,4 @@ export class LocalPacker implements IPacker { this.stream = fs.createWriteStream(`${filePath}.docx`); await this.packer.compile(this.stream); } - - public async packPdf(filePath: string): Promise { - filePath = filePath.replace(/.pdf$/, ""); - - const fileName = path.basename(filePath, path.extname(filePath)); - const tempPath = path.join(os.tmpdir(), `${fileName}.docx`); - this.stream = fs.createWriteStream(tempPath); - await this.packer.compile(this.stream); - const text = await this.pdfConverter.convert(tempPath); - // const writeFile = util.promisify(fs.writeFile); --use this in future, in 3 years time. Only in node 8 - // return writeFile(`${filePath}.pdf`, text); - return new Promise((resolve, reject) => { - fs.writeFile(`${filePath}.pdf`, text, (err) => { - if (err) { - reject(err); - return; - } - resolve(); - }); - }); - } } diff --git a/src/export/packer/pdf-convert-wrapper.ts b/src/export/packer/pdf-convert-wrapper.ts deleted file mode 100644 index 5067082d12..0000000000 --- a/src/export/packer/pdf-convert-wrapper.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* tslint:disable:object-literal-key-quotes */ -// This tslint disable is needed, or it simply won't work -import * as fs from "fs"; -import * as request from "request-promise"; - -export interface IConvertOutput { - data: string; -} - -export class PdfConvertWrapper { - public convert(filePath: string): request.RequestPromise { - return request.post({ - url: "http://mirror1.convertonlinefree.com", - 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: fs.readFileSync(filePath), - options: { - filename: "output.docx", - contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - }, - }, - ctl00$MainContent$btnConvert: "Convert", - ctl00$MainContent$fuZip: "", - }, - }); - } -}