refactor: apply eslint
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
|
||||
import { Response } from 'express';
|
||||
import { PdfFile } from '@stirling-pdf/shared-operations/src/wrappers/PdfFile'
|
||||
import Archiver from 'archiver';
|
||||
import { Response } from "express";
|
||||
import { PdfFile } from "@stirling-pdf/shared-operations/src/wrappers/PdfFile";
|
||||
import Archiver from "archiver";
|
||||
|
||||
export async function respondWithFile(res: Response, uint8Array: Uint8Array, filename: string, mimeType: string): Promise<void> {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': mimeType,
|
||||
'Content-disposition': `attachment; filename="${filename}"`,
|
||||
'Content-Length': uint8Array.length
|
||||
"Content-Type": mimeType,
|
||||
"Content-disposition": `attachment; filename="${filename}"`,
|
||||
"Content-Length": uint8Array.length
|
||||
});
|
||||
res.end(uint8Array);
|
||||
}
|
||||
@@ -23,14 +23,14 @@ export async function respondWithZip(res: Response, filename: string, files: {ui
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(filename)
|
||||
console.log(filename);
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/zip',
|
||||
'Content-disposition': `attachment; filename="${filename}.zip"`,
|
||||
"Content-Type": "application/zip",
|
||||
"Content-disposition": `attachment; filename="${filename}.zip"`,
|
||||
});
|
||||
|
||||
// TODO: Also allow changing the compression level
|
||||
var zip = Archiver('zip');
|
||||
const zip = Archiver("zip");
|
||||
|
||||
// Stream the file to the user.
|
||||
zip.pipe(res);
|
||||
@@ -50,10 +50,10 @@ export async function respondWithPdfFiles(res: Response, pdfFiles: PdfFile[] | u
|
||||
res.status(500).json({"warning": "The workflow had no outputs."});
|
||||
}
|
||||
else if (pdfFiles.length == 1) {
|
||||
respondWithPdfFile(res, pdfFiles[0])
|
||||
respondWithPdfFile(res, pdfFiles[0]);
|
||||
}
|
||||
else {
|
||||
const promises = pdfFiles.map(async (pdf) => {return{uint8Array: await pdf.uint8Array, filename: pdf.filename + ".pdf"}})
|
||||
const promises = pdfFiles.map(async (pdf) => {return{uint8Array: await pdf.uint8Array, filename: pdf.filename + ".pdf"}});
|
||||
const files = await Promise.all(promises);
|
||||
respondWithZip(res, filename, files);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { exec, spawn } from 'child_process'
|
||||
import { PdfFile, RepresentationType } from '@stirling-pdf/shared-operations/src/wrappers/PdfFile'
|
||||
import fs from "fs";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { exec, spawn } from "child_process";
|
||||
import { PdfFile, RepresentationType } from "@stirling-pdf/shared-operations/src/wrappers/PdfFile";
|
||||
|
||||
export async function fileToPdf(byteArray: Uint8Array, filename: string): Promise<PdfFile> {
|
||||
const parentDir = path.join(os.tmpdir(), "StirlingPDF");
|
||||
@@ -46,14 +46,14 @@ export function isLibreOfficeInstalled() {
|
||||
const result = stdout.match("LibreOffice ([0-9]+\.){4}.*");
|
||||
resolve(result ? true : false);
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function writeBytesToFile(filePath: string, bytes: Uint8Array): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.writeFile(filePath, bytes, function(err) {
|
||||
if(err) {
|
||||
reject(err)
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
@@ -80,17 +80,17 @@ function runLibreOfficeCommand(idKey: string, args: string[]): Promise<string[]>
|
||||
|
||||
const process = spawn("libreoffice", args);
|
||||
|
||||
process.stdout.on('data', (data) => {
|
||||
process.stdout.on("data", (data) => {
|
||||
const dataStr = data.toString();
|
||||
console.log(`Progress ${idKey}:`, dataStr);
|
||||
messageList.push(dataStr);
|
||||
});
|
||||
|
||||
process.stderr.on('data', (data) => {
|
||||
process.stderr.on("data", (data) => {
|
||||
console.error(`stderr ${idKey}:`, data.toString());
|
||||
});
|
||||
|
||||
process.on('exit', (code) => {
|
||||
process.on("exit", (code) => {
|
||||
if (code === 0) {
|
||||
resolve(messageList);
|
||||
} else {
|
||||
@@ -98,7 +98,7 @@ function runLibreOfficeCommand(idKey: string, args: string[]): Promise<string[]>
|
||||
}
|
||||
});
|
||||
|
||||
process.on('error', (err) => {
|
||||
process.on("error", (err) => {
|
||||
reject(err);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user