-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.html
More file actions
501 lines (455 loc) · 22.6 KB
/
Copy pathupload.html
File metadata and controls
501 lines (455 loc) · 22.6 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Dashboard Pack — Handi Homepage</title>
<link rel="stylesheet" href="/css/vendor/fa-7.2.0/css/all.min.css">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
background: #f6f8fc;
color: #1e1e1e;
padding: 40px 20px;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.container {
max-width: 600px;
width: 100%;
background: #fff;
border-radius: 20px;
padding: 40px;
box-shadow: 0 8px 30px rgba(0,0,0,0.08);
text-align: center;
}
h1 { font-size: 1.8rem; margin-bottom: 8px; }
h1 i { color: #0047cc; }
p.desc { color: #64748b; margin-bottom: 24px; font-size: 1rem; }
.drop-zone {
border: 3px dashed #cbd5e1;
border-radius: 16px;
padding: 40px;
margin-bottom: 20px;
transition: border-color 0.2s, background 0.2s;
cursor: pointer;
}
.drop-zone:hover, .drop-zone.dragover {
border-color: #0047cc;
background: #eaf2ff;
}
.drop-zone i { font-size: 3rem; color: #94a3b8; margin-bottom: 12px; display: block; margin-left: auto; margin-right: auto; }
.drop-zone p { color: #64748b; }
.drop-zone .browse { color: #0047cc; font-weight: 700; text-decoration: underline; }
input[type="file"] { display: none; }
.progress { display: none; margin: 20px 0; }
.progress-bar {
height: 8px;
background: #e5e7eb;
border-radius: 4px;
overflow: hidden;
margin-bottom: 8px;
}
.progress-bar div {
height: 100%;
background: #0047cc;
border-radius: 4px;
transition: width 0.3s;
}
.status { font-size: 0.9rem; color: #64748b; }
.log { text-align: left; font-size: 0.85rem; color: #475569; max-height: 200px; overflow-y: auto; margin-top: 16px; display: none; }
.log-item { padding: 4px 0; border-bottom: 1px solid #f1f5f9; }
.log-item.done { color: #16a34a; }
.log-item.skip { color: #94a3b8; }
.back-link { display: block; margin-top: 24px; color: #0047cc; font-size: 0.9rem; }
</style>
</head>
<body>
<div class="container">
<h1><i class="fa-solid fa-file-zipper"></i> Load Dashboard Pack</h1>
<p class="desc">Drop a <strong>.zip</strong> file containing your dashboard assets (music, images, podcasts, theme, config)</p>
<div class="drop-zone" id="dropZone">
<i class="fa-solid fa-cloud-arrow-up"></i>
<p>Drag & drop your ZIP here<br>or <span class="browse">browse files</span></p>
</div>
<input type="file" id="fileInput" accept=".zip">
<div class="progress" id="progress">
<div class="progress-bar"><div id="progressFill" style="width:0%"></div></div>
<div class="status" id="status"></div>
</div>
<div class="log" id="log"></div>
<a href="/selector.html" class="back-link">← Back to Element Selector</a>
</div>
<script type="module">
import JSZip from 'https://cdn.jsdelivr.net/npm/jszip@3.10.1/+esm';
const dropZone = document.getElementById("dropZone");
const fileInput = document.getElementById("fileInput");
const progress = document.getElementById("progress");
const progressFill = document.getElementById("progressFill");
const status = document.getElementById("status");
const log = document.getElementById("log");
function addLog(msg, cls) {
const d = document.createElement("div");
d.className = "log-item " + (cls || "");
d.textContent = msg;
log.appendChild(d);
log.style.display = "block";
log.scrollTop = log.scrollHeight;
}
function setProgress(pct, msg) {
progress.style.display = "block";
progressFill.style.width = pct + "%";
status.textContent = msg;
}
dropZone.addEventListener("click", () => fileInput.click());
dropZone.addEventListener("dragover", (e) => { e.preventDefault(); dropZone.classList.add("dragover"); });
dropZone.addEventListener("dragleave", () => dropZone.classList.remove("dragover"));
dropZone.addEventListener("drop", (e) => {
e.preventDefault();
dropZone.classList.remove("dragover");
if (e.dataTransfer.files.length) processZip(e.dataTransfer.files[0]);
});
fileInput.addEventListener("change", () => {
if (fileInput.files.length) processZip(fileInput.files[0]);
});
// Generate a :root {} CSS block from config theme colors/fonts
function buildThemeCss(cfg) {
if (!cfg.theme || !cfg.theme.colors) return null;
var c = cfg.theme.colors;
var f = cfg.theme.fonts || {};
var css = ":root {\n";
if (c.primary) {
css += " --primary: " + c.primary + ";\n";
css += " --primary-soft: " + c.primary + "15;\n";
css += " --primary-dark: " + c.primary + ";\n";
}
if (c.secondary) css += " --secondary: " + c.secondary + ";\n";
if (c.tertiary) css += " --tertiary: " + c.tertiary + ";\n";
if (c.background) css += " --bg: " + c.background + ";\n --surface: " + c.background + ";\n";
// --bg-image is handled separately via handiBgDataUrl (data URL), so omit it here
// to avoid 404s from relative URLs resolving against site-pack.css location.
if (f.text) css += " --text-font: " + f.text + ";\n";
if (f.header) css += " --header-font: " + f.header + ";\n";
css += "}\n";
return css;
}
/** Detect whether a file path points to a video based on extension. */
function detectMediaTypeFromPath(path) {
if (!path) return "image";
if (/\.(mp4|webm|ogg|ogv|mov|avi|mkv)$/i.test(path)) return "video";
return "image";
}
/** Detect media type from a data URI. */
function detectMediaTypeFromDataUri(uri) {
if (!uri) return "image";
if (uri.startsWith("data:video/")) return "video";
return "image";
}
async function processZip(file) {
log.innerHTML = "";
setProgress(0, "Reading ZIP...");
addLog("Reading: " + file.name);
try {
const zip = await JSZip.loadAsync(file);
const files = Object.keys(zip.files).filter(f => !f.startsWith("__MACOSX") && !f.endsWith("/"));
const total = files.length;
setProgress(5, `Found ${total} files in ZIP`);
let musicFiles = [], imageFiles = [], castFiles = [], imageByPath = {};
let themeCss = null, configJson = null, contactsJson = null, contactPhotos = {};
let processed = 0;
for (const [path, entry] of Object.entries(zip.files)) {
if (path.startsWith("__MACOSX") || entry.dir) continue;
const name = path.split("/").pop();
const ext = name.split(".").pop().toLowerCase();
const blob = await entry.async("blob");
const fileObj = new File([blob], name, { type: blob.type || "application/octet-stream" });
var isMusic = path.startsWith("music/") || path.includes("/music/");
var isImg = path.startsWith("img/") || path.includes("/img/");
var isPodcast = path.startsWith("podcasts/") || path.includes("/podcasts/");
var isAudio = ["mp3", "wav", "ogg", "m4a", "flac"].includes(ext);
var isImage = ["jpg", "jpeg", "png", "webp", "gif"].includes(ext);
if (isMusic && isAudio) {
musicFiles.push(fileObj);
addLog("🎵 " + path, "done");
} else if (isImg && isImage) {
imageFiles.push(fileObj);
imageByPath[path] = blob;
addLog("🖼️ " + path, "done");
} else if (isPodcast && isAudio) {
castFiles.push(fileObj);
addLog("🎙️ " + path, "done");
} else if (path.endsWith("theme.css")) {
themeCss = await entry.async("text");
addLog("🎨 theme.css", "done");
} else if (path.endsWith("config.json")) {
configJson = await entry.async("text");
addLog("⚙️ config.json", "done");
} else if (path.includes("/phone/") && path.endsWith("contacts.json")) {
contactsJson = await entry.async("text");
addLog("📞 contacts.json", "done");
} else if (path.match(/\/phone\/photos?\/.+\.(jpg|jpeg|png|webp)$/i)) {
const idx = parseInt(name.replace(/\..*/, ''));
if (!isNaN(idx)) {
contactPhotos[idx] = URL.createObjectURL(blob);
addLog("📷 phone photo #" + idx, "done");
}
} else {
addLog("⏭️ " + path + " (skipped)", "skip");
}
processed++;
setProgress(5 + Math.round((processed / total) * 85), `Processing ${processed}/${total}...`);
}
// Store files
setProgress(90, "Saving...");
const { saveMusic, saveGallery, saveCastFn } = await import("/js/core/storage.js?v=4");
if (musicFiles.length) {
addLog("Saving " + musicFiles.length + " music files...");
await saveMusic(musicFiles);
addLog("Saved " + musicFiles.length + " music files", "done");
}
if (imageFiles.length) {
addLog("Saving " + imageFiles.length + " images...");
await saveGallery(imageFiles);
addLog("Saved " + imageFiles.length + " images", "done");
}
if (castFiles.length) {
addLog("Saving " + castFiles.length + " podcasts...");
await saveCastFn(castFiles);
addLog("Saved " + castFiles.length + " podcasts", "done");
}
// Theme: use file CSS, or generate from config colors
if (themeCss) {
localStorage.setItem("handiCustomTheme", themeCss);
addLog("Custom theme saved", "done");
}
// Merge config.json into handiSettings
console.log("[upload] configJson present:", !!configJson);
if (configJson) {
try {
const cfg = JSON.parse(configJson);
localStorage.setItem("handiCustomConfig", JSON.stringify(cfg));
const settings = JSON.parse(localStorage.getItem("handiSettings") || "{}");
// Generate theme CSS from config colors if no theme.css file
if (!themeCss) {
const genCss = buildThemeCss(cfg);
if (genCss) {
localStorage.setItem("handiCustomTheme", genCss);
addLog("Theme generated from config colors", "done");
}
}
// Convert background image to data URL for dashboard
var bgDataUrl = null;
var bgPath = cfg.theme?.background;
if (bgPath && imageByPath[bgPath]) {
bgDataUrl = await new Promise(function(resolve) {
var fr = new FileReader();
fr.onload = function() { resolve(fr.result); };
fr.readAsDataURL(imageByPath[bgPath]);
});
localStorage.setItem("handiBgDataUrl", bgDataUrl);
addLog("Background image saved for dashboard", "done");
}
// Strip background-image references from stored theme CSS now that
// we have a data URL. Relative URLs in custom properties resolve
// against the stylesheet where var() is *used* (site-pack.css at /css/),
// causing 404s (e.g. img/foo.png → /css/img/foo.png).
if (bgDataUrl) {
var storedCss = localStorage.getItem("handiCustomTheme");
if (storedCss) {
// Remove any --bg-image declaration
storedCss = storedCss.replace(/--bg-image\s*:\s*[^;]+;?\s*/g, "");
// Remove direct background-image / background that reference
// the same relative image path (only if it matches bgPath)
if (bgPath) {
var escapedPath = bgPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
var bgRe = new RegExp("(background(?:-image)?)\\s*:\\s*url\\([\"']?" + escapedPath + "[\"']?\\)\\s*(!important)?\\s*;?", "gi");
storedCss = storedCss.replace(bgRe, "");
}
localStorage.setItem("handiCustomTheme", storedCss);
}
}
// Enable modules from elements list (write to MMR, not settings.enabledModules)
if (cfg.elements && Array.isArray(cfg.elements)) {
var mmr = JSON.parse(localStorage.getItem("handiMasterModules") || "{}");
// Map config names to MMR module IDs
var idMap = { bus: "live_bus", emergency: "emergency_alert" };
cfg.elements.forEach(function(el) {
var key = idMap[el] || el;
mmr[key] = 1;
});
localStorage.setItem("handiMasterModules", JSON.stringify(mmr));
addLog("Enabled modules: " + cfg.elements.join(", "), "done");
}
// Weather
if (cfg.weather && cfg.weather.location) {
settings.weather = settings.weather || {};
settings.weather.location = cfg.weather.location;
addLog("Weather: " + cfg.weather.location, "done");
}
// News RSS — handle both array and object formats
console.log("[upload] cfg.news:", JSON.stringify(cfg.news));
if (cfg.news && cfg.news.feeds) {
var rssUrl = "";
if (Array.isArray(cfg.news.feeds)) {
rssUrl = cfg.news.feeds[0];
} else if (typeof cfg.news.feeds === "object") {
var vals = Object.values(cfg.news.feeds);
rssUrl = vals[0] || "";
}
if (rssUrl && rssUrl.indexOf("//") === 0) rssUrl = "https:" + rssUrl;
console.log("[upload] News RSS extracted:", rssUrl);
if (rssUrl) {
settings.news = settings.news || {};
settings.news.rssUrl = rssUrl;
localStorage.setItem("handiNewsFeed", rssUrl);
addLog("News RSS: " + rssUrl, "done");
}
}
// Radio feeds
if (cfg.radio) {
settings.radio = settings.radio || {};
if (cfg.radio.feeds && cfg.radio.feeds.length) {
settings.radio.customFeeds = cfg.radio.feeds;
addLog("Radio feeds: " + cfg.radio.feeds.length, "done");
}
if (cfg.radio.defaultCountry) {
settings.radio.defaultCountry = cfg.radio.defaultCountry;
localStorage.setItem("handiRadioCountry", cfg.radio.defaultCountry);
addLog("Radio country: " + cfg.radio.defaultCountry, "done");
}
}
// Social / Mastodon
if (cfg.social) {
settings.social = settings.social || {};
if (cfg.social.feeds && cfg.social.feeds.length) {
try {
const u = new URL(cfg.social.feeds[0]);
settings.social.instance = u.origin;
addLog("Mastodon instance: " + u.origin, "done");
} catch(e) {}
}
if (cfg.social.hashtag) {
settings.social.hashtag = cfg.social.hashtag;
settings.social.feedType = "hashtag";
addLog("Hashtag: " + cfg.social.hashtag, "done");
}
if (cfg.social.profile) {
var p = cfg.social.profile;
try {
var pu = new URL(p);
p = "@" + pu.pathname.replace(/^\/+/, "").replace(/^@/, "") + "@" + pu.hostname;
} catch(e) {}
settings.social.profile = p;
if (!cfg.social.hashtag) settings.social.feedType = "profile";
addLog("Profile: " + p, "done");
}
}
// Chat / Matrix
if (cfg.chat) {
settings.chat = settings.chat || {};
if (cfg.chat.matrix_server) {
settings.chat.homeserver = cfg.chat.matrix_server;
addLog("Matrix server: " + cfg.chat.matrix_server, "done");
}
if (cfg.chat.rooms && cfg.chat.rooms.length) {
settings.chat.rooms = cfg.chat.rooms;
addLog("Chat rooms: " + cfg.chat.rooms.join(", "), "done");
}
}
// Calendar
if (cfg.calendar && cfg.calendar.ics_link) {
settings.calendar = settings.calendar || {};
settings.calendar.url = cfg.calendar.ics_link;
addLog("Calendar ICS saved", "done");
}
// Support
if (cfg.support) {
settings.support = settings.support || {};
// Accept both short keys (title/link) and full keys (imageTitle/linkUrl)
if (cfg.support.title || cfg.support.imageTitle) {
settings.support.imageTitle = cfg.support.title || cfg.support.imageTitle;
}
if (cfg.support.link || cfg.support.linkUrl) {
settings.support.linkUrl = cfg.support.link || cfg.support.linkUrl;
}
if (cfg.support.description) {
settings.support.description = cfg.support.description;
}
// Look up media by path (image, video, or generic "media" key);
// also accept if value is already a data URL
var supMediaPath = cfg.support.image || cfg.support.imageUrl || cfg.support.media || "";
if (supMediaPath && imageByPath[supMediaPath]) {
var supDataUrl = await new Promise(function(resolve) {
var fr = new FileReader();
fr.onload = function() { resolve(fr.result); };
fr.readAsDataURL(imageByPath[supMediaPath]);
});
settings.support.imageUrl = supDataUrl;
settings.support.mediaType = detectMediaTypeFromPath(supMediaPath);
var label = settings.support.mediaType === "video" ? "video" : "image";
addLog("Support " + label + " saved", "done");
} else if (cfg.support.imageUrl && cfg.support.imageUrl.startsWith("data:")) {
// Already a data URL – use directly
settings.support.imageUrl = cfg.support.imageUrl;
settings.support.mediaType = cfg.support.mediaType || detectMediaTypeFromDataUri(cfg.support.imageUrl);
addLog("Support media (inline) saved", "done");
}
addLog("Support module configured", "done");
}
// Bus routes
if (cfg.bus && cfg.bus.routes && cfg.bus.routes.length) {
settings.live_bus = settings.live_bus || {};
for (let ri = 0; ri < Math.min(cfg.bus.routes.length, 3); ri++) {
const n = ri + 1;
settings.live_bus["route" + n + "_id"] = cfg.bus.routes[ri];
settings.live_bus["route" + n + "_short"] = String(cfg.bus.routes[ri]);
}
addLog("Bus routes: " + cfg.bus.routes.join(", "), "done");
}
// Phone contacts from config (inline)
if (cfg.phone && cfg.phone.contacts && cfg.phone.contacts.length) {
settings.phone = settings.phone || {};
settings.phone.contacts = cfg.phone.contacts;
addLog("Phone contacts: " + cfg.phone.contacts.length, "done");
}
localStorage.setItem("handiSettings", JSON.stringify(settings));
addLog("Config merged into dashboard settings", "done");
} catch (e) {
addLog("Config parse failed: " + e.message, "skip");
}
}
// Separate phone/contacts.json (overrides config contacts if present)
if (contactsJson || Object.keys(contactPhotos).length) {
try {
const settings = JSON.parse(localStorage.getItem("handiSettings") || "{}");
settings.phone = settings.phone || {};
if (contactsJson) {
settings.phone.contacts = JSON.parse(contactsJson);
addLog("Loaded " + settings.phone.contacts.length + " contacts from phone/", "done");
}
if (Object.keys(contactPhotos).length) {
localStorage.setItem("handiContactPhotos", JSON.stringify(contactPhotos));
addLog("Loaded " + Object.keys(contactPhotos).length + " contact photos", "done");
}
localStorage.setItem("handiSettings", JSON.stringify(settings));
} catch (e) {
addLog("Contacts failed: " + e.message, "skip");
}
}
setProgress(100, "Done!");
addLog("Total: " + musicFiles.length + " music, " + imageFiles.length + " images, " + castFiles.length + " podcasts", "done");
if (!musicFiles.length && !imageFiles.length && !castFiles.length) {
addLog("No files matched. Make sure your ZIP has music/, img/, podcasts/ folders.", "skip");
}
setTimeout(() => { window.location.href = "/index.html"; }, 1500);
} catch (e) {
setProgress(0, "Error: " + e.message);
addLog("ERROR: " + e.message);
}
}
</script>
</body>
</html>