Skip to content

Commit

Permalink
change dropbox links
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrm committed Oct 11, 2023
1 parent 5c0e3c5 commit ef2ffcc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ describe("util", () => {
const result = checkAndSanitizePath(url);
expect(result).toEqual(url);
});
test("it returns a dropbox url unmodified", () => {
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 ef2ffcc

Please sign in to comment.