Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/components/renderer/file-download.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ export default {
this.setFilesInfo();
},
methods: {
isWebEntryTemporaryFileId(fileId) {
return typeof fileId === "string" && fileId.startsWith("webentry_");
},
downloadFile(file) {
if (this.collection) {
this.downloadCollectionFile(file);
Expand Down Expand Up @@ -209,6 +212,12 @@ export default {
const fileId = this.value
? this.value
: _.get(this.requestData, this.fileDataName, null);

if (this.isWebEntryTemporaryFileId(fileId)) {
this.filesInfo = [];
return;
}

let { endpoint } = this;

if (this.requestFiles) {
Expand Down
49 changes: 49 additions & 0 deletions tests/unit/FileDownloadUtils.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const fs = require("fs");
const path = require("path");
const vm = require("vm");

const componentPath = path.join(
process.cwd(),
"src/components/renderer/file-download.vue"
);

const source = fs.readFileSync(componentPath, "utf8");

function getComponentOptions() {
const scriptMatch = source.match(/<script>([\s\S]*?)<\/script>/);

if (!scriptMatch) {
throw new Error("Unable to find file-download.vue script block");
}

const executableScript = scriptMatch[1]
.replace(/^import .*$/gm, "")
.replace("export default", "module.exports =");

const sandbox = {
module: { exports: {} },
exports: {}
};

vm.runInNewContext(executableScript, sandbox, { filename: componentPath });

return sandbox.module.exports;
}

describe("File Download Web Entry temporary files", () => {
const FileDownload = getComponentOptions();
const { isWebEntryTemporaryFileId } = FileDownload.methods;

test("recognizes a Web Entry temporary file ID", () => {
expect(isWebEntryTemporaryFileId("webentry_upload_123_document.pdf")).toBe(
true
);
});

test.each([123, "123", "request_file_123", null, undefined, {}, []])(
"does not classify %p as a temporary file ID",
(fileId) => {
expect(isWebEntryTemporaryFileId(fileId)).toBe(false);
}
);
});
Loading