-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.js
More file actions
27 lines (24 loc) · 1.01 KB
/
io.js
File metadata and controls
27 lines (24 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// io.js
async function loadSchemaFromFile(path = 'test.json') {
const res = await fetch(path, { cache: 'no-store' });
if (!res.ok) throw new Error(`Failed to load ${path}: ${res.status}`);
return await res.json();
}
function saveSchemaToLocalStorage(schema) {
localStorage.setItem('dbdesigner:lastSchema', JSON.stringify(schema));
}
function loadSchemaFromLocalStorage() {
const raw = localStorage.getItem('dbdesigner:lastSchema');
return raw ? JSON.parse(raw) : null;
}
// UPDATED: allow choosing the target file (defaults to test.json)
async function saveSchemaToServer(schema, filename = 'test.json') {
const res = await fetch(`/api/save?file=${encodeURIComponent(filename)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(schema, null, 2),
});
if (!res.ok) throw new Error(`Save failed: ${res.status}`);
return await res.text();
}
window.saveSchemaToServer = saveSchemaToServer; // (optional) expose to console