Skip to content

Commit 8ffe988

Browse files
fix: load URLs that do not include an extension (#92)
* fix: append subdomain prefix to 'nmrxiv.org' * fix: append .zip extension if the file URL not include an extension * test: load URLs that do not include an extension
1 parent 2ed264d commit 8ffe988

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

src/allowed-origins.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@
1515
"https://chemotion-t-01.zdv.uni-mainz.de",
1616
"https://chemotion-01.zdv.uni-mainz.de",
1717
"https://chemotion.biblio.etc.tu-bs.de"
18-
]
19-
18+
]

src/demo/NMRiumWrapperDemo.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ export default function NMRiumWrapperDemo() {
5555
>
5656
Test Load from URLS
5757
</Button.Done>
58+
59+
<Button.Done
60+
style={{ marginRight: '10px' }}
61+
onClick={() => {
62+
events.trigger('load', {
63+
data: [
64+
'https://cheminfo.github.io/bruker-data-test/data/zipped/aspirin-1h',
65+
],
66+
type: 'url',
67+
});
68+
}}
69+
>
70+
Test Load URL without extension
71+
</Button.Done>
5872
<Button.Done
5973
onClick={async () => {
6074
const files = await loadFilesFromURLs(['../data/13c.zip']);

src/hooks/useLoadSpectra.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ async function loadSpectraFromFiles(files: File[]) {
2323
async function loadSpectraFromURLs(urls: string[]) {
2424
const entries = urls.map((url) => {
2525
const refURL = new URL(url);
26-
let name = getFileNameFromURL(url);
26+
const name = getFileNameFromURL(url);
27+
let path = refURL.pathname;
2728
const hasExtension = name && name.indexOf('.') !== -1;
2829
if (!hasExtension) {
29-
name = `${name}.zip`;
30+
path = `${path}.zip`;
3031
}
31-
return { relativePath: refURL.pathname, baseURL: refURL.origin };
32+
return { relativePath: path, baseURL: refURL.origin };
3233
}, []);
3334

3435
const { data } = await readFromWebSource({ entries });

test-e2e/core.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,13 @@ test('should load NMRium from json', async ({ page }) => {
6464
// if loaded successfully, there should be a 1H and 13C tabs
6565
await expect(nmrium.page.locator('.tab-list-item >> text=13C')).toBeVisible();
6666
});
67+
test('should load NMRium from URL without .zip extension in the path', async ({
68+
page,
69+
}) => {
70+
const nmrium = await NmriumWrapperPage.create(page);
71+
72+
await nmrium.page.click('text=Test Load URL without extension');
73+
74+
// if loaded successfully, there should be a 1H
75+
await expect(nmrium.page.locator('.tab-list-item >> text=1H')).toBeVisible();
76+
});

0 commit comments

Comments
 (0)