Skip to content

Commit 8bad513

Browse files
committed
Fix file uploads.
1 parent 0743f39 commit 8bad513

1 file changed

Lines changed: 33 additions & 7 deletions

File tree

web/aladin.html

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='8' fill='%230f172a'/%3E%3Cpath fill='%23facc15' d='M16 4l3.4 7 7.6.7-5.8 5.2 1.8 7.6-7-4.2-7 4.2 1.8-7.6-5.8-5.2 7.6-.7z'/%3E%3C/svg%3E" />
88
<link rel="stylesheet" href="/static/styles.css" />
99
<link rel="stylesheet" href="https://aladin.cds.unistra.fr/AladinLite/api/v3/latest/aladin.min.css" />
10+
<script src="https://aladin.cds.unistra.fr/AladinLite/api/v3/latest/aladin.js"></script>
1011
</head>
1112
<body>
1213
<div id="aladin-lite-div" aria-label="Interactive FITS viewer"></div>
@@ -57,8 +58,11 @@
5758
</p>
5859
<p class="notice hidden" id="aladin-error" role="alert"></p>
5960
</aside>
60-
<script type="module">
61-
import { A } from 'https://aladin.cds.unistra.fr/AladinLite/api/v3/latest/aladin.min.js';
61+
<script>
62+
const { A } = window;
63+
if (!A) {
64+
console.error('Aladin Lite library failed to load.');
65+
}
6266

6367
const statusMessage = document.getElementById('status-message');
6468
const errorBox = document.getElementById('aladin-error');
@@ -145,6 +149,7 @@
145149
const label = options.label || deriveLabel(source);
146150

147151
clearError();
152+
statusMessage.textContent = `Loading ${label}…`;
148153
const loadTimeout = window.setTimeout(() => {
149154
if (requestId !== currentRequestId) {
150155
return;
@@ -153,15 +158,28 @@
153158
showError('The FITS file is taking longer than expected to respond. Please try again or use a different source.');
154159
}, options.timeout ?? 20000);
155160

156-
const clearLoadState = () => {
161+
let finished = false;
162+
163+
const finish = () => {
164+
if (finished) {
165+
return;
166+
}
167+
finished = true;
157168
window.clearTimeout(loadTimeout);
169+
if (typeof options.onCleanup === 'function') {
170+
try {
171+
options.onCleanup();
172+
} catch (cleanupError) {
173+
console.warn('Cleanup callback failed', cleanupError);
174+
}
175+
}
158176
};
159177

160178
const handleSuccess = (ra, dec, fov, image) => {
161179
if (requestId !== currentRequestId) {
162180
return;
163181
}
164-
clearLoadState();
182+
finish();
165183
configureImage(image, options.colormap);
166184
focusOnImage(ra, dec, fov);
167185
updateStatus(label, fov);
@@ -171,15 +189,15 @@
171189
if (requestId !== currentRequestId) {
172190
return;
173191
}
174-
clearLoadState();
192+
finish();
175193
console.error('Failed to load FITS data', error);
176194
showError('Unable to load the FITS data. Please verify the file or URL and try again.');
177195
};
178196

179197
try {
180198
const result = aladinInstance.displayFITS(source, options.params || {}, handleSuccess, handleError);
181199
if (result && typeof result.then === 'function') {
182-
result.catch(handleError).finally(clearLoadState);
200+
result.catch(handleError).finally(finish);
183201
}
184202
} catch (error) {
185203
handleError(error);
@@ -191,7 +209,11 @@
191209
if (!file) {
192210
return;
193211
}
194-
loadFits(file, { label: `Local file: ${file.name}` });
212+
const objectUrl = URL.createObjectURL(file);
213+
loadFits(objectUrl, {
214+
label: `Local file: ${file.name}`,
215+
onCleanup: () => URL.revokeObjectURL(objectUrl)
216+
});
195217
event.target.value = '';
196218
}
197219

@@ -220,6 +242,10 @@
220242
}
221243

222244
async function initialiseViewer() {
245+
if (!A) {
246+
showError('Aladin Lite could not be loaded. Please check your connection and refresh the page.');
247+
return;
248+
}
223249
try {
224250
await A.init;
225251
aladinInstance = await A.aladin('#aladin-lite-div', {

0 commit comments

Comments
 (0)