Skip to content

Commit a509496

Browse files
committed
Add if statements and isAbsoluteUrl function
1 parent 50e9ab5 commit a509496

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/vitessce/widget.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,12 @@ def get_uid_str(uid):
163163
const { createRoot } = await importWithMap("react-dom/client", importMap);
164164
165165
const e = React.createElement;
166+
167+
function isAbsoluteUrl(s) {
168+
return s.startsWith('http://') || s.startsWith('https://');
169+
}
166170
const WORKSPACES_URL_KEYWORD = 'https://workspaces-pt';
171+
const OPTIONS_URL_KEYS = ['offsetsUrl', 'refSpecUrl'];
167172
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
168173
// The jupyter server may be running through a proxy,
169174
// which means that the client needs to prepend the part of the URL before /proxy/8000 such as
@@ -197,24 +202,25 @@ def get_uid_str(uid):
197202
datasets: config.datasets.map(d => ({
198203
...d,
199204
files: d.files.map(f => {
200-
// Update the main file URL
201-
const updatedUrl = f.url.startsWith('http://') || f.url.startsWith('https://')
202-
? f.url
203-
: `${origin}${baseUrl}${f.url}`;
204-
// Update any urls within the options object
205-
const updatedOptions = { ...f.options };
206-
['offsetsUrl', 'refSpecUrl'].forEach(key => {
207-
if (updatedOptions.hasOwnProperty(key)) {
208-
if (!updatedOptions[key].startsWith('http://') && !updatedOptions[key].startsWith('https://')) {
209-
updatedOptions[key] = `${origin}${baseUrl}${updatedOptions[key]}`;
205+
const updatedFileDef = { ...f };
206+
if (!isAbsoluteUrl(f.url)) {
207+
// Update the main file URL if necessary.
208+
updatedFileDef.url = `${origin}${baseUrl}${f.url}`;
209+
}
210+
if (f.options) {
211+
// Update any urls within the options object
212+
const updatedOptions = { ...f.options };
213+
OPTIONS_URL_KEYS.forEach(key => {
214+
const optionValue = updatedOptions[key];
215+
if (optionValue) {
216+
if (!isAbsoluteUrl(optionValue)) {
217+
updatedOptions[key] = `${origin}${baseUrl}${optionValue}`;
218+
}
210219
}
211-
}
212-
});
213-
return {
214-
...f,
215-
url: updatedUrl,
216-
options: updatedOptions,
217-
};
220+
});
221+
updatedFileDef.options = updatedOptions;
222+
}
223+
return updatedFileDef;
218224
}),
219225
})),
220226
};

0 commit comments

Comments
 (0)