310 lines
		
	
	
		
			9.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			310 lines
		
	
	
		
			9.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
<!DOCTYPE html>
 | 
						|
<html lang="en">
 | 
						|
<head>
 | 
						|
    <meta charset="UTF-8">
 | 
						|
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 | 
						|
    <title>Simple Downloader</title>
 | 
						|
    <style>
 | 
						|
        body {
 | 
						|
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
 | 
						|
            background-color: #1e1e1e;
 | 
						|
            color: #d4d4d4;
 | 
						|
            line-height: 1.6;
 | 
						|
            padding: 20px;
 | 
						|
            max-width: 900px;
 | 
						|
            margin: 0 auto;
 | 
						|
            box-sizing: border-box;
 | 
						|
        }
 | 
						|
        h1, h2 {
 | 
						|
            border-bottom: 1px solid #333;
 | 
						|
            padding-bottom: 10px;
 | 
						|
            word-wrap: break-word;
 | 
						|
        }
 | 
						|
        form {
 | 
						|
            margin-bottom: 20px;
 | 
						|
            display: flex;
 | 
						|
            flex-direction: column;
 | 
						|
        }
 | 
						|
        input[type="file"], input[type="submit"] {
 | 
						|
            background-color: #2d2d2d;
 | 
						|
            color: #d4d4d4;
 | 
						|
            padding: 8px 12px;
 | 
						|
            border-radius: 4px;
 | 
						|
            margin-bottom: 10px;
 | 
						|
            max-width: 100%;
 | 
						|
        }
 | 
						|
        input[type="submit"] {
 | 
						|
            cursor: pointer;
 | 
						|
            background-color: #4CAF50;
 | 
						|
            color: white;
 | 
						|
        }
 | 
						|
        input[type="submit"]:hover {
 | 
						|
            background-color: #45a049;
 | 
						|
        }
 | 
						|
        ul {
 | 
						|
            list-style-type: none;
 | 
						|
            padding: 0;
 | 
						|
            margin-bottom: 10px; 
 | 
						|
        }
 | 
						|
        li {
 | 
						|
            background-color: #2d2d2d;
 | 
						|
            margin-bottom: 10px;
 | 
						|
            padding: 10px;
 | 
						|
            border-radius: 4px;
 | 
						|
            word-wrap: break-word;
 | 
						|
        }
 | 
						|
        .job-title {
 | 
						|
            font-size: 1.1em;
 | 
						|
            font-weight: bold;
 | 
						|
            margin-bottom: 5px;
 | 
						|
        }
 | 
						|
        .job-title a {
 | 
						|
            color: #58a6ff;
 | 
						|
            text-decoration: none;
 | 
						|
        }
 | 
						|
        .job-title a:hover {
 | 
						|
            text-decoration: underline;
 | 
						|
        }
 | 
						|
        .job-info {
 | 
						|
            font-size: 0.9em;
 | 
						|
            color: #a0a0a0;
 | 
						|
        }
 | 
						|
        .progress-text {
 | 
						|
            display: inline-block;
 | 
						|
            width: 5em;
 | 
						|
        }
 | 
						|
        .paused {
 | 
						|
            color: #ffa500;
 | 
						|
        }
 | 
						|
        .speed-limit {
 | 
						|
            font-size: 1em;
 | 
						|
            color: #a0a0a0;
 | 
						|
            margin-top: 10px;
 | 
						|
        }
 | 
						|
        @media (max-width: 600px) {
 | 
						|
            body {
 | 
						|
                padding: 10px;
 | 
						|
            }
 | 
						|
            h1, h2 {
 | 
						|
                font-size: 1.5em;
 | 
						|
            }
 | 
						|
            input[type="file"], input[type="submit"] {
 | 
						|
                font-size: 16px;
 | 
						|
            }
 | 
						|
            input[type="submit"], #clear-completed {
 | 
						|
                font-size: 16px;
 | 
						|
            }
 | 
						|
        }
 | 
						|
        input[type="submit"], #clear-completed {
 | 
						|
            cursor: pointer;
 | 
						|
            color: white;
 | 
						|
            border: 1px solid #444;
 | 
						|
            padding: 8px 12px;
 | 
						|
            border-radius: 4px;
 | 
						|
            margin-bottom: 10px;
 | 
						|
            max-width: 100%;
 | 
						|
            width: 100%;
 | 
						|
        }
 | 
						|
        #clear-completed {
 | 
						|
            background-color: #f44336;
 | 
						|
        }
 | 
						|
        #clear-completed:hover {
 | 
						|
            background-color: #d32f2f;
 | 
						|
        }
 | 
						|
        /* New CSS for speed limit form */
 | 
						|
        .settings-section {
 | 
						|
            margin-top: 30px;
 | 
						|
        }
 | 
						|
        .speed-limit-form {
 | 
						|
            display: flex;
 | 
						|
            align-items: center;
 | 
						|
            justify-content: space-between;
 | 
						|
            gap: 10px;
 | 
						|
            margin-bottom: 20px;
 | 
						|
        }
 | 
						|
        .speed-limit-form .form-group {
 | 
						|
            display: flex;
 | 
						|
            align-items: center;
 | 
						|
            gap: 10px;
 | 
						|
        }
 | 
						|
        .speed-limit-form input[type="number"],
 | 
						|
        .speed-limit-form select,
 | 
						|
        .speed-limit-form button {
 | 
						|
            background-color: #2d2d2d;
 | 
						|
            color: #d4d4d4;
 | 
						|
            border: 1px solid #444;
 | 
						|
            padding: 8px 12px;
 | 
						|
            border-radius: 4px;
 | 
						|
        }
 | 
						|
        .speed-limit-form button {
 | 
						|
            cursor: pointer;
 | 
						|
            background-color: #4CAF50;
 | 
						|
            color: white;
 | 
						|
        }
 | 
						|
        .speed-limit-form button:hover {
 | 
						|
            background-color: #45a049;
 | 
						|
        }
 | 
						|
        .speed-limit-container {
 | 
						|
            display: flex;
 | 
						|
            align-items: center;
 | 
						|
            margin-bottom: 20px;
 | 
						|
            background-color: #2d2d2d;
 | 
						|
            padding: 8px 12px;
 | 
						|
            border-radius: 4px;
 | 
						|
        }
 | 
						|
        .speed-limit-container .form-group {
 | 
						|
            display: flex;
 | 
						|
            align-items: center;
 | 
						|
            gap: 10px;
 | 
						|
            width: 100%;
 | 
						|
        }
 | 
						|
        .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 button {
 | 
						|
            background-color: #2d2d2d;
 | 
						|
            color: #d4d4d4;
 | 
						|
            border: 1px solid #444;
 | 
						|
            padding: 8px 12px;
 | 
						|
            border-radius: 4px;
 | 
						|
            height: 40px;
 | 
						|
            box-sizing: border-box;
 | 
						|
        }
 | 
						|
        .speed-limit-container button {
 | 
						|
            cursor: pointer;
 | 
						|
            background-color: #4CAF50;
 | 
						|
            color: white;
 | 
						|
        }
 | 
						|
        .speed-limit-container button:hover {
 | 
						|
            background-color: #45a049;
 | 
						|
        }
 | 
						|
        .speed-limit-container .speed-limit {
 | 
						|
            color: #d4d4d4;
 | 
						|
            margin-left: auto;
 | 
						|
            display: flex;
 | 
						|
            align-items: center;
 | 
						|
        }
 | 
						|
        .speed-limit-container .speed-limit span {
 | 
						|
            margin-left: 5px;
 | 
						|
        }
 | 
						|
        .current-speed-limit {
 | 
						|
            color: #d4d4d4;
 | 
						|
            margin-top: 10px;
 | 
						|
        }
 | 
						|
    </style>
 | 
						|
</head>
 | 
						|
<body>
 | 
						|
    <h1>Simple Downloader</h1>
 | 
						|
    <form action="/upload" method="post" enctype="multipart/form-data">
 | 
						|
        <input type="file" name="files" accept=".drmd" multiple>
 | 
						|
        <input type="submit" value="Upload and Process">
 | 
						|
    </form>
 | 
						|
    <h2>Currently Running Jobs</h2>
 | 
						|
    <ul>
 | 
						|
        {{range $filename, $info := .Jobs}}
 | 
						|
            <li>
 | 
						|
                <div class="job-title">
 | 
						|
                    <a href="/progress?filename={{$filename}}">{{$filename}}</a>
 | 
						|
                </div>
 | 
						|
                <div class="job-info">
 | 
						|
                    Progress: <span class="progress-text">{{printf "%5.1f%%" $info.Percentage}}</span>
 | 
						|
                    Current file: {{$info.CurrentFile}}
 | 
						|
                    {{if $info.Paused}}
 | 
						|
                        <span class="paused">(Paused)</span>
 | 
						|
                    {{end}}
 | 
						|
                </div>
 | 
						|
            </li>
 | 
						|
        {{else}}
 | 
						|
            <li>No active jobs</li>
 | 
						|
        {{end}}
 | 
						|
    </ul>
 | 
						|
    <button id="clear-completed" onclick="clearCompleted()">Clear Completed Jobs</button>
 | 
						|
    
 | 
						|
    <div class="settings-section">
 | 
						|
        <h2>Settings</h2>
 | 
						|
        <div class="speed-limit-container">
 | 
						|
            <div class="form-group">
 | 
						|
                <label for="speedLimitValue">Speed Limit:</label>
 | 
						|
                <input type="number" id="speedLimitValue" name="speedLimitValue" min="0" step="0.01" required>
 | 
						|
                <select id="speedLimitUnit" name="speedLimitUnit">
 | 
						|
                    <option value="GBps">GBps</option>
 | 
						|
                    <option value="MBps" selected>MBps</option>
 | 
						|
                    <option value="KBps">KBps</option>
 | 
						|
                </select>
 | 
						|
                <button type="button" onclick="updateSpeedLimit(event)">Set Limit</button>
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
    </div>
 | 
						|
 | 
						|
    <script>
 | 
						|
        function clearCompleted() {
 | 
						|
            fetch('/clear-completed', { method: 'POST' })
 | 
						|
                .then(response => response.json())
 | 
						|
                .then(data => {
 | 
						|
                    if (data.success) {
 | 
						|
                        location.reload();
 | 
						|
                    } else {
 | 
						|
                        alert('Failed to clear completed jobs');
 | 
						|
                    }
 | 
						|
                });
 | 
						|
        }
 | 
						|
 | 
						|
        function updateSpeedLimit(event) {
 | 
						|
            event.preventDefault();
 | 
						|
 | 
						|
            const speedLimitValue = document.getElementById('speedLimitValue').value;
 | 
						|
            const speedLimitUnit = document.getElementById('speedLimitUnit').value;
 | 
						|
            const speedLimit = speedLimitValue === "0" ? "unlimited" : speedLimitValue + speedLimitUnit;
 | 
						|
 | 
						|
            if (!validateSpeedLimit(speedLimitValue)) {
 | 
						|
                alert('Please enter a valid speed limit.');
 | 
						|
                return;
 | 
						|
            }
 | 
						|
 | 
						|
            fetch('/set-speed-limit', {
 | 
						|
                method: 'POST',
 | 
						|
                headers: {
 | 
						|
                    'Content-Type': 'application/json',
 | 
						|
                },
 | 
						|
                body: JSON.stringify({ speedLimit }),
 | 
						|
            }).then(response => {
 | 
						|
                if (response.ok) {
 | 
						|
                    alert('Speed limit updated successfully');
 | 
						|
                    document.getElementById('currentSpeedLimit').textContent = speedLimit;
 | 
						|
                } else {
 | 
						|
                    alert('Failed to update speed limit');
 | 
						|
                }
 | 
						|
            });
 | 
						|
        }
 | 
						|
 | 
						|
        function validateSpeedLimit(value) {
 | 
						|
            const number = parseFloat(value);
 | 
						|
            return !isNaN(number) && number >= 0;
 | 
						|
        }
 | 
						|
 | 
						|
        document.addEventListener('DOMContentLoaded', function() {
 | 
						|
            const currentSpeedLimit = "{{if .GlobalSpeedLimit}}{{.GlobalSpeedLimit}}{{else}}0{{end}}";
 | 
						|
            const speedLimitValueInput = document.getElementById('speedLimitValue');
 | 
						|
            const speedLimitUnitSelect = document.getElementById('speedLimitUnit');
 | 
						|
 | 
						|
            const match = currentSpeedLimit.match(/(\d+(\.\d+)?)([A-Za-z]+)/);
 | 
						|
            if (match) {
 | 
						|
                speedLimitValueInput.value = match[1];
 | 
						|
                speedLimitUnitSelect.value = match[3];
 | 
						|
            } else {
 | 
						|
                speedLimitValueInput.value = "0"; 
 | 
						|
                speedLimitUnitSelect.value = "MBps";
 | 
						|
            }
 | 
						|
        });
 | 
						|
    </script>
 | 
						|
</body>
 | 
						|
</html>
 |