Skip to content

Commit b52b763

Browse files
committed
Refactor config JS
Introduce a firmware upload page (upload_index.html, upload_index.js) with styles and client-side chunked upload logic, plus route mapping (/upload -> upload/index.html). Refactor many modern config modules to standardize variable names (json), use a consistent div/card element, and call fillDataKeys(div, json) instead of per-file default objects. Replace/saveDataKeyForm with an async version that normalizes input types, supports hooks (beforePost/afterPost), optional reload behavior, and improved number handling. Add feature guard for upload content generation and minor validation/UX tweaks (dmxsend slot validation moved into beforePost, ltc form validation preserved). Update khtmlinfos to expose the new upload path.
1 parent 5b9e306 commit b52b763

22 files changed

Lines changed: 638 additions & 416 deletions

lib-remoteconfig/http/content/generate_content.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ static constexpr char kHaveTimeEnd[] = "#endif // !defined (CONFIG_HTTP_HTML_NO_
107107
static constexpr char kHaveRtcBegin[] = "#if !defined (CONFIG_HTTP_HTML_NO_RTC) && !defined (DISABLE_RTC)\n";
108108
static constexpr char kHaveRtcEnd[] = "#endif // !defined (CONFIG_HTTP_HTML_NO_RTC) && !defined (DISABLE_RTC)\n";
109109

110+
static constexpr char kHaveUploadBegin[] = "#if defined (CONFIG_HTTPD_ENABLE_UPLOAD)\n";
111+
static constexpr char kHaveUploadEnd[] = "#endif // (CONFIG_HTTPD_ENABLE_UPLOAD)\n";
112+
110113
struct FeatureGuard {
111114
const char* match;
112115
const char* begin;
@@ -132,7 +135,9 @@ static constexpr FeatureGuard kFeatureGuards[] = {
132135
{"display.js", kHaveDisplayUdfBegin, kHaveDisplayUdfEnd},
133136
{"showfile.js", kHaveShowfileBegin, kHaveShowfileEnd},
134137
{"time", kHaveTimeBegin, kHaveTimeEnd},
135-
{"rtc", kHaveRtcBegin, kHaveRtcEnd}};
138+
{"rtc", kHaveRtcBegin, kHaveRtcEnd},
139+
{"upload", kHaveUploadBegin, kHaveUploadEnd}
140+
};
136141

137142
static FILE* file_content;
138143
static FILE* file_includes;

lib-remoteconfig/http/content/modern/config_artnet.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
window.artnet = {
22
init: async function(path, name) {
3-
const j = await getJSON(path);
4-
if (!j) return;
3+
const json = await getJSON(path);
4+
if (!json) return;
55

66
const suffixes = ["a", "b", "c", "d"].filter(function(suffix) {
7-
return j["protocol_port_" + suffix] !== undefined ||
8-
j["rdm_enable_port_" + suffix] !== undefined ||
9-
j["destination_ip_port_" + suffix] !== undefined;
7+
return json["protocol_port_" + suffix] !== undefined ||
8+
json["rdm_enable_port_" + suffix] !== undefined ||
9+
json["destination_ip_port_" + suffix] !== undefined;
1010
});
1111

12-
const card = document.createElement("div");
13-
card.className = "card";
12+
const div = document.createElement("div");
13+
div.className = "card";
1414

15-
card.innerHTML = `
15+
div.innerHTML = `
1616
<h2>${name}</h2>
1717
<form>
1818
<div class="row">
@@ -30,10 +30,10 @@ window.artnet = {
3030
</form>
3131
`;
3232

33-
const optionalRdmContainer = card.querySelector(".optional-rdm-container");
34-
const portsContainer = card.querySelector(".ports-container");
33+
const optionalRdmContainer = div.querySelector(".optional-rdm-container");
34+
const portsContainer = div.querySelector(".ports-container");
3535

36-
if (j.enable_rdm !== undefined) {
36+
if (json.enable_rdm !== undefined) {
3737
const row = document.createElement("div");
3838
row.className = "row checkbox";
3939

@@ -58,14 +58,14 @@ window.artnet = {
5858
portLabel.textContent = "Port " + suffix.toUpperCase();
5959
row.appendChild(portLabel);
6060

61-
if (j["protocol_port_" + suffix] !== undefined) {
61+
if (json["protocol_port_" + suffix] !== undefined) {
6262
const select = document.createElement("select");
6363
select.dataset.key = "protocol_port_" + suffix;
6464
select.innerHTML = "<option value='artnet'>artnet</option><option value='sacn'>sacn</option><option value='disabled'>disabled</option>";
6565
row.appendChild(select);
6666
}
6767

68-
if (j["rdm_enable_port_" + suffix] !== undefined) {
68+
if (json["rdm_enable_port_" + suffix] !== undefined) {
6969
const rdmLabel = document.createElement("label");
7070
rdmLabel.textContent = "RDM";
7171
rdmLabel.style.width = "auto";
@@ -79,7 +79,7 @@ window.artnet = {
7979
row.appendChild(rdmInput);
8080
}
8181

82-
if (j["destination_ip_port_" + suffix] !== undefined) {
82+
if (json["destination_ip_port_" + suffix] !== undefined) {
8383
const ipLabel = document.createElement("label");
8484
ipLabel.textContent = "Destination IP";
8585
ipLabel.style.width = "auto";
@@ -96,12 +96,12 @@ window.artnet = {
9696
portsContainer.appendChild(row);
9797
}
9898

99-
document.getElementById("modules").appendChild(card);
100-
card.querySelector("form").onsubmit = () => {
101-
saveDataKeyForm(path, card);
99+
document.getElementById("modules").appendChild(div);
100+
div.querySelector("form").onsubmit = () => {
101+
saveDataKeyForm(path, div);
102102
return false;
103103
};
104104

105-
fillDataKeys(card, j);
105+
fillDataKeys(div, json);
106106
}
107107
};

lib-remoteconfig/http/content/modern/config_dmxmonitor.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ window.dmxmonitor = {
55

66
const div = document.createElement("div");
77
div.className = "card";
8+
89
div.innerHTML = `
910
<h2>${name}</h2>
1011
<form accept-charset="utf-8">
@@ -37,10 +38,6 @@ window.dmxmonitor = {
3738
return false;
3839
};
3940

40-
fillDataKeys(div, {
41-
dmx_start_address: json.dmx_start_address || 1,
42-
dmx_max_channels: json.dmx_max_channels || 16,
43-
format: json.format || "dec"
44-
});
41+
fillDataKeys(div, json);
4542
}
4643
};

lib-remoteconfig/http/content/modern/config_dmxnode.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
window.dmxnode = {
22
init: async function(path, name) {
3-
const j = await getJSON(path);
4-
if (!j) return;
3+
const json = await getJSON(path);
4+
if (!json) return;
55

66
const suffixes = ["a", "b", "c", "d"].filter(function(suffix) {
7-
return j["label_port_" + suffix] !== undefined ||
8-
j["universe_port_" + suffix] !== undefined ||
9-
j["direction_port_" + suffix] !== undefined ||
10-
j["merge_mode_port_" + suffix] !== undefined;
7+
return json["label_port_" + suffix] !== undefined ||
8+
json["universe_port_" + suffix] !== undefined ||
9+
json["direction_port_" + suffix] !== undefined ||
10+
json["merge_mode_port_" + suffix] !== undefined;
1111
});
1212

13-
const card = document.createElement("div");
14-
card.className = "card";
13+
const div = document.createElement("div");
14+
div.className = "card";
1515

16-
card.innerHTML = `
16+
div.innerHTML = `
1717
<h2>${name}</h2>
1818
<form>
1919
<div class="row">
@@ -56,7 +56,7 @@ window.dmxnode = {
5656
label.textContent = "Port " + suffix.toUpperCase();
5757
row.appendChild(label);
5858

59-
if (j["label_port_" + suffix] !== undefined) {
59+
if (json["label_port_" + suffix] !== undefined) {
6060
const input = document.createElement("input");
6161
input.dataset.key = "label_port_" + suffix;
6262
input.maxLength = 18;
@@ -65,7 +65,7 @@ window.dmxnode = {
6565
row.appendChild(input);
6666
}
6767

68-
if (j["universe_port_" + suffix] !== undefined) {
68+
if (json["universe_port_" + suffix] !== undefined) {
6969
const input = document.createElement("input");
7070
input.dataset.key = "universe_port_" + suffix;
7171
input.type = "number";
@@ -74,14 +74,14 @@ window.dmxnode = {
7474
row.appendChild(input);
7575
}
7676

77-
if (j["direction_port_" + suffix] !== undefined) {
77+
if (json["direction_port_" + suffix] !== undefined) {
7878
const select = document.createElement("select");
7979
select.dataset.key = "direction_port_" + suffix;
8080
select.innerHTML = "<option value='output'>output</option><option value='input'>input</option><option value='disable'>disable</option>";
8181
row.appendChild(select);
8282
}
8383

84-
if (j["merge_mode_port_" + suffix] !== undefined) {
84+
if (json["merge_mode_port_" + suffix] !== undefined) {
8585
const select = document.createElement("select");
8686
select.dataset.key = "merge_mode_port_" + suffix;
8787
select.innerHTML = "<option value='htp'>htp</option><option value='ltp'>ltp</option>";
@@ -91,12 +91,12 @@ window.dmxnode = {
9191
portsContainer.appendChild(row);
9292
}
9393

94-
document.getElementById("modules").appendChild(card);
95-
card.querySelector("form").onsubmit = () => {
96-
saveDataKeyForm(path, card);
94+
document.getElementById("modules").appendChild(div);
95+
div.querySelector("form").onsubmit = () => {
96+
saveDataKeyForm(path, div);
9797
return false;
9898
};
9999

100-
fillDataKeys(card, j);
100+
fillDataKeys(div, json);
101101
}
102102
};

lib-remoteconfig/http/content/modern/config_dmxpca9685.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,12 @@ window.dmxpca9685 = {
6666
</form>
6767
`;
6868

69-
document.getElementById("modules").appendChild(card);
70-
card.querySelector("form").onsubmit = () => {
71-
saveDataKeyForm(path, card);
69+
document.getElementById("modules").appendChild(div);
70+
div.querySelector("form").onsubmit = () => {
71+
saveDataKeyForm(path, div);
7272
return false;
7373
};
7474

75-
fillDataKeys(div, {
76-
mode: json.mode ?? "led",
77-
channel_count: json.channel_count ?? 16,
78-
dmx_start_address: json.dmx_start_address ?? 1,
79-
led_pwm_frequency: json.led_pwm_frequency ?? 120,
80-
use_8bit: json.use_8bit ?? 0,
81-
led_output_invert: json.led_output_invert ?? 0,
82-
led_output_opendrain: json.led_output_opendrain ?? 0,
83-
servo_left_us: json.servo_left_us ?? 1000,
84-
servo_center_us: json.servo_center_us ?? 0,
85-
servo_right_us: json.servo_right_us ?? 2000
86-
});
75+
fillDataKeys(div, json);
8776
}
8877
};

lib-remoteconfig/http/content/modern/config_dmxpixel.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
window.dmxpixel = {
22
init: async function(path, name) {
3-
const j = await getJSON(path);
4-
if (!j) return;
3+
const json = await getJSON(path);
4+
if (!json) return;
55

6-
const ports = Object.keys(j).filter(k => k.startsWith("start_uni_port_"));
6+
const ports = Object.keys(json).filter(k => k.startsWith("start_uni_port_"));
77

88
const div = document.createElement("div");
99
div.className = "card";
10+
1011
div.innerHTML = `
1112
<h2>${name}</h2>
1213
<form>
@@ -65,6 +66,6 @@ window.dmxpixel = {
6566
return false;
6667
};
6768

68-
fillDataKeys(div, j);
69+
fillDataKeys(div, json);
6970
}
7071
};

lib-remoteconfig/http/content/modern/config_dmxsend.js

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,25 @@ window.dmxsend = {
3636
`;
3737

3838
document.getElementById("modules").appendChild(div);
39-
div.querySelector("form").onsubmit = () => {
40-
saveDataKeyForm(path, div, {
41-
beforePost: function(out, card) {
42-
const slotsField = card.querySelector("[data-key='slots_count']");
43-
if ((out.slots_count & 1) !== 0) {
44-
slotsField.setCustomValidity("Slots count must be even.");
45-
slotsField.reportValidity();
46-
return false;
47-
}
48-
return true;
49-
},
50-
afterLoad: function(card, data) {
51-
fillDataKeys(card, {
52-
break_time: data.break_time ?? 176,
53-
mab_time: data.mab_time ?? 12,
54-
refresh_rate: data.refresh_rate ?? 40,
55-
slots_count: data.slots_count ?? 512
56-
});
57-
}
58-
});
59-
return false;
60-
};
39+
div.querySelector("form").onsubmit = () => {
40+
saveDataKeyForm(path, div, {
41+
beforePost: function(out, card) {
42+
const slotsField = card.querySelector("[data-key='slots_count']");
43+
slotsField.setCustomValidity("");
6144

62-
fillDataKeys(div, {
63-
break_time: json.break_time ?? 176,
64-
mab_time: json.mab_time ?? 12,
65-
refresh_rate: json.refresh_rate ?? 40,
66-
slots_count: json.slots_count ?? 512
67-
});
45+
if ((out.slots_count & 1) !== 0) {
46+
slotsField.setCustomValidity("Slots count must be even.");
47+
slotsField.reportValidity();
48+
return false;
49+
}
50+
51+
return true;
52+
}
53+
});
54+
55+
return false;
56+
};
57+
58+
fillDataKeys(div, json);
6859
}
6960
};

lib-remoteconfig/http/content/modern/config_etc.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,10 @@ window.etc = {
4343

4444
document.getElementById("modules").appendChild(div);
4545
div.querySelector("form").onsubmit = () => {
46-
saveDataKeyForm(path, card);
46+
saveDataKeyForm(path, div);
4747
return false;
4848
};
4949

50-
fillDataKeys(div, {
51-
destination_ip: json.destination_ip ?? "0.0.0.0",
52-
destination_port: json.destination_port ?? 0,
53-
source_multicast_ip: json.source_multicast_ip ?? "0.0.0.0",
54-
source_port: json.source_port ?? 0,
55-
udp_terminator: json.udp_terminator ?? "None"
56-
});
50+
fillDataKeys(div, json);
5751
}
5852
};

lib-remoteconfig/http/content/modern/config_gps.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ window.gps = {
3939
return false;
4040
};
4141

42-
fillDataKeys(div, {
43-
module: json.module ?? "ATGM336H",
44-
enable: json.enable ?? 0,
45-
utc_offset: json.utc_offset ?? "00:00"
46-
});
42+
fillDataKeys(div, json);
4743
}
4844
};

0 commit comments

Comments
 (0)