fix
This commit is contained in:
+22
-7
@@ -1,5 +1,20 @@
|
||||
// Client for the belt's HTTP API.
|
||||
|
||||
/**
|
||||
* The project used to be called "wh". Carry over anything an earlier visit stored
|
||||
* under the old prefix (the access key, drafts, choices), so nobody is logged out.
|
||||
*/
|
||||
export function migrateStorage() {
|
||||
try {
|
||||
for (const k of Object.keys(localStorage)) {
|
||||
if (!k.startsWith('wh.')) continue;
|
||||
const next = `halcyon.${k.slice(3)}`;
|
||||
if (localStorage.getItem(next) === null) localStorage.setItem(next, localStorage.getItem(k));
|
||||
localStorage.removeItem(k);
|
||||
}
|
||||
} catch { /* storage unavailable: nothing to carry over */ }
|
||||
}
|
||||
|
||||
export class ApiError extends Error {
|
||||
constructor(status, message) {
|
||||
super(message);
|
||||
@@ -7,7 +22,7 @@ export class ApiError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
const KEY = 'wh.key';
|
||||
const KEY = 'halcyon.key';
|
||||
export const keyStore = {
|
||||
get() {
|
||||
try { return localStorage.getItem(KEY); } catch { return null; }
|
||||
@@ -64,8 +79,12 @@ export const api = {
|
||||
me: (key) => call('GET', '/me', { key }),
|
||||
ships: () => call('GET', '/ships'),
|
||||
assemble: (source) => call('POST', '/assemble', { body: source, type: 'text/plain', auth: false }),
|
||||
setProgram: (id, bytes) => call('PUT', `/ships/${id}/program`, { body: bytes, type: 'application/octet-stream' }),
|
||||
launch: (id) => call('POST', `/ships/${id}/launch`),
|
||||
// Launch a docked ship, flying the program in code slot `slot`.
|
||||
launch: (id, slot) => call('POST', `/ships/${id}/launch`, { json: { slot } }),
|
||||
slots: () => call('GET', '/slots'),
|
||||
slot: (n) => call('GET', `/slots/${n}`),
|
||||
saveSlot: (n, name, source) => call('PUT', `/slots/${n}`, { json: { name, source } }),
|
||||
deleteSlot: (n) => call('DELETE', `/slots/${n}`),
|
||||
setUplink: (id, bytes) => call('PUT', `/ships/${id}/uplink`, { body: bytes, type: 'application/octet-stream' }),
|
||||
async downlink(id) {
|
||||
const res = await call('GET', `/ships/${id}/downlink`, { raw: true });
|
||||
@@ -79,10 +98,6 @@ export const api = {
|
||||
if (!res.ok) throw new ApiError(res.status, `example ${name} not found`);
|
||||
return res.text();
|
||||
},
|
||||
async examples() {
|
||||
const res = await fetch('/examples/index.json');
|
||||
return res.ok ? res.json() : [];
|
||||
},
|
||||
};
|
||||
|
||||
export function b64ToBytes(b64) {
|
||||
|
||||
Reference in New Issue
Block a user