Skip to content

Commit

Permalink
fix(routes/rtf/txt): rtf images dumped into cwd (#1297)
Browse files Browse the repository at this point in the history
* fix(routes/rtf/txt): rtf images dumped into cwd

* test(routes/rtf/txt): remove debug log
  • Loading branch information
Fdawgs authored Mar 3, 2023
1 parent fa823ff commit 20144e8
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 215 deletions.
139 changes: 137 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"fluent-json-schema": "^4.1.0",
"glob": "^9.1.0",
"html-minifier-terser": "^7.1.0",
"html-to-text": "^9.0.4",
"htmltidy2": "^1.0.1",
"jsdom": "^21.1.0",
"language-tags": "^1.0.8",
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/rtf-to-html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const { randomUUID } = require("crypto");
* for options.
* @param {string} options.tempDir - Directory for temporarily storing
* files during conversion.
* @param {string} [options.tempFilePrefix="docsmith_rtf-to-html"] - Prefix for temporary file names.
*/
async function plugin(server, options) {
const directory = path.normalizeTrim(options.tempDir);
Expand Down Expand Up @@ -78,11 +79,12 @@ async function plugin(server, options) {
noPictures: true,
outputHtml: true,
},
tempFilePrefix: "docsmith_rtf-to-html",
...options,
};

// Build temporary file for UnRTF to write to, and following plugins to read from
const id = `docsmith_rtf-to-html_${randomUUID()}`;
const id = `${config.tempFilePrefix}_${randomUUID()}`;
const tempFile = path.joinSafe(directory, `${id}.rtf`);
req.conversionResults.docLocation = {
directory,
Expand Down Expand Up @@ -110,6 +112,7 @@ async function plugin(server, options) {
* ever have the same name.
*/
const images = dom.window.document.querySelectorAll("img");
/* istanbul ignore if: dependant on UnRTF version used */
if (images.length > 0) {
await Promise.all(
Array.from(images).map((image) => {
Expand All @@ -122,6 +125,9 @@ async function plugin(server, options) {
*/
return fs.rm(path.joinSafe(process.cwd(), src), {
force: true,
maxRetries: 10,
recursive: true,
retryDelay: 100,
});
})
);
Expand Down
117 changes: 0 additions & 117 deletions src/plugins/rtf-to-txt/index.js

This file was deleted.

Loading

0 comments on commit 20144e8

Please sign in to comment.