Skip to content

Commit

Permalink
Merge pull request #335 from simularium/fix/dropbox-links
Browse files Browse the repository at this point in the history
change dropbox links
  • Loading branch information
meganrm authored Oct 11, 2023
2 parents c143785 + 11921e7 commit cd75a2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,18 @@ describe("util", () => {
});
});
describe("checkAndSanitizePath", () => {
test("it returns a url unmodified", () => {
test("it returns a non dropbox url unmodified", () => {
const url = "http://www.url.com";
const result = checkAndSanitizePath(url);
expect(result).toEqual(url);
});
test("it returns a dropbox url modified with dropboxusercontent", () => {
const url =
"https://www.dropbox.com/scl/fi/xh3vmyt9d74cl5cbhqgpm/Antigen.obj?rlkey=key&dl=1";
const expected =
"https://dl.dropboxusercontent.com/scl/fi/xh3vmyt9d74cl5cbhqgpm/Antigen.obj?rlkey=key&dl=1";
expect(checkAndSanitizePath(url)).toEqual(expected);
});
test("it returns a path with a forward slash unmodified", () => {
const path = "/path/to/file.obj";
const result = checkAndSanitizePath(path);
Expand Down
6 changes: 5 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export const checkAndSanitizePath = (pathOrUrl: string): string => {
const isUrlRegEX =
/(https?:\/\/)([\w\-])+\.{1}([a-zA-Z]{2,63})([\/\w-]*)*\/?\??([^#\n\r]*)?#?([^\n\r]*)/g;
if (isUrlRegEX.test(pathOrUrl)) {
return pathOrUrl;
let url = pathOrUrl;
if (url.includes("dropbox")) {
url = url.replace("www.dropbox.com", "dl.dropboxusercontent.com");
}
return url;
} else if (/\B\//g.test(pathOrUrl)) {
return pathOrUrl;
}
Expand Down

0 comments on commit cd75a2a

Please sign in to comment.