diff --git a/client/src/utils/upload-payload.js b/client/src/utils/upload-payload.js index 2fbca26c06da..7fa7d29766d2 100644 --- a/client/src/utils/upload-payload.js +++ b/client/src/utils/upload-payload.js @@ -18,6 +18,19 @@ export function isUrl(content) { return URI_PREFIXES.some((prefix) => content.startsWith(prefix)); } +export function isGalaxyFile(content) { + if (content === undefined || content === null) { + return false; + } + const galaxyRegexPattern = /Galaxy\d+-\[(.*?)\](\..+)/; + const match = content.match(galaxyRegexPattern); + if (match) { + return true; + } else { + return false; + } +} + export function uploadPayload(items, historyId, composite = false) { const files = []; const elements = items @@ -28,6 +41,11 @@ export function uploadPayload(items, historyId, composite = false) { if (fileName === DEFAULT_FILE_NAME) { fileName = null; } + if (isGalaxyFile(item.fileName)) { + const modifiedFileName = item.fileName.replace(/Galaxy\d+-\[(.*?)\](\..+)/, "$1"); + item.fileName = modifiedFileName; + fileName = modifiedFileName; + } // consolidate exclusive file content attributes const urlContent = (item.fileUri || item.filePath || item.fileContent || "").trim(); const hasFileData = item.fileData && item.fileData.size > 0; diff --git a/client/src/utils/upload-payload.test.js b/client/src/utils/upload-payload.test.js index 9a3bc946391e..747dba290fa0 100644 --- a/client/src/utils/upload-payload.test.js +++ b/client/src/utils/upload-payload.test.js @@ -66,12 +66,22 @@ describe("uploadPayload", () => { spaceToTab: false, toPosixLines: false, }, + { + dbKey: "dbKey5", + deferred: true, + extension: "extension5", + fileData: { size: 1 }, + fileMode: "local", + fileName: "Galaxy5-[PreviousGalaxyFile].bed", + spaceToTab: true, + toPosixLines: true, + }, ], "historyId" ); expect(p).toEqual({ auto_decompress: true, - files: [{ size: 1 }], + files: [{ size: 1 }, { size: 1 }], history_id: "historyId", targets: [ { @@ -126,6 +136,15 @@ describe("uploadPayload", () => { to_posix_lines: false, url: "http://test.me", }, + { + dbkey: "dbKey5", + deferred: true, + ext: "extension5", + name: "PreviousGalaxyFile", + space_to_tab: true, + src: "files", + to_posix_lines: true, + }, ], }, ], @@ -147,13 +166,24 @@ describe("uploadPayload", () => { spaceToTab: true, toPosixLines: true, }, + { + dbKey: "dbKey2", + deferred: true, + extension: "extension2", + fileContent: "fileContent", + fileData: "fileData", + fileMode: "local", + fileName: "Galaxy2-[PreviousGalaxyFile].bed", + spaceToTab: true, + toPosixLines: true, + }, ], "historyId", true ); expect(p).toEqual({ auto_decompress: true, - files: ["fileData"], + files: ["fileData", "fileData"], history_id: "historyId", targets: [ { @@ -181,6 +211,15 @@ describe("uploadPayload", () => { src: "files", to_posix_lines: true, }, + { + dbkey: "dbKey2", + deferred: true, + ext: "extension2", + name: "PreviousGalaxyFile", + space_to_tab: true, + src: "files", + to_posix_lines: true, + }, ], }, dbkey: "?",