|
1 | 1 | import { LitElement, css, html } from "lit"; |
2 | 2 | import { InspectorList } from "./InspectorList"; |
3 | | -import { Neurosift, getURLFromFilePath } from "./Neurosift"; |
| 3 | +import { Neurosift } from "./Neurosift"; |
4 | 4 | import { unsafeHTML } from "lit/directives/unsafe-html.js"; |
5 | 5 | import { run } from "../../utils/run"; |
| 6 | +import { baseUrl } from "../server/globals"; |
6 | 7 |
|
7 | 8 | import { until } from "lit/directives/until.js"; |
8 | 9 | import { InstanceManager } from "./InstanceManager"; |
@@ -48,17 +49,38 @@ class NWBPreviewInstance extends LitElement { |
48 | 49 | super(); |
49 | 50 | this.file = file; |
50 | 51 | this.project = project; |
| 52 | + this.neurosiftUrl = undefined; |
51 | 53 |
|
52 | 54 | window.addEventListener("online", () => this.requestUpdate()); |
53 | 55 | window.addEventListener("offline", () => this.requestUpdate()); |
| 56 | + |
| 57 | + // Register the file when the instance is created |
| 58 | + this.registerFile(this.file); |
| 59 | + } |
| 60 | + |
| 61 | + async registerFile(path) { |
| 62 | + if (path) { |
| 63 | + try { |
| 64 | + // Enable access to the explicit file path |
| 65 | + const result = await fetch(`${baseUrl}/files/${path}`, { |
| 66 | + method: "POST", |
| 67 | + }).then((res) => res.text()); |
| 68 | + |
| 69 | + // Set the URL for Neurosift |
| 70 | + if (result) this.neurosiftUrl = result; |
| 71 | + this.requestUpdate(); |
| 72 | + } catch (error) { |
| 73 | + console.error("Error registering file:", error); |
| 74 | + } |
| 75 | + } |
54 | 76 | } |
55 | 77 |
|
56 | 78 | render() { |
57 | 79 | const isOnline = navigator.onLine; |
58 | 80 |
|
59 | 81 | return isOnline |
60 | 82 | ? new Neurosift({ |
61 | | - url: getURLFromFilePath(this.file, this.project), |
| 83 | + url: this.neurosiftUrl, |
62 | 84 | fullscreen: false, |
63 | 85 | }) |
64 | 86 | : until( |
|
0 commit comments