Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change dropbox links #335

Merged
merged 2 commits into from
Oct 11, 2023
Merged
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: 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");
ShrimpCryptid marked this conversation as resolved.
Show resolved Hide resolved
}
return url;
} else if (/\B\//g.test(pathOrUrl)) {
return pathOrUrl;
}
Expand Down