impl speed limit

This commit is contained in:
Joren 2024-12-30 16:32:12 +01:00
parent 457ede5b62
commit f1efb1d67c
Signed by: Joren
GPG Key ID: 280E33DFBC0F1B55
2 changed files with 26 additions and 7 deletions

View File

@ -5,9 +5,9 @@ TempBaseDir = "/tmp/nre"
EnableConsole = true EnableConsole = true
[WatchFolder] [WatchFolder]
Path = "/mnt/watched" Path = "/home/joren/dev/DRMDTool/folder"
PollingInterval = 10 PollingInterval = 10
UsePolling = false UsePolling = true
UseInotify = false UseInotify = false
[N_m3u8DLRE] [N_m3u8DLRE]

View File

@ -28,7 +28,6 @@
input[type="file"], input[type="submit"] { input[type="file"], input[type="submit"] {
background-color: #2d2d2d; background-color: #2d2d2d;
color: #d4d4d4; color: #d4d4d4;
border: 1px solid #444;
padding: 8px 12px; padding: 8px 12px;
border-radius: 4px; border-radius: 4px;
margin-bottom: 10px; margin-bottom: 10px;
@ -152,7 +151,6 @@
background-color: #2d2d2d; background-color: #2d2d2d;
padding: 8px 12px; padding: 8px 12px;
border-radius: 4px; border-radius: 4px;
border: 1px solid #444;
} }
.speed-limit-container .form-group { .speed-limit-container .form-group {
display: flex; display: flex;
@ -160,7 +158,16 @@
gap: 10px; gap: 10px;
width: 100%; width: 100%;
} }
.speed-limit-container input[type="number"], .speed-limit-container input[type="number"] {
background-color: #2d2d2d;
color: #d4d4d4;
border: 1px solid #444;
padding: 8px 12px;
border-radius: 4px;
height: 40px;
box-sizing: border-box;
flex-grow: 1;
}
.speed-limit-container select, .speed-limit-container select,
.speed-limit-container button { .speed-limit-container button {
background-color: #2d2d2d; background-color: #2d2d2d;
@ -225,14 +232,14 @@
<h2>Settings</h2> <h2>Settings</h2>
<div class="speed-limit-container"> <div class="speed-limit-container">
<div class="form-group"> <div class="form-group">
<label for="speedLimitValue">Global Speed Limit:</label> <label for="speedLimitValue">Speed Limit:</label>
<input type="number" id="speedLimitValue" name="speedLimitValue" min="0" step="0.01" required> <input type="number" id="speedLimitValue" name="speedLimitValue" min="0" step="0.01" required>
<select id="speedLimitUnit" name="speedLimitUnit"> <select id="speedLimitUnit" name="speedLimitUnit">
<option value="GBps">GBps</option> <option value="GBps">GBps</option>
<option value="MBps" selected>MBps</option> <option value="MBps" selected>MBps</option>
<option value="KBps">KBps</option> <option value="KBps">KBps</option>
</select> </select>
<button type="button" onclick="updateSpeedLimit(event)">Set Speed Limit</button> <button type="button" onclick="updateSpeedLimit(event)">Set Limit</button>
</div> </div>
</div> </div>
</div> </div>
@ -249,6 +256,7 @@
} }
}); });
} }
function updateSpeedLimit(event) { function updateSpeedLimit(event) {
event.preventDefault(); event.preventDefault();
@ -256,6 +264,11 @@
const speedLimitUnit = document.getElementById('speedLimitUnit').value; const speedLimitUnit = document.getElementById('speedLimitUnit').value;
const speedLimit = speedLimitValue === "0" ? "unlimited" : speedLimitValue + speedLimitUnit; const speedLimit = speedLimitValue === "0" ? "unlimited" : speedLimitValue + speedLimitUnit;
if (!validateSpeedLimit(speedLimitValue)) {
alert('Please enter a valid speed limit.');
return;
}
fetch('/set-speed-limit', { fetch('/set-speed-limit', {
method: 'POST', method: 'POST',
headers: { headers: {
@ -271,6 +284,12 @@
} }
}); });
} }
function validateSpeedLimit(value) {
const number = parseFloat(value);
return !isNaN(number) && number >= 0;
}
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
const currentSpeedLimit = "{{if .GlobalSpeedLimit}}{{.GlobalSpeedLimit}}{{else}}0{{end}}"; const currentSpeedLimit = "{{if .GlobalSpeedLimit}}{{.GlobalSpeedLimit}}{{else}}0{{end}}";
const speedLimitValueInput = document.getElementById('speedLimitValue'); const speedLimitValueInput = document.getElementById('speedLimitValue');