diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/electron/renderer/src/server/globals.ts b/src/electron/renderer/src/server/globals.ts index 698243dc9..af69d9af9 100644 --- a/src/electron/renderer/src/server/globals.ts +++ b/src/electron/renderer/src/server/globals.ts @@ -56,7 +56,7 @@ export const activateServer = () => { export const serverGlobals = { species: new Promise((res, rej) => { onServerOpen(() => { - fetch(new URL("get-recommended-species", baseUrl)) + fetch(new URL("dandi/get-recommended-species", baseUrl)) .then((res) => res.json()) .then((species) => { res(species) @@ -67,7 +67,7 @@ export const serverGlobals = { }), cpus: new Promise((res, rej) => { onServerOpen(() => { - fetch(new URL("cpus", baseUrl)) + fetch(new URL("system/cpus", baseUrl)) .then((res) => res.json()) .then((cpus) => { res(cpus) diff --git a/src/electron/renderer/src/stories/pages/preview/PreviewPage.js b/src/electron/renderer/src/stories/pages/preview/PreviewPage.js index a8e6a320a..868b279ac 100644 --- a/src/electron/renderer/src/stories/pages/preview/PreviewPage.js +++ b/src/electron/renderer/src/stories/pages/preview/PreviewPage.js @@ -18,7 +18,12 @@ export class PreviewPage extends Page { updatePath = async (path) => { if (path) { - const result = await fetch(`${baseUrl}/files/${path}`, { method: "POST" }).then((res) => res.text()); + // Enable access to the explicit file path + const result = await fetch(`${baseUrl}/files/${path}`, { + method: "POST", + }).then((res) => res.text()); + + // Set Neurosift to access the returned URL if (result) this.neurosift.url = result; } else this.neurosift.url = undefined; }; diff --git a/src/electron/renderer/src/stories/preview/NWBFilePreview.js b/src/electron/renderer/src/stories/preview/NWBFilePreview.js index 4bc8b7b71..9a82e8880 100644 --- a/src/electron/renderer/src/stories/preview/NWBFilePreview.js +++ b/src/electron/renderer/src/stories/preview/NWBFilePreview.js @@ -1,12 +1,13 @@ import { LitElement, css, html } from "lit"; import { InspectorList } from "./inspector/InspectorList"; -import { Neurosift, getURLFromFilePath } from "./Neurosift"; +import { Neurosift } from "./Neurosift"; import { unsafeHTML } from "lit/directives/unsafe-html.js"; import { run } from "../pages/guided-mode/options/utils"; import { until } from "lit/directives/until.js"; import { InstanceManager } from "../InstanceManager"; import { path } from "../../electron"; import { FullScreenToggle } from "../FullScreenToggle"; +import { baseUrl } from "../../server/globals"; export function getSharedPath(array) { array = array.map((str) => str.replace(/\\/g, "/")); // Convert to Mac-style path @@ -55,15 +56,26 @@ class NWBPreviewInstance extends LitElement { render() { const isOnline = navigator.onLine; - return isOnline - ? new Neurosift({ url: getURLFromFilePath(this.file, this.project), fullscreen: false }) - : until( - (async () => { - const htmlRep = await run("html", { nwbfile_path: this.file }, { swal: false }); - return unsafeHTML(htmlRep); - })(), - html`Loading HTML representation...` - ); + if (!isOnline) + return until( + (async () => { + const htmlRep = await run("html", { nwbfile_path: this.file }, { swal: false }); + return unsafeHTML(htmlRep); + })(), + html`Loading HTML representation...` + ); + + const neurosift = new Neurosift({ fullscreen: false }); + + // Enable access to the explicit file path + fetch(`${baseUrl}/files/${this.file}`, { method: "POST" }) + .then((res) => res.text()) + .then((result) => { + // Set Neurosift to access the returned URL + if (result) neurosift.url = result; + }); + + return neurosift; } } diff --git a/src/electron/renderer/src/stories/preview/Neurosift.js b/src/electron/renderer/src/stories/preview/Neurosift.js index 8def8c8dd..ecce4cbb9 100644 --- a/src/electron/renderer/src/stories/preview/Neurosift.js +++ b/src/electron/renderer/src/stories/preview/Neurosift.js @@ -2,12 +2,6 @@ import { LitElement, css, html } from "lit"; import { Loader } from "../Loader"; import { FullScreenToggle } from "../FullScreenToggle"; -import { baseUrl } from "../../server/globals"; - -export function getURLFromFilePath(file, projectName) { - const regexp = new RegExp(`.+(${projectName}.+)`); - return `${baseUrl}/preview/${file.match(regexp)[1]}`; -} export class Neurosift extends LitElement { static get styles() { @@ -80,7 +74,9 @@ export class Neurosift extends LitElement { render() { return this.url ? html`
- ${new Loader({ message: `Loading Neurosift view...
${this.url}` })} + ${new Loader({ + message: `Loading Neurosift view...
${this.url}`, + })}
${this.fullscreen ? new FullScreenToggle({ target: this }) : ""}