From ef2ffcc832943f1ea8eaf8789a73f157d86417eb Mon Sep 17 00:00:00 2001 From: meganrm Date: Tue, 10 Oct 2023 20:18:03 -0700 Subject: [PATCH] change dropbox links --- src/test/util.test.ts | 7 +++++++ src/util.ts | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/test/util.test.ts b/src/test/util.test.ts index 4a50a06f..83c94843 100644 --- a/src/test/util.test.ts +++ b/src/test/util.test.ts @@ -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); diff --git a/src/util.ts b/src/util.ts index bfc8d845..ac7d0140 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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; }