Skip to content

Commit

Permalink
www: make web interface work when there's no cam_disk.bin
Browse files Browse the repository at this point in the history
  • Loading branch information
marcone committed Oct 7, 2024
1 parent 429d7ef commit 1f2aba3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions teslausb-www/html/cgi-bin/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ HTTP/1.0 200 OK
Content-type: application/json
{
"has_cam" : "$(exists /backingfiles/cam_disk.bin)",
"has_music" : "$(exists /backingfiles/music_disk.bin)",
"has_lightshow" : "$(exists /backingfiles/lightshow_disk.bin)",
"has_boombox" : "$(exists /backingfiles/boombox_disk.bin)"
Expand Down
4 changes: 2 additions & 2 deletions teslausb-www/html/cgi-bin/status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ else
drives_active=no
fi

readarray -t snapshots <<<"$(find /backingfiles/snapshots/ -name snap.bin 2> /dev/null | sort)"
readarray -t snapshots < <(find /backingfiles/snapshots/ -name snap.bin 2> /dev/null | sort)
readonly numsnapshots=${#snapshots[@]}
if [[ "$numsnapshots" != "0" ]]
then
Expand Down Expand Up @@ -55,7 +55,7 @@ Content-type: application/json
"num_snapshots": "$numsnapshots",
"snapshot_oldest": "$oldestsnapshot",
"snapshot_newest": "$newestsnapshot",
$(eval "$(stat --file-system --format='echo -e \"total_space\": \"$((%b*%S))\",\\\n\ \ \ \"free_space\": \"$((%f*%S))\",' /backingfiles/cam_disk.bin)")
$(eval "$(stat --file-system --format='echo -e \"total_space\": \"$((%b*%S))\",\\\n\ \ \ \"free_space\": \"$((%f*%S))\",' /backingfiles/.)")
"uptime": "$ut",
"drives_active": "$drives_active",
"wifi_ssid": "$wifi_ssid",
Expand Down
36 changes: 34 additions & 2 deletions teslausb-www/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@
}

/*hide music tab by default */
.tablabel6 {
.tablabel5,
.tablabel6,
.tablabel7 {
display: none;
}

Expand Down Expand Up @@ -1211,12 +1213,28 @@
request.send();
}

function readyState(state) {
if (state == 0) {
return "UNSENT";
} else if (state == 1) {
return "OPENED";
} else if (state == 2) {
return "HEADERS_RECEIVED";
} else if (state == 3) {
return "LOADING";
} else if (state == 4) {
return "DONE";
} else {
return "UNKNOWN";
}
}

function readfile({url, callback, callbackarg, pre, tail, button}) {
var request = new XMLHttpRequest();
request.open('GET', cachebustingurl(url));
log("reading " + url);
request.onreadystatechange = function () {
log("read " + url + ", result: " + request.status);
log(`read ${url}, result: ${request.status}, state: ${readyState(request.readyState)}`);
if (request.readyState === 4 && request.status === 200) {
var type = request.getResponseHeader('Content-Type');
if (type.indexOf("text") !== 1) {
Expand Down Expand Up @@ -1630,6 +1648,20 @@
...config.has_boombox == "yes" ? [{ path: "fs/Boombox", label: "Boombox" }] : []
]);
}
if (config.has_cam == "yes") {
const recordingstab = document.querySelector(".tablabel5");
const viewertab = document.querySelector(".tablabel7");
recordingstab.style.display = "inline-block";
viewertab.style.display = "inline-block";
} else if (numdrives > 0) {
const filesbtn = document.querySelector("#tab6");
filesbtn.checked = true;
} else {
const toolsbtn = document.querySelector("#tab4");
toolsbtn.checked = true;
}


}});
}

Expand Down

0 comments on commit 1f2aba3

Please sign in to comment.