From 1f2aba32277209a5b274853cf7fb9e90b16eaa6b Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Thu, 26 Sep 2024 20:48:59 -0700 Subject: [PATCH] www: make web interface work when there's no cam_disk.bin --- teslausb-www/html/cgi-bin/config.sh | 1 + teslausb-www/html/cgi-bin/status.sh | 4 ++-- teslausb-www/html/index.html | 36 +++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/teslausb-www/html/cgi-bin/config.sh b/teslausb-www/html/cgi-bin/config.sh index e4143fa4..21feb514 100755 --- a/teslausb-www/html/cgi-bin/config.sh +++ b/teslausb-www/html/cgi-bin/config.sh @@ -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)" diff --git a/teslausb-www/html/cgi-bin/status.sh b/teslausb-www/html/cgi-bin/status.sh index ae130657..fa981dbc 100755 --- a/teslausb-www/html/cgi-bin/status.sh +++ b/teslausb-www/html/cgi-bin/status.sh @@ -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 @@ -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", diff --git a/teslausb-www/html/index.html b/teslausb-www/html/index.html index e3d1cb13..a5ef130c 100755 --- a/teslausb-www/html/index.html +++ b/teslausb-www/html/index.html @@ -239,7 +239,9 @@ } /*hide music tab by default */ -.tablabel6 { +.tablabel5, +.tablabel6, +.tablabel7 { display: none; } @@ -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) { @@ -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; + } + + }}); }