mirror of
https://github.com/Retropex/custom-ocean.xyz-dashboard.git
synced 2025-05-12 11:10:44 +02:00
Adding project files via Upload
This commit is contained in:
commit
3fcbdce9af
563
boot.html
Normal file
563
boot.html
Normal file
@ -0,0 +1,563 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Ocean.xyz Pool Miner - Initializing...</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=VT323&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
/* Base Styles with a subtle radial background for extra depth */
|
||||
body {
|
||||
background: linear-gradient(135deg, #121212, #000000);
|
||||
color: #f7931a;
|
||||
font-family: 'VT323', monospace;
|
||||
font-size: 16px;
|
||||
line-height: 1.4;
|
||||
margin: 0;
|
||||
padding: 10px;
|
||||
overflow-x: hidden;
|
||||
text-shadow: 0 0 5px rgba(247, 147, 26, 0.4);
|
||||
height: calc(100vh - 100px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
/* CRT Screen Effect */
|
||||
body::before {
|
||||
content: " ";
|
||||
display: block;
|
||||
position: fixed;
|
||||
top: 0; left: 0; bottom: 0; right: 0;
|
||||
background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.1) 50%),
|
||||
linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.03));
|
||||
background-size: 100% 2px, 3px 100%;
|
||||
pointer-events: none;
|
||||
z-index: 2;
|
||||
opacity: 0.15;
|
||||
}
|
||||
/* Flicker Animation */
|
||||
@keyframes flicker {
|
||||
0% { opacity: 0.97; }
|
||||
5% { opacity: 0.95; }
|
||||
10% { opacity: 0.97; }
|
||||
15% { opacity: 0.94; }
|
||||
20% { opacity: 0.98; }
|
||||
50% { opacity: 0.95; }
|
||||
80% { opacity: 0.96; }
|
||||
90% { opacity: 0.94; }
|
||||
100% { opacity: 0.98; }
|
||||
}
|
||||
/* Terminal Window with scrolling enabled */
|
||||
#terminal {
|
||||
width: 100%;
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
animation: flicker 4s infinite;
|
||||
height: 400px;
|
||||
overflow-y: auto;
|
||||
position: relative;
|
||||
flex: 1;
|
||||
}
|
||||
#terminal-content {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
}
|
||||
.cursor {
|
||||
display: inline-block;
|
||||
width: 10px;
|
||||
height: 16px;
|
||||
background-color: #f7931a;
|
||||
animation: blink 1s step-end infinite;
|
||||
vertical-align: middle;
|
||||
box-shadow: 0 0 5px rgba(247, 147, 26, 0.8);
|
||||
}
|
||||
@keyframes blink {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0; }
|
||||
}
|
||||
/* Neon-inspired color classes */
|
||||
.green {
|
||||
color: #39ff14 !important;
|
||||
text-shadow: 0 0 10px #39ff14, 0 0 20px #39ff14;
|
||||
}
|
||||
.blue {
|
||||
color: #00dfff !important;
|
||||
text-shadow: 0 0 10px #00dfff, 0 0 20px #00dfff;
|
||||
}
|
||||
.yellow {
|
||||
color: #ffd700 !important;
|
||||
text-shadow: 0 0 8px #ffd700, 0 0 16px #ffd700;
|
||||
}
|
||||
.white {
|
||||
color: #ffffff !important;
|
||||
text-shadow: 0 0 8px #ffffff, 0 0 16px #ffffff;
|
||||
}
|
||||
.red {
|
||||
color: #ff2d2d !important;
|
||||
text-shadow: 0 0 10px #ff2d2d, 0 0 20px #ff2d2d;
|
||||
}
|
||||
.magenta {
|
||||
color: #ff2d95 !important;
|
||||
text-shadow: 0 0 10px #ff2d95, 0 0 20px #ff2d95;
|
||||
}
|
||||
/* Bitcoin Logo styling with extra neon border */
|
||||
#bitcoin-logo {
|
||||
display: block;
|
||||
visibility: hidden;
|
||||
text-align: center;
|
||||
margin: 10px auto;
|
||||
font-size: 16px;
|
||||
line-height: 1;
|
||||
color: #f7931a;
|
||||
text-shadow: 0 0 10px rgba(247, 147, 26, 0.8);
|
||||
white-space: pre;
|
||||
width: 450px;
|
||||
padding: 15px;
|
||||
border: 2px solid #f7931a;
|
||||
background-color: #0a0a0a;
|
||||
box-shadow: 0 0 15px rgba(247, 147, 26, 0.5);
|
||||
font-family: monospace;
|
||||
opacity: 0;
|
||||
transition: opacity 1s ease;
|
||||
}
|
||||
/* Skip Button */
|
||||
#skip-button {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
background-color: #f7931a;
|
||||
color: #000;
|
||||
border: none;
|
||||
padding: 10px 15px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-family: 'VT323', monospace;
|
||||
font-size: 16px;
|
||||
box-shadow: 0 0 8px rgba(247, 147, 26, 0.5);
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
#skip-button:hover {
|
||||
background-color: #ffa32e;
|
||||
box-shadow: 0 0 12px rgba(247, 147, 26, 0.7);
|
||||
}
|
||||
/* Prompt Styling */
|
||||
#prompt-container {
|
||||
display: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
#prompt-text {
|
||||
color: #f7931a;
|
||||
margin-right: 5px;
|
||||
text-shadow: 0 0 5px rgba(247, 147, 26, 0.8);
|
||||
display: inline;
|
||||
}
|
||||
#user-input {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: #f7931a;
|
||||
font-family: 'VT323', monospace;
|
||||
font-size: 16px;
|
||||
caret-color: transparent;
|
||||
outline: none;
|
||||
width: 20px;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
text-shadow: 0 0 5px rgba(247, 147, 26, 0.8);
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
}
|
||||
.prompt-cursor {
|
||||
display: inline-block;
|
||||
width: 10px;
|
||||
height: 16px;
|
||||
background-color: #f7931a;
|
||||
animation: blink 1s step-end infinite;
|
||||
vertical-align: middle;
|
||||
box-shadow: 0 0 5px rgba(247, 147, 26, 0.8);
|
||||
position: relative;
|
||||
top: 1px;
|
||||
margin-left: -2px;
|
||||
}
|
||||
/* Mobile Responsiveness */
|
||||
@media (max-width: 600px) {
|
||||
body { font-size: 14px; padding: 10px; }
|
||||
#terminal { margin: 0; }
|
||||
}
|
||||
/* Loading and Debug Info */
|
||||
#loading-message {
|
||||
text-align: center;
|
||||
margin-bottom: 10px;
|
||||
text-shadow: 0 0 5px rgba(247, 147, 26, 0.8);
|
||||
}
|
||||
#debug-info {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
color: #666;
|
||||
font-size: 12px;
|
||||
z-index: 100;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<button id="skip-button">SKIP</button>
|
||||
<div id="debug-info"></div>
|
||||
<div id="loading-message">Loading mining data...</div>
|
||||
<div id="bitcoin-logo">
|
||||
██████╗ ████████╗ ██████╗ ██████╗ ███████╗
|
||||
██╔══██╗╚══██╔══╝██╔════╝ ██╔═══██╗██╔════╝
|
||||
██████╔╝ ██║ ██║ ██║ ██║███████╗
|
||||
██╔══██╗ ██║ ██║ ██║ ██║╚════██║
|
||||
██████╔╝ ██║ ╚██████╗ ╚██████╔╝███████║
|
||||
╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝
|
||||
v.21
|
||||
</div>
|
||||
<div id="terminal">
|
||||
<div id="terminal-content">
|
||||
<span id="output"></span><span class="cursor"></span>
|
||||
<span id="prompt-container">
|
||||
<span id="prompt-text">Initialize mining dashboard? [Y/N]:
|
||||
<span class="prompt-cursor"></span>
|
||||
<input type="text" id="user-input" maxlength="1" autocomplete="off" spellcheck="false" autofocus style="font-size: 16px; font-weight: bold;">
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Debug logging
|
||||
function updateDebug(message) {
|
||||
document.getElementById('debug-info').textContent = message;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// Format numbers with commas
|
||||
function numberWithCommas(x) {
|
||||
if (x == null) return "N/A";
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
}
|
||||
|
||||
// Global variables
|
||||
let bootMessages = [];
|
||||
let dashboardData = null;
|
||||
let outputElement = document.getElementById('output');
|
||||
const bitcoinLogo = document.getElementById('bitcoin-logo');
|
||||
const skipButton = document.getElementById('skip-button');
|
||||
const loadingMessage = document.getElementById('loading-message');
|
||||
const promptContainer = document.getElementById('prompt-container');
|
||||
const userInput = document.getElementById('user-input');
|
||||
let messageIndex = 0;
|
||||
let timeoutId = null;
|
||||
let waitingForUserInput = false;
|
||||
let bootComplete = false;
|
||||
|
||||
// Safety timeout: redirect after 60 seconds if boot not complete
|
||||
window.addEventListener('load', function() {
|
||||
setTimeout(function() {
|
||||
if (!bootComplete && !waitingForUserInput) {
|
||||
console.warn("Safety timeout reached - redirecting to dashboard");
|
||||
redirectToDashboard();
|
||||
}
|
||||
}, 60000);
|
||||
});
|
||||
|
||||
// Redirect to dashboard
|
||||
function redirectToDashboard() {
|
||||
updateDebug("Boot sequence complete, redirecting...");
|
||||
const baseUrl = window.location.origin;
|
||||
window.location.href = baseUrl + "/dashboard";
|
||||
}
|
||||
|
||||
// Fade in Bitcoin logo
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
setTimeout(function() {
|
||||
bitcoinLogo.style.visibility = 'visible';
|
||||
setTimeout(function() {
|
||||
bitcoinLogo.style.opacity = '1';
|
||||
}, 100);
|
||||
}, 500);
|
||||
});
|
||||
|
||||
// Post-confirmation messages with retro typing effect
|
||||
function showPostConfirmationMessages(response) {
|
||||
try {
|
||||
outputElement = document.getElementById('output');
|
||||
if (!outputElement) {
|
||||
setTimeout(redirectToDashboard, 1000);
|
||||
return;
|
||||
}
|
||||
const yesMessages = [
|
||||
{ text: "INITIALIZING DASHBOARD...\n", html: true, delay: 400 },
|
||||
{ text: "Connecting to real-time data feeds...", speed: 20, delay: 300 },
|
||||
{ text: "<span class='green'>CONNECTED</span>\n", html: true, delay: 400 },
|
||||
{ text: "Loading blockchain validators...", speed: 15, delay: 300 },
|
||||
{ text: "<span class='green'>COMPLETE</span>\n", html: true, delay: 400 },
|
||||
{ text: "Starting TX fee calculation module...", speed: 15, delay: 400 },
|
||||
{ text: "<span class='green'>ACTIVE</span>\n", html: true, delay: 400 },
|
||||
{ text: "Verifying BTC-USD exchange rates...", speed: 15, delay: 200 },
|
||||
{ text: "<span class='green'>CURRENT RATE CONFIRMED</span>\n", html: true, delay: 300 },
|
||||
{ text: "Calibrating hashrate telemetry...", speed: 15, delay: 200 },
|
||||
{ text: "<span class='green'>CALIBRATED</span>\n", html: true, delay: 200 },
|
||||
{ text: "Loading historical mining data: [", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>████</span>", html: true, delay: 100 },
|
||||
{ text: "<span class='green'>████████</span>", html: true, delay: 100 },
|
||||
{ text: "<span class='green'>███████</span>", html: true, delay: 100 },
|
||||
{ text: "<span class='green'>████</span>", html: true, delay: 100 },
|
||||
{ text: "<span class='green'>██</span>", html: true, delay: 100 },
|
||||
{ text: "<span class='green'>█</span>", html: true, delay: 100 },
|
||||
{ text: "] <span class='green'>COMPLETE</span>\n", html: true, delay: 400 },
|
||||
{ text: "Block reward calculation initialized...", speed: 15, delay: 300 },
|
||||
{ text: "<span class='yellow'>HALVING SCHEDULE VERIFIED</span>\n", html: true, delay: 400 },
|
||||
{ text: "Satoshi per kWh optimizer: <span class='green'>ENGAGED</span>\n", html: true, delay: 500 },
|
||||
{ text: "Launching mining dashboard in 3...", speed: 80, delay: 1000 },
|
||||
{ text: " 2...", speed: 80, delay: 1000 },
|
||||
{ text: " 1...\n", speed: 80, delay: 1000 },
|
||||
{ text: "<span class='green'>STACK SATS MODE: ACTIVATED</span>\n", html: true, delay: 500 }
|
||||
];
|
||||
const noMessages = [
|
||||
{ text: "DASHBOARD INITIALIZATION ABORTED.\n", html: true, delay: 400 },
|
||||
{ text: "Mining processes will continue in background.\n", speed: 30, delay: 500 },
|
||||
{ text: "Attempting emergency recovery...\n", speed: 30, delay: 1000 },
|
||||
{ text: "Bypassing authentication checks...", speed: 20, delay: 300 },
|
||||
{ text: "<span class='green'>SUCCESS</span>\n", html: true, delay: 500 },
|
||||
{ text: "Initializing fallback ASIC control interface...", speed: 20, delay: 300 },
|
||||
{ text: "<span class='green'>ACTIVE</span>\n", html: true, delay: 400 },
|
||||
{ text: "<span class='green'>RECOVERY SUCCESSFUL!</span>\n", html: true, delay: 400 },
|
||||
{ text: "Loading minimal dashboard in safe mode: [", speed: 15, delay: 100 },
|
||||
{ text: "<span class='yellow'>████████</span>", html: true, delay: 100 },
|
||||
{ text: "<span class='yellow'>████████</span>", html: true, delay: 100 },
|
||||
{ text: "<span class='yellow'>████████</span>", html: true, delay: 100 },
|
||||
{ text: "] <span class='white'>READY</span>\n", html: true, delay: 400 },
|
||||
{ text: "\nNOTE: REDUCED FUNCTIONALITY IN SAFE MODE\n", html: true, delay: 500 },
|
||||
{ text: "Launching minimal dashboard in 3...", speed: 80, delay: 1000 },
|
||||
{ text: " 2...", speed: 80, delay: 1000 },
|
||||
{ text: " 1...\n", speed: 80, delay: 1000 },
|
||||
{ text: "<span class='green'>BITCOIN MINING CONTINUES REGARDLESS! ;)</span>\n", html: true, delay: 500 }
|
||||
];
|
||||
const messages = response === 'Y' ? yesMessages : noMessages;
|
||||
let msgIndex = 0;
|
||||
function processNextMessage() {
|
||||
if (msgIndex >= messages.length) {
|
||||
bootComplete = true;
|
||||
setTimeout(redirectToDashboard, 500);
|
||||
return;
|
||||
}
|
||||
const currentMessage = messages[msgIndex];
|
||||
if (currentMessage.html) {
|
||||
outputElement.innerHTML += currentMessage.text;
|
||||
msgIndex++;
|
||||
setTimeout(processNextMessage, currentMessage.delay || 300);
|
||||
} else {
|
||||
let charIndex = 0;
|
||||
function typeCharacter() {
|
||||
if (charIndex < currentMessage.text.length) {
|
||||
outputElement.innerHTML += currentMessage.text.charAt(charIndex);
|
||||
charIndex++;
|
||||
setTimeout(typeCharacter, currentMessage.speed || 20);
|
||||
} else {
|
||||
msgIndex++;
|
||||
setTimeout(processNextMessage, currentMessage.delay || 300);
|
||||
}
|
||||
}
|
||||
typeCharacter();
|
||||
}
|
||||
}
|
||||
setTimeout(processNextMessage, 500);
|
||||
} catch(err) {
|
||||
setTimeout(redirectToDashboard, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Y/N prompt input
|
||||
userInput.addEventListener('keydown', function(e) {
|
||||
if (waitingForUserInput && e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
const response = userInput.value.toUpperCase();
|
||||
promptContainer.style.display = 'none';
|
||||
waitingForUserInput = false;
|
||||
outputElement.innerHTML += response + "\n";
|
||||
userInput.value = '';
|
||||
showPostConfirmationMessages(response);
|
||||
}
|
||||
});
|
||||
|
||||
// Show the prompt
|
||||
function showUserPrompt() {
|
||||
promptContainer.style.display = 'inline';
|
||||
waitingForUserInput = true;
|
||||
document.querySelector('.cursor').style.display = 'none';
|
||||
userInput.focus();
|
||||
}
|
||||
|
||||
// We disable truncation so all text is visible.
|
||||
function manageTerminalContent() { }
|
||||
|
||||
// Retro typing effect for boot messages
|
||||
function typeBootMessages() {
|
||||
try {
|
||||
if (!outputElement) {
|
||||
outputElement = document.getElementById('output');
|
||||
if (!outputElement) {
|
||||
skipButton.click();
|
||||
return;
|
||||
}
|
||||
}
|
||||
console.log("Processing boot message index:", messageIndex);
|
||||
if (messageIndex >= bootMessages.length) { return; }
|
||||
const currentMessage = bootMessages[messageIndex];
|
||||
if (currentMessage.showPrompt) {
|
||||
messageIndex++;
|
||||
showUserPrompt();
|
||||
return;
|
||||
}
|
||||
if (currentMessage.html) {
|
||||
outputElement.innerHTML += currentMessage.text;
|
||||
messageIndex++;
|
||||
timeoutId = setTimeout(typeBootMessages, currentMessage.delay || 300);
|
||||
return;
|
||||
}
|
||||
if (!currentMessage.typingIndex) { currentMessage.typingIndex = 0; }
|
||||
if (currentMessage.typingIndex < currentMessage.text.length) {
|
||||
outputElement.innerHTML += currentMessage.text.charAt(currentMessage.typingIndex);
|
||||
currentMessage.typingIndex++;
|
||||
timeoutId = setTimeout(typeBootMessages, currentMessage.speed || 15);
|
||||
} else {
|
||||
messageIndex++;
|
||||
timeoutId = setTimeout(typeBootMessages, currentMessage.delay || 300);
|
||||
}
|
||||
} catch(err) {
|
||||
messageIndex++;
|
||||
timeoutId = setTimeout(typeBootMessages, 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Skip button: immediately redirect
|
||||
skipButton.addEventListener('click', function() {
|
||||
clearTimeout(timeoutId);
|
||||
redirectToDashboard();
|
||||
});
|
||||
|
||||
// Start the typing animation (hides loading message)
|
||||
function startTyping() {
|
||||
loadingMessage.style.display = 'none';
|
||||
setTimeout(typeBootMessages, 150);
|
||||
}
|
||||
|
||||
// Fallback messages (used immediately)
|
||||
function setupFallbackMessages() {
|
||||
bootMessages = [
|
||||
{ text: "BITCOIN MINING SYSTEM v21.000.000\n", speed: 25, delay: 300 },
|
||||
{ text: "Copyright (c) 2009-2025 Satoshi Nakamoto\n", speed: 20, delay: 250 },
|
||||
{ text: "All rights reserved.\n\n", speed: 25, delay: 300 },
|
||||
{ text: "INITIALIZING SYSTEM...\n", speed: 25, delay: 300 },
|
||||
{ text: "HARDWARE: ", speed: 25, delay: 100 },
|
||||
{ text: "<span class='green'>OK</span>\n", html: true, delay: 300 },
|
||||
{ text: "NETWORK: ", speed: 25, delay: 100 },
|
||||
{ text: "<span class='green'>OK</span>\n", html: true, delay: 300 },
|
||||
{ text: "BLOCKCHAIN: ", speed: 25, delay: 100 },
|
||||
{ text: "<span class='green'>SYNCHRONIZED</span>\n", html: true, delay: 300 },
|
||||
{ text: "MINING RIG: ", speed: 25, delay: 100 },
|
||||
{ text: "<span class='green'>ONLINE</span>\n", html: true, delay: 300 },
|
||||
{ text: "\nSystem ready. ", speed: 25, delay: 400 },
|
||||
{ showPrompt: true, delay: 0 }
|
||||
];
|
||||
startTyping();
|
||||
}
|
||||
|
||||
// Initialize with fallback, then try live data
|
||||
setupFallbackMessages();
|
||||
updateDebug("Fetching dashboard data...");
|
||||
fetch('/api/metrics')
|
||||
.then(response => {
|
||||
if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); }
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
dashboardData = data;
|
||||
clearTimeout(timeoutId);
|
||||
messageIndex = 0;
|
||||
outputElement = document.getElementById('output');
|
||||
outputElement.innerHTML = "";
|
||||
bootMessages = [
|
||||
{ text: "BITCOIN MINING CONTROL SYSTEM v21.000.000\n", speed: 25, delay: 300 },
|
||||
{ text: "Copyright (c) 2009-2025 Satoshi Nakamoto & The Bitcoin Core Developers\n", speed: 20, delay: 250 },
|
||||
{ text: "All rights reserved.\n\n", speed: 25, delay: 300 },
|
||||
{ text: "INITIALIZING SHA-256 MINING SUBSYSTEMS...\n", speed: 25, delay: 400 },
|
||||
{ text: "ASIC CLUSTER STATUS: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>ONLINE</span>\n", html: true, delay: 300 },
|
||||
{ text: "CHIP TEMPERATURE: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>62°C - WITHIN OPTIMAL RANGE</span>\n", html: true, delay: 300 },
|
||||
{ text: "COOLING SYSTEMS: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>OPERATIONAL</span>\n", html: true, delay: 300 },
|
||||
{ text: "POWER SUPPLY HEALTH: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>98.7% - NOMINAL</span>\n", html: true, delay: 300 },
|
||||
{ text: "\nCONNECTING TO BITCOIN NETWORK...\n", speed: 20, delay: 400 },
|
||||
{ text: "BLOCKCHAIN SYNC STATUS: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>SYNCHRONIZED</span>\n", html: true, delay: 300 },
|
||||
{ text: "DIFFICULTY ADJUSTMENT: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='yellow'>CALCULATED</span>\n", html: true, delay: 300 },
|
||||
{ text: "MEMPOOL MONITORING: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>ACTIVE</span>\n", html: true, delay: 300 },
|
||||
{ text: "\nESTABLISHING POOL CONNECTION...\n", speed: 20, delay: 300 },
|
||||
{ text: "CONNECTING TO OCEAN.XYZ...\n", speed: 20, delay: 300 },
|
||||
{ text: "STRATUM PROTOCOL v2: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>INITIALIZED</span>\n", html: true, delay: 300 },
|
||||
{ text: "POOL HASHRATE: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>VERIFIED</span>\n", html: true, delay: 300 },
|
||||
{ text: "WORKER AUTHENTICATION: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>SUCCESSFUL</span>\n", html: true, delay: 300 },
|
||||
{ text: "\nINITIALIZING METRICS COLLECTORS...\n", speed: 20, delay: 300 },
|
||||
{ text: "HASHRATE MONITOR: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>ACTIVE</span>\n", html: true, delay: 300 },
|
||||
{ text: "EARNINGS CALCULATOR: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>CALIBRATED</span>\n", html: true, delay: 300 },
|
||||
{ text: "POWER USAGE TRACKING: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>ENABLED</span>\n", html: true, delay: 300 },
|
||||
{ text: "PAYOUT THRESHOLD MONITOR: ", speed: 15, delay: 100 },
|
||||
{ text: "<span class='green'>ACTIVE</span>\n", html: true, delay: 300 },
|
||||
{ text: "\nCURRENT NETWORK METRICS DETECTED\n", speed: 20, delay: 300 },
|
||||
{ text: "BTC PRICE: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='yellow'>$" + numberWithCommas((data.btc_price || 0).toFixed(2)) + "</span>\n", html: true, delay: 300 },
|
||||
{ text: "NETWORK DIFFICULTY: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='white'>" + numberWithCommas(Math.round(data.difficulty || 0)) + "</span>\n", html: true, delay: 300 },
|
||||
{ text: "NETWORK HASHRATE: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='white'>" + (data.network_hashrate ? numberWithCommas(Math.round(data.network_hashrate)) : "N/A") + " EH/s</span>\n", html: true, delay: 300 },
|
||||
{ text: "BLOCK HEIGHT: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='white'>" + numberWithCommas(data.block_number || "N/A") + "</span>\n", html: true, delay: 300 },
|
||||
{ text: "\nMINER PERFORMANCE DATA\n", speed: 20, delay: 300 },
|
||||
{ text: "CURRENT HASHRATE: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='yellow'>" + (data.hashrate_60sec || "N/A") + " " + (data.hashrate_60sec_unit || "TH/s") + "</span>\n", html: true, delay: 300 },
|
||||
{ text: "24HR AVG HASHRATE: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='yellow'>" + (data.hashrate_24hr || "N/A") + " " + (data.hashrate_24hr_unit || "TH/s") + "</span>\n", html: true, delay: 300 },
|
||||
{ text: "ACTIVE WORKERS: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='yellow'>" + (data.workers_hashing || "0") + "</span>\n", html: true, delay: 300 },
|
||||
{ text: "\nFINANCIAL CALCULATIONS\n", speed: 20, delay: 300 },
|
||||
{ text: "DAILY MINING REVENUE: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='green'>$" + numberWithCommas((data.daily_revenue || 0).toFixed(2)) + "</span>\n", html: true, delay: 300 },
|
||||
{ text: "DAILY POWER COST: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='red'>$" + numberWithCommas((data.daily_power_cost || 0).toFixed(2)) + "</span>\n", html: true, delay: 300 },
|
||||
{ text: "DAILY PROFIT: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='green'>$" + numberWithCommas((data.daily_profit_usd || 0).toFixed(2)) + "</span>\n", html: true, delay: 300 },
|
||||
{ text: "PROJECTED MONTHLY PROFIT: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='green'>$" + numberWithCommas((data.monthly_profit_usd || 0).toFixed(2)) + "</span>\n", html: true, delay: 300 },
|
||||
{ text: "DAILY SATOSHI YIELD: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='yellow'>" + numberWithCommas(data.daily_mined_sats || 0) + " sats</span>\n", html: true, delay: 300 },
|
||||
{ text: "UNPAID EARNINGS: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='green'>" + (data.unpaid_earnings || "0") + " BTC</span>\n", html: true, delay: 300 },
|
||||
{ text: "ESTIMATED TIME TO PAYOUT: ", speed: 20, delay: 100 },
|
||||
{ text: "<span class='yellow'>" + (data.est_time_to_payout || "Unknown") + "</span>\n", html: true, delay: 300 },
|
||||
{ text: "\n", speed: 25, delay: 100 },
|
||||
{ text: "<span class='green'>ALL MINING PROCESSES OPERATIONAL</span>\n", html: true, delay: 400 },
|
||||
{ text: "\nInitialize mining dashboard? ", speed: 25, delay: 400 },
|
||||
{ showPrompt: true, delay: 0 }
|
||||
];
|
||||
startTyping();
|
||||
})
|
||||
.catch(error => {
|
||||
updateDebug(`Error fetching dashboard data: ${error.message}`);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
55
dockerfile
Normal file
55
dockerfile
Normal file
@ -0,0 +1,55 @@
|
||||
FROM python:3.9-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install curl for healthcheck and other dependencies
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends curl && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install dependencies first to leverage Docker cache.
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy the entire application.
|
||||
COPY . .
|
||||
|
||||
# Run the minifier to process HTML templates.
|
||||
RUN python minify.py
|
||||
|
||||
# Create a non-root user first.
|
||||
RUN adduser --disabled-password --gecos '' appuser
|
||||
|
||||
# Change ownership of the /app directory so that appuser can write files.
|
||||
RUN chown -R appuser:appuser /app
|
||||
|
||||
# Create a directory for logs with proper permissions
|
||||
RUN mkdir -p /app/logs && chown -R appuser:appuser /app/logs
|
||||
|
||||
USER appuser
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
# Add environment variables for app configuration
|
||||
ENV FLASK_ENV=production
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
ENV PYTHON_UNBUFFERED=1
|
||||
|
||||
# Improve healthcheck reliability - use new health endpoint
|
||||
HEALTHCHECK --interval=15s --timeout=5s --start-period=30s --retries=3 \
|
||||
CMD curl -f http://localhost:5000/api/health || exit 1
|
||||
|
||||
# Use Gunicorn as the production WSGI server with improved settings
|
||||
# For shared global state, we need to keep the single worker model but optimize other parameters
|
||||
CMD ["gunicorn", "-b", "0.0.0.0:5000", "App:app", \
|
||||
"--workers=1", \
|
||||
"--threads=12", \
|
||||
"--timeout=600", \
|
||||
"--keep-alive=5", \
|
||||
"--log-level=info", \
|
||||
"--access-logfile=-", \
|
||||
"--error-logfile=-", \
|
||||
"--log-file=-", \
|
||||
"--graceful-timeout=60", \
|
||||
"--worker-tmp-dir=/dev/shm"]
|
58
dockerfile.txt
Normal file
58
dockerfile.txt
Normal file
@ -0,0 +1,58 @@
|
||||
FROM python:3.9-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install curl for healthcheck and other dependencies
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends curl && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install dependencies first to leverage Docker cache.
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy the entire application.
|
||||
COPY . .
|
||||
|
||||
# Run the minifier to process HTML templates.
|
||||
RUN python minify.py
|
||||
|
||||
# Create a non-root user first.
|
||||
RUN adduser --disabled-password --gecos '' appuser
|
||||
|
||||
# Change ownership of the /app directory so that appuser can write files.
|
||||
RUN chown -R appuser:appuser /app
|
||||
|
||||
# Create a directory for logs with proper permissions
|
||||
RUN mkdir -p /app/logs && chown -R appuser:appuser /app/logs
|
||||
|
||||
USER appuser
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
# Add environment variables for app configuration
|
||||
ENV FLASK_ENV=production
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
ENV PYTHON_UNBUFFERED=1
|
||||
|
||||
# Improve healthcheck reliability - use new health endpoint
|
||||
HEALTHCHECK --interval=15s --timeout=5s --start-period=30s --retries=3 \
|
||||
CMD curl -f http://localhost:5000/api/health || exit 1
|
||||
|
||||
# Use Gunicorn as the production WSGI server with improved settings
|
||||
# For shared global state, we need to keep the single worker model but optimize other parameters
|
||||
CMD ["gunicorn", "-b", "0.0.0.0:5000", "App:app", \
|
||||
"--preload", \
|
||||
"--workers=1", \
|
||||
"--threads=12", \
|
||||
"--timeout=600", \
|
||||
"--keep-alive=5", \
|
||||
"--max-requests=1000", \
|
||||
"--max-requests-jitter=100", \
|
||||
"--log-level=info", \
|
||||
"--access-logfile=-", \
|
||||
"--error-logfile=-", \
|
||||
"--log-file=-", \
|
||||
"--graceful-timeout=60", \
|
||||
"--worker-tmp-dir=/dev/shm"]
|
60
error.html
Normal file
60
error.html
Normal file
@ -0,0 +1,60 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Error - Dashboard</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color: #121212;
|
||||
--primary-color: #f7931a;
|
||||
--text-color: white;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--bg-color);
|
||||
color: var(--text-color);
|
||||
padding-top: 20px;
|
||||
font-family: 'Orbitron', sans-serif;
|
||||
}
|
||||
|
||||
a.btn-primary {
|
||||
background-color: var(--primary-color);
|
||||
border-color: var(--primary-color);
|
||||
color: black;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.error-container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
border: 1px solid var(--primary-color);
|
||||
border-radius: 5px;
|
||||
background-color: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: var(--primary-color);
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
p {
|
||||
margin-bottom: 1.5rem;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="error-container">
|
||||
<h1>Error</h1>
|
||||
<p>{{ message }}</p>
|
||||
<a href="/" class="btn btn-primary">Return to Dashboard</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
627
index.html
Normal file
627
index.html
Normal file
@ -0,0 +1,627 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<!-- Custom Orbitron Font -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap" rel="stylesheet">
|
||||
<!-- Meta viewport for responsive scaling -->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Ocean.xyz Pool Mining Dashboard v 0.2</title>
|
||||
<!-- Font Awesome CDN for icon support -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color: #0d0d0d;
|
||||
--bg-gradient: linear-gradient(135deg, #0d0d0d, #1a1a1a);
|
||||
--primary-color: #f7931a;
|
||||
--accent-color: #00ffff;
|
||||
--text-color: #ffffff;
|
||||
--card-padding: 0.5rem;
|
||||
--text-size-base: 14px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
:root {
|
||||
--card-padding: 0.75rem;
|
||||
--text-size-base: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--bg-gradient);
|
||||
color: var(--text-color);
|
||||
padding-top: 0.5rem;
|
||||
font-size: var(--text-size-base);
|
||||
font-family: 'Orbitron', sans-serif;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: calc(var(--text-size-base) * 1.4);
|
||||
font-weight: bold;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.card,
|
||||
.card-header,
|
||||
.card-body,
|
||||
.card-footer {
|
||||
border-radius: 0 !important;
|
||||
}
|
||||
|
||||
.card {
|
||||
background-color: var(--bg-color);
|
||||
border: 1px solid var(--primary-color);
|
||||
margin-bottom: 0.5rem;
|
||||
padding: var(--card-padding);
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* Override for Payout & Misc card */
|
||||
#payoutMiscCard {
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
background-color: #000;
|
||||
color: var(--primary-color);
|
||||
font-weight: bold;
|
||||
padding: 0.25rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.card-body hr {
|
||||
border-top: 1px solid var(--primary-color);
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
display: inline-block;
|
||||
font-weight: bold;
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
/* Bounce Up Animation for Up Chevron */
|
||||
@keyframes bounceUp {
|
||||
0% { transform: translateY(0); }
|
||||
25% { transform: translateY(-2px); }
|
||||
50% { transform: translateY(0); }
|
||||
75% { transform: translateY(-2px); }
|
||||
100% { transform: translateY(0); }
|
||||
}
|
||||
|
||||
/* Bounce Down Animation for Down Chevron */
|
||||
@keyframes bounceDown {
|
||||
0% { transform: translateY(0); }
|
||||
25% { transform: translateY(2px); }
|
||||
50% { transform: translateY(0); }
|
||||
75% { transform: translateY(2px); }
|
||||
100% { transform: translateY(0); }
|
||||
}
|
||||
|
||||
/* Apply bounce animations */
|
||||
.bounce-up {
|
||||
animation: bounceUp 1s infinite;
|
||||
}
|
||||
|
||||
.bounce-down {
|
||||
animation: bounceDown 1s infinite;
|
||||
}
|
||||
|
||||
/* Make chevrons slightly smaller */
|
||||
.chevron {
|
||||
font-size: 0.8rem;
|
||||
position: relative;
|
||||
top: 3px;
|
||||
}
|
||||
|
||||
.online-dot {
|
||||
display: inline-block;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
background: #32CD32;
|
||||
border-radius: 50%;
|
||||
margin-left: 0.5em;
|
||||
position: relative;
|
||||
top: -2px;
|
||||
animation: glow 1s infinite;
|
||||
}
|
||||
|
||||
@keyframes glow {
|
||||
0%, 100% { box-shadow: 0 0 5px #32CD32, 0 0 10px #32CD32; }
|
||||
50% { box-shadow: 0 0 10px #32CD32, 0 0 20px #32CD32; }
|
||||
}
|
||||
|
||||
.offline-dot {
|
||||
display: inline-block;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
background: red;
|
||||
border-radius: 50%;
|
||||
margin-left: 0.5em;
|
||||
animation: glowRed 1s infinite;
|
||||
}
|
||||
|
||||
@keyframes glowRed {
|
||||
0%, 100% { box-shadow: 0 0 5px red, 0 0 10px red; }
|
||||
50% { box-shadow: 0 0 10px red, 0 0 20px red; }
|
||||
}
|
||||
|
||||
@keyframes glowPulse {
|
||||
0%, 100% { text-shadow: 0 0 5px #32CD32; }
|
||||
50% { text-shadow: 0 0 10px #32CD32; }
|
||||
}
|
||||
|
||||
#graphContainer {
|
||||
background-color: #000;
|
||||
padding: 0.5rem;
|
||||
margin-bottom: 1rem;
|
||||
height: 230px;
|
||||
}
|
||||
|
||||
/* Refresh timer container */
|
||||
#refreshUptime {
|
||||
text-align: center;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
#refreshContainer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.metric-value {
|
||||
color: var(--text-color);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#btc_price { color: #ffd700; }
|
||||
#unpaid_earnings { color: #32CD32; }
|
||||
#miner_status.online { color: #32CD32; }
|
||||
#daily_power_cost { color: red !important; }
|
||||
#daily_revenue,
|
||||
#daily_profit_usd,
|
||||
#monthly_profit_usd { color: #32CD32; }
|
||||
#est_time_to_payout { color: #ffd700; }
|
||||
|
||||
.card-body strong {
|
||||
color: var(--primary-color);
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
|
||||
.card-body p {
|
||||
margin: 0.25rem 0;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
a.btn-primary {
|
||||
background-color: var(--primary-color);
|
||||
border-color: var(--primary-color);
|
||||
color: #000;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.row.equal-height {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.row.equal-height > [class*="col-"] {
|
||||
display: flex;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.row.equal-height > [class*="col-"] .card {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.container-fluid {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding-left: 1rem;
|
||||
padding-right: 1rem;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#topRightLink {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
color: grey;
|
||||
text-decoration: none;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
#uptimeTimer strong {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#uptimeTimer {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
/* Connection status indicator */
|
||||
#connectionStatus {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
background: rgba(255,0,0,0.7);
|
||||
color: white;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
z-index: 9999;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
/* Bitcoin Progress Bar Styles */
|
||||
.bitcoin-progress-container {
|
||||
width: 100%;
|
||||
max-width: 300px;
|
||||
height: 20px;
|
||||
background-color: #222;
|
||||
border: 1px solid var(--primary-color);
|
||||
border-radius: 0;
|
||||
margin: 0.5rem auto;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 0 8px rgba(247, 147, 26, 0.3);
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.bitcoin-progress-inner {
|
||||
height: 100%;
|
||||
width: 0;
|
||||
background: linear-gradient(90deg, #f7931a, #ffa500);
|
||||
border-radius: 0;
|
||||
transition: width 0.3s ease;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.bitcoin-progress-inner::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: linear-gradient(90deg,
|
||||
rgba(255, 255, 255, 0.1) 0%,
|
||||
rgba(255, 255, 255, 0.2) 20%,
|
||||
rgba(255, 255, 255, 0.1) 40%);
|
||||
animation: shimmer 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% { transform: translateX(-100%); }
|
||||
100% { transform: translateX(100%); }
|
||||
}
|
||||
|
||||
.bitcoin-icons {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
transform: translateY(-50%);
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
font-size: 12px;
|
||||
color: rgba(0, 0, 0, 0.7);
|
||||
}
|
||||
|
||||
.glow-effect {
|
||||
box-shadow: 0 0 10px #f7931a, 0 0 20px #f7931a;
|
||||
animation: pulse 1s infinite;
|
||||
}
|
||||
|
||||
/* Extra styling for when server update is late */
|
||||
.waiting-for-update {
|
||||
animation: waitingPulse 2s infinite !important;
|
||||
}
|
||||
|
||||
@keyframes waitingPulse {
|
||||
0%, 100% { box-shadow: 0 0 5px #f7931a, 0 0 10px #f7931a; opacity: 0.8; }
|
||||
50% { box-shadow: 0 0 15px #f7931a, 0 0 30px #f7931a; opacity: 1; }
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.8; }
|
||||
}
|
||||
|
||||
#progress-text {
|
||||
font-size: 0.8rem;
|
||||
color: var(--primary-color);
|
||||
margin-top: 0.3rem;
|
||||
font-family: 'Orbitron', sans-serif;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Mobile responsiveness improvements */
|
||||
@media (max-width: 576px) {
|
||||
.container-fluid {
|
||||
padding-left: 0.5rem;
|
||||
padding-right: 0.5rem;
|
||||
}
|
||||
|
||||
.card-body {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
#graphContainer {
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
#topRightLink {
|
||||
position: static;
|
||||
display: block;
|
||||
text-align: right;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container-fluid">
|
||||
<!-- Connection status indicator -->
|
||||
<div id="connectionStatus"></div>
|
||||
|
||||
<!-- Top right link -->
|
||||
<a href="https://x.com/DJObleezy" id="topRightLink" target="_blank" rel="noopener noreferrer">Made by @DJO₿leezy</a>
|
||||
|
||||
<h1 class="text-center"><a href="/" style="text-decoration:none; color:inherit;">Ocean.xyz Pool Mining Dashboard v 0.2</a></h1>
|
||||
<p class="text-center" id="lastUpdated"><strong>Last Updated:</strong> {{ current_time }}</p>
|
||||
|
||||
<!-- Graph Container -->
|
||||
<div id="graphContainer" class="mb-2">
|
||||
<canvas id="trendGraph" style="width: 100%; height: 100%;"></canvas>
|
||||
</div>
|
||||
|
||||
<!-- Miner Status -->
|
||||
<div class="row mb-2 equal-height">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header">Miner Status</div>
|
||||
<div class="card-body">
|
||||
<p>
|
||||
<strong>Status:</strong>
|
||||
<span id="miner_status" class="metric-value">
|
||||
{% if metrics.workers_hashing and metrics.workers_hashing > 0 %}
|
||||
ONLINE <span class="online-dot"></span>
|
||||
{% else %}
|
||||
OFFLINE <span class="offline-dot"></span>
|
||||
{% endif %}
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Workers Hashing:</strong>
|
||||
<span id="workers_hashing" class="metric-value">{{ metrics.workers_hashing or 0 }}</span>
|
||||
<span id="indicator_workers_hashing"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Last Share:</strong>
|
||||
<span id="last_share" class="metric-value">{{ metrics.total_last_share }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Pool Hashrates and Bitcoin Network Stats -->
|
||||
<div class="row equal-height">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">Pool Hashrates</div>
|
||||
<div class="card-body">
|
||||
<p>
|
||||
<strong>Pool Total Hashrate:</strong>
|
||||
<span id="pool_total_hashrate" class="metric-value">
|
||||
{% if metrics.pool_total_hashrate %}
|
||||
{{ metrics.pool_total_hashrate }} {{ metrics.pool_total_hashrate_unit[:-2]|upper ~ metrics.pool_total_hashrate_unit[-2:] }}
|
||||
{% else %}
|
||||
N/A
|
||||
{% endif %}
|
||||
</span>
|
||||
<span id="indicator_pool_total_hashrate"></span>
|
||||
</p>
|
||||
<hr>
|
||||
<p>
|
||||
<strong>24hr Avg Hashrate:</strong>
|
||||
<span id="hashrate_24hr" class="metric-value">
|
||||
{{ metrics.hashrate_24hr }} {{ metrics.hashrate_24hr_unit[:-2]|upper ~ metrics.hashrate_24hr_unit[-2:] }}
|
||||
</span>
|
||||
<span id="indicator_hashrate_24hr"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>3hr Avg Hashrate:</strong>
|
||||
<span id="hashrate_3hr" class="metric-value">
|
||||
{{ metrics.hashrate_3hr }} {{ metrics.hashrate_3hr_unit[:-2]|upper ~ metrics.hashrate_3hr_unit[-2:] }}
|
||||
</span>
|
||||
<span id="indicator_hashrate_3hr"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>10min Avg Hashrate:</strong>
|
||||
<span id="hashrate_10min" class="metric-value">
|
||||
{{ metrics.hashrate_10min }} {{ metrics.hashrate_10min_unit[:-2]|upper ~ metrics.hashrate_10min_unit[-2:] }}
|
||||
</span>
|
||||
<span id="indicator_hashrate_10min"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>60sec Avg Hashrate:</strong>
|
||||
<span id="hashrate_60sec" class="metric-value">
|
||||
{{ metrics.hashrate_60sec }} {{ metrics.hashrate_60sec_unit[:-2]|upper ~ metrics.hashrate_60sec_unit[-2:] }}
|
||||
</span>
|
||||
<span id="indicator_hashrate_60sec"></span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">Bitcoin Network Stats</div>
|
||||
<div class="card-body">
|
||||
<p>
|
||||
<strong>Block Number:</strong>
|
||||
<span id="block_number" class="metric-value">{{ metrics.block_number|commafy }}</span>
|
||||
<span id="indicator_block_number"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>BTC Price:</strong>
|
||||
<span id="btc_price" class="metric-value">${{ "%.2f"|format(metrics.btc_price) }}</span>
|
||||
<span id="indicator_btc_price"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Network Hashrate:</strong>
|
||||
<span id="network_hashrate" class="metric-value">{{ metrics.network_hashrate|round|commafy }} EH/s</span>
|
||||
<span id="indicator_network_hashrate"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Difficulty:</strong>
|
||||
<span id="difficulty" class="metric-value">{{ metrics.difficulty|round|commafy }}</span>
|
||||
<span id="indicator_difficulty"></span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Satoshi and USD Metrics -->
|
||||
<div class="row equal-height">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">Satoshi Metrics</div>
|
||||
<div class="card-body">
|
||||
<p>
|
||||
<strong>Daily Mined (Net):</strong>
|
||||
<span id="daily_mined_sats" class="metric-value">{{ metrics.daily_mined_sats|commafy }} sats</span>
|
||||
<span id="indicator_daily_mined_sats"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Monthly Mined (Net):</strong>
|
||||
<span id="monthly_mined_sats" class="metric-value">{{ metrics.monthly_mined_sats|commafy }} sats</span>
|
||||
<span id="indicator_monthly_mined_sats"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Est. Earnings/Day:</strong>
|
||||
<span id="estimated_earnings_per_day_sats" class="metric-value">{{ metrics.estimated_earnings_per_day_sats|commafy }} sats</span>
|
||||
<span id="indicator_estimated_earnings_per_day_sats"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Est. Earnings/Block:</strong>
|
||||
<span id="estimated_earnings_next_block_sats" class="metric-value">{{ metrics.estimated_earnings_next_block_sats|commafy }} sats</span>
|
||||
<span id="indicator_estimated_earnings_next_block_sats"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Est. Rewards in Window:</strong>
|
||||
<span id="estimated_rewards_in_window_sats" class="metric-value">{{ metrics.estimated_rewards_in_window_sats|commafy }} sats</span>
|
||||
<span id="indicator_estimated_rewards_in_window_sats"></span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">USD Metrics</div>
|
||||
<div class="card-body">
|
||||
<p>
|
||||
<strong>Daily Revenue:</strong>
|
||||
<span id="daily_revenue" class="metric-value">${{ "%.2f"|format(metrics.daily_revenue) }}</span>
|
||||
<span id="indicator_daily_revenue"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Daily Power Cost:</strong>
|
||||
<span id="daily_power_cost" class="metric-value">${{ "%.2f"|format(metrics.daily_power_cost) }}</span>
|
||||
<span id="indicator_daily_power_cost"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Daily Profit (USD):</strong>
|
||||
<span id="daily_profit_usd" class="metric-value">${{ "%.2f"|format(metrics.daily_profit_usd) }}</span>
|
||||
<span id="indicator_daily_profit_usd"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Monthly Profit (USD):</strong>
|
||||
<span id="monthly_profit_usd" class="metric-value">${{ "%.2f"|format(metrics.monthly_profit_usd) }}</span>
|
||||
<span id="indicator_monthly_profit_usd"></span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Payout & Misc -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card" id="payoutMiscCard">
|
||||
<div class="card-header">Payout & Misc</div>
|
||||
<div class="card-body">
|
||||
<p>
|
||||
<strong>Unpaid Earnings:</strong>
|
||||
<span id="unpaid_earnings" class="metric-value">{{ metrics.unpaid_earnings }} BTC</span>
|
||||
<span id="indicator_unpaid_earnings"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Last Block:</strong>
|
||||
<span id="last_block_height" class="metric-value">{{ metrics.last_block_height }}</span>
|
||||
—<span id="last_block_time" class="metric-value" style="color: cyan;">{{ metrics.last_block_time }}</span>—
|
||||
<span style="color: green;">+{{ metrics.last_block_earnings | int | commafy }} sats</span>
|
||||
<span id="indicator_last_block"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Est. Time to Payout:</strong>
|
||||
<span id="est_time_to_payout" class="metric-value">{{ metrics.est_time_to_payout }}</span>
|
||||
<span id="indicator_est_time_to_payout"></span>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Blocks Found:</strong>
|
||||
<span id="blocks_found" class="metric-value">{{ metrics.blocks_found }}</span>
|
||||
<span id="indicator_blocks_found"></span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Bitcoin-themed Progress Bar and Uptime -->
|
||||
<div id="refreshUptime" class="text-center">
|
||||
<div id="refreshContainer">
|
||||
<!-- Bitcoin-themed progress bar -->
|
||||
<div class="bitcoin-progress-container">
|
||||
<div id="bitcoin-progress-inner" class="bitcoin-progress-inner">
|
||||
<!-- Small Bitcoin icons inside the bar -->
|
||||
<div class="bitcoin-icons">
|
||||
<i class="fab fa-bitcoin"></i>
|
||||
<i class="fab fa-bitcoin"></i>
|
||||
<i class="fab fa-bitcoin"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div id="progress-text">60s to next update</div> -->
|
||||
</div>
|
||||
<div id="uptimeTimer"><strong>Uptime:</strong> 0h 0m 0s</div>
|
||||
</div>
|
||||
|
||||
<!-- Hidden Congrats Message -->
|
||||
<div id="congratsMessage" style="display:none; position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 1000; background: #f7931a; color: #000; padding: 10px; border-radius: 5px;"></div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- External JavaScript libraries -->
|
||||
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-annotation@1.1.0"></script>
|
||||
<!-- External JavaScript file with our application logic -->
|
||||
<script src="/static/js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
772
main.js
Normal file
772
main.js
Normal file
@ -0,0 +1,772 @@
|
||||
"use strict";
|
||||
|
||||
// Global variables
|
||||
let previousMetrics = {};
|
||||
let persistentArrows = {};
|
||||
let serverTimeOffset = 0;
|
||||
let serverStartTime = null;
|
||||
let latestMetrics = null;
|
||||
let initialLoad = true;
|
||||
let trendData = [];
|
||||
let trendLabels = [];
|
||||
let trendChart = null;
|
||||
let connectionRetryCount = 0;
|
||||
let maxRetryCount = 10;
|
||||
let reconnectionDelay = 1000; // Start with 1 second
|
||||
let pingInterval = null;
|
||||
let lastPingTime = Date.now();
|
||||
let connectionLostTimeout = null;
|
||||
|
||||
// Bitcoin-themed progress bar functionality
|
||||
let progressInterval;
|
||||
let currentProgress = 0;
|
||||
let lastUpdateTime = Date.now();
|
||||
let expectedUpdateInterval = 60000; // Expected server update interval (60 seconds)
|
||||
const PROGRESS_MAX = 60; // 60 seconds for a complete cycle
|
||||
|
||||
// Initialize the progress bar and start the animation
|
||||
function initProgressBar() {
|
||||
// Clear any existing interval
|
||||
if (progressInterval) {
|
||||
clearInterval(progressInterval);
|
||||
}
|
||||
|
||||
// Set last update time to now
|
||||
lastUpdateTime = Date.now();
|
||||
|
||||
// Reset progress with initial offset
|
||||
currentProgress = 1; // Start at 1 instead of 0 for offset
|
||||
updateProgressBar(currentProgress);
|
||||
|
||||
// Start the interval
|
||||
progressInterval = setInterval(function() {
|
||||
// Calculate elapsed time since last update
|
||||
const elapsedTime = Date.now() - lastUpdateTime;
|
||||
|
||||
// Calculate progress percentage based on elapsed time with +1 second offset
|
||||
const secondsElapsed = Math.floor(elapsedTime / 1000) + 1; // Add 1 second offset
|
||||
|
||||
// If we've gone past the expected update time
|
||||
if (secondsElapsed >= PROGRESS_MAX) {
|
||||
// Keep the progress bar full but show waiting state
|
||||
currentProgress = PROGRESS_MAX;
|
||||
} else {
|
||||
// Normal progress with offset
|
||||
currentProgress = secondsElapsed;
|
||||
}
|
||||
|
||||
updateProgressBar(currentProgress);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
// Update the progress bar display
|
||||
function updateProgressBar(seconds) {
|
||||
const progressPercent = (seconds / PROGRESS_MAX) * 100;
|
||||
$("#bitcoin-progress-inner").css("width", progressPercent + "%");
|
||||
|
||||
// Add glowing effect when close to completion
|
||||
if (progressPercent > 80) {
|
||||
$("#bitcoin-progress-inner").addClass("glow-effect");
|
||||
} else {
|
||||
$("#bitcoin-progress-inner").removeClass("glow-effect");
|
||||
}
|
||||
|
||||
// Update remaining seconds text - more precise calculation
|
||||
let remainingSeconds = PROGRESS_MAX - seconds;
|
||||
|
||||
// When we're past the expected time, show "Waiting for update..."
|
||||
if (remainingSeconds <= 0) {
|
||||
$("#progress-text").text("Waiting for update...");
|
||||
$("#bitcoin-progress-inner").addClass("waiting-for-update");
|
||||
} else {
|
||||
$("#progress-text").text(remainingSeconds + "s to next update");
|
||||
$("#bitcoin-progress-inner").removeClass("waiting-for-update");
|
||||
}
|
||||
}
|
||||
|
||||
// Register Chart.js annotation plugin if available
|
||||
if (window['chartjs-plugin-annotation']) {
|
||||
Chart.register(window['chartjs-plugin-annotation']);
|
||||
}
|
||||
|
||||
// SSE Connection with Error Handling and Reconnection Logic
|
||||
function setupEventSource() {
|
||||
console.log("Setting up EventSource connection...");
|
||||
|
||||
if (window.eventSource) {
|
||||
console.log("Closing existing EventSource connection");
|
||||
window.eventSource.close();
|
||||
window.eventSource = null;
|
||||
}
|
||||
|
||||
// Always use absolute URL with origin to ensure it works from any path
|
||||
const baseUrl = window.location.origin;
|
||||
const streamUrl = `${baseUrl}/stream`;
|
||||
|
||||
console.log("Current path:", window.location.pathname);
|
||||
console.log("Using stream URL:", streamUrl);
|
||||
|
||||
// Clear any existing ping interval
|
||||
if (pingInterval) {
|
||||
clearInterval(pingInterval);
|
||||
pingInterval = null;
|
||||
}
|
||||
|
||||
// Clear any connection lost timeout
|
||||
if (connectionLostTimeout) {
|
||||
clearTimeout(connectionLostTimeout);
|
||||
connectionLostTimeout = null;
|
||||
}
|
||||
|
||||
try {
|
||||
const eventSource = new EventSource(streamUrl);
|
||||
|
||||
eventSource.onopen = function(e) {
|
||||
console.log("EventSource connection opened successfully");
|
||||
connectionRetryCount = 0; // Reset retry count on successful connection
|
||||
reconnectionDelay = 1000; // Reset reconnection delay
|
||||
hideConnectionIssue();
|
||||
|
||||
// Start ping interval to detect dead connections
|
||||
lastPingTime = Date.now();
|
||||
pingInterval = setInterval(function() {
|
||||
const now = Date.now();
|
||||
if (now - lastPingTime > 60000) { // 60 seconds without data
|
||||
console.warn("No data received for 60 seconds, reconnecting...");
|
||||
showConnectionIssue("Connection stalled");
|
||||
eventSource.close();
|
||||
setupEventSource();
|
||||
}
|
||||
}, 10000); // Check every 10 seconds
|
||||
};
|
||||
|
||||
eventSource.onmessage = function(e) {
|
||||
console.log("SSE message received");
|
||||
lastPingTime = Date.now(); // Update ping time on any message
|
||||
|
||||
try {
|
||||
const data = JSON.parse(e.data);
|
||||
|
||||
// Handle different message types
|
||||
if (data.type === "ping") {
|
||||
console.log("Ping received:", data);
|
||||
// Update connection count if available
|
||||
if (data.connections !== undefined) {
|
||||
console.log(`Active connections: ${data.connections}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "timeout_warning") {
|
||||
console.log(`Connection timeout warning: ${data.remaining}s remaining`);
|
||||
// If less than 30 seconds remaining, prepare for reconnection
|
||||
if (data.remaining < 30) {
|
||||
console.log("Preparing for reconnection due to upcoming timeout");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === "timeout") {
|
||||
console.log("Connection timeout from server:", data.message);
|
||||
eventSource.close();
|
||||
// If reconnect flag is true, reconnect immediately
|
||||
if (data.reconnect) {
|
||||
console.log("Server requested reconnection");
|
||||
setTimeout(setupEventSource, 500);
|
||||
} else {
|
||||
setupEventSource();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.error) {
|
||||
console.error("Server reported error:", data.error);
|
||||
showConnectionIssue(data.error);
|
||||
|
||||
// If retry time provided, use it, otherwise use default
|
||||
const retryTime = data.retry || 5000;
|
||||
setTimeout(function() {
|
||||
manualRefresh();
|
||||
}, retryTime);
|
||||
return;
|
||||
}
|
||||
|
||||
// Process regular data update
|
||||
latestMetrics = data;
|
||||
updateUI();
|
||||
hideConnectionIssue();
|
||||
|
||||
// Also explicitly trigger a data refresh event
|
||||
$(document).trigger('dataRefreshed');
|
||||
} catch (err) {
|
||||
console.error("Error processing SSE data:", err);
|
||||
showConnectionIssue("Data processing error");
|
||||
}
|
||||
};
|
||||
|
||||
eventSource.onerror = function(e) {
|
||||
console.error("SSE connection error", e);
|
||||
showConnectionIssue("Connection lost");
|
||||
|
||||
eventSource.close();
|
||||
|
||||
// Implement exponential backoff for reconnection
|
||||
connectionRetryCount++;
|
||||
|
||||
if (connectionRetryCount > maxRetryCount) {
|
||||
console.log("Maximum retry attempts reached, switching to polling mode");
|
||||
if (pingInterval) {
|
||||
clearInterval(pingInterval);
|
||||
pingInterval = null;
|
||||
}
|
||||
|
||||
// Switch to regular polling
|
||||
showConnectionIssue("Using polling mode");
|
||||
setInterval(manualRefresh, 30000); // Poll every 30 seconds
|
||||
manualRefresh(); // Do an immediate refresh
|
||||
return;
|
||||
}
|
||||
|
||||
// Exponential backoff with jitter
|
||||
const jitter = Math.random() * 0.3 + 0.85; // 0.85-1.15
|
||||
reconnectionDelay = Math.min(30000, reconnectionDelay * 1.5 * jitter);
|
||||
|
||||
console.log(`Reconnecting in ${(reconnectionDelay/1000).toFixed(1)} seconds... (attempt ${connectionRetryCount}/${maxRetryCount})`);
|
||||
setTimeout(setupEventSource, reconnectionDelay);
|
||||
};
|
||||
|
||||
window.eventSource = eventSource;
|
||||
console.log("EventSource setup complete");
|
||||
|
||||
// Set a timeout to detect if connection is established
|
||||
connectionLostTimeout = setTimeout(function() {
|
||||
if (eventSource.readyState !== 1) { // 1 = OPEN
|
||||
console.warn("Connection not established within timeout, switching to manual refresh");
|
||||
showConnectionIssue("Connection timeout");
|
||||
eventSource.close();
|
||||
manualRefresh();
|
||||
}
|
||||
}, 10000); // 10 seconds timeout to establish connection
|
||||
|
||||
} catch (error) {
|
||||
console.error("Failed to create EventSource:", error);
|
||||
showConnectionIssue("Connection setup failed");
|
||||
setTimeout(setupEventSource, 5000); // Try again in 5 seconds
|
||||
}
|
||||
|
||||
// Add page visibility change listener
|
||||
// This helps reconnect when user returns to the tab after it's been inactive
|
||||
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
||||
document.addEventListener("visibilitychange", handleVisibilityChange);
|
||||
}
|
||||
|
||||
// Handle page visibility changes
|
||||
function handleVisibilityChange() {
|
||||
if (!document.hidden) {
|
||||
console.log("Page became visible, checking connection");
|
||||
if (!window.eventSource || window.eventSource.readyState !== 1) {
|
||||
console.log("Connection not active, reestablishing");
|
||||
setupEventSource();
|
||||
}
|
||||
manualRefresh(); // Always refresh data when page becomes visible
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to show connection issues to the user
|
||||
function showConnectionIssue(message) {
|
||||
let $connectionStatus = $("#connectionStatus");
|
||||
if (!$connectionStatus.length) {
|
||||
$("body").append('<div id="connectionStatus" style="position: fixed; top: 10px; right: 10px; background: rgba(255,0,0,0.7); color: white; padding: 10px; border-radius: 5px; z-index: 9999;"></div>');
|
||||
$connectionStatus = $("#connectionStatus");
|
||||
}
|
||||
$connectionStatus.html(`<i class="fas fa-exclamation-triangle"></i> ${message}`).show();
|
||||
|
||||
// Show manual refresh button when there are connection issues
|
||||
$("#refreshButton").show();
|
||||
}
|
||||
|
||||
// Helper function to hide connection issue message
|
||||
function hideConnectionIssue() {
|
||||
$("#connectionStatus").hide();
|
||||
$("#refreshButton").hide();
|
||||
}
|
||||
|
||||
// Improved manual refresh function as fallback
|
||||
function manualRefresh() {
|
||||
console.log("Manually refreshing data...");
|
||||
|
||||
$.ajax({
|
||||
url: '/api/metrics',
|
||||
method: 'GET',
|
||||
dataType: 'json',
|
||||
timeout: 15000, // 15 second timeout
|
||||
success: function(data) {
|
||||
console.log("Manual refresh successful");
|
||||
lastPingTime = Date.now(); // Update ping time
|
||||
latestMetrics = data;
|
||||
updateUI();
|
||||
hideConnectionIssue();
|
||||
|
||||
// Explicitly trigger data refresh event
|
||||
$(document).trigger('dataRefreshed');
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error("Manual refresh failed:", error);
|
||||
showConnectionIssue("Manual refresh failed");
|
||||
|
||||
// Try again with exponential backoff
|
||||
const retryDelay = Math.min(30000, 1000 * Math.pow(1.5, Math.min(5, connectionRetryCount)));
|
||||
connectionRetryCount++;
|
||||
setTimeout(manualRefresh, retryDelay);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize Chart.js with Error Handling
|
||||
function initializeChart() {
|
||||
try {
|
||||
const ctx = document.getElementById('trendGraph').getContext('2d');
|
||||
if (!ctx) {
|
||||
console.error("Could not find trend graph canvas");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!window.Chart) {
|
||||
console.error("Chart.js not loaded");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if Chart.js plugin is available
|
||||
const hasAnnotationPlugin = window['chartjs-plugin-annotation'] !== undefined;
|
||||
|
||||
return new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: [],
|
||||
datasets: [{
|
||||
label: '60s Hashrate Trend (TH/s)',
|
||||
data: [],
|
||||
borderColor: '#f7931a',
|
||||
backgroundColor: 'rgba(247,147,26,0.1)',
|
||||
fill: true,
|
||||
tension: 0.2,
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
animation: {
|
||||
duration: 0 // Disable animations for better performance
|
||||
},
|
||||
scales: {
|
||||
x: { display: false },
|
||||
y: {
|
||||
ticks: { color: 'white' },
|
||||
grid: { color: '#333' }
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
legend: { display: false },
|
||||
annotation: hasAnnotationPlugin ? {
|
||||
annotations: {
|
||||
averageLine: {
|
||||
type: 'line',
|
||||
yMin: 0,
|
||||
yMax: 0,
|
||||
borderColor: '#f7931a',
|
||||
borderWidth: 2,
|
||||
borderDash: [6, 6],
|
||||
label: {
|
||||
enabled: true,
|
||||
content: '24hr Avg: 0 TH/s',
|
||||
backgroundColor: 'rgba(0,0,0,0.7)',
|
||||
color: '#f7931a',
|
||||
font: { weight: 'bold', size: 13 },
|
||||
position: 'start'
|
||||
}
|
||||
}
|
||||
}
|
||||
} : {}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error initializing chart:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to safely format numbers with commas
|
||||
function numberWithCommas(x) {
|
||||
if (x == null) return "N/A";
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
}
|
||||
|
||||
// Server time update via polling
|
||||
function updateServerTime() {
|
||||
$.ajax({
|
||||
url: "/api/time",
|
||||
method: "GET",
|
||||
timeout: 5000,
|
||||
success: function(data) {
|
||||
serverTimeOffset = new Date(data.server_timestamp).getTime() - Date.now();
|
||||
serverStartTime = new Date(data.server_start_time).getTime();
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
console.error("Error fetching server time:", textStatus, errorThrown);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Update uptime display
|
||||
function updateUptime() {
|
||||
if (serverStartTime) {
|
||||
const currentServerTime = Date.now() + serverTimeOffset;
|
||||
const diff = currentServerTime - serverStartTime;
|
||||
const hours = Math.floor(diff / (1000 * 60 * 60));
|
||||
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
|
||||
const seconds = Math.floor((diff % (1000 * 60)) / 1000);
|
||||
$("#uptimeTimer").html("<strong>Uptime:</strong> " + hours + "h " + minutes + "m " + seconds + "s");
|
||||
}
|
||||
}
|
||||
|
||||
// Update UI indicators (arrows)
|
||||
function updateIndicators(newMetrics) {
|
||||
const keys = [
|
||||
"pool_total_hashrate", "hashrate_24hr", "hashrate_3hr", "hashrate_10min",
|
||||
"hashrate_60sec", "block_number", "btc_price", "network_hashrate",
|
||||
"difficulty", "daily_revenue", "daily_power_cost", "daily_profit_usd",
|
||||
"monthly_profit_usd", "daily_mined_sats", "monthly_mined_sats", "unpaid_earnings",
|
||||
"estimated_earnings_per_day_sats", "estimated_earnings_next_block_sats", "estimated_rewards_in_window_sats",
|
||||
"workers_hashing"
|
||||
];
|
||||
|
||||
keys.forEach(function(key) {
|
||||
const newVal = parseFloat(newMetrics[key]);
|
||||
if (isNaN(newVal)) return;
|
||||
|
||||
const oldVal = parseFloat(previousMetrics[key]);
|
||||
if (!isNaN(oldVal)) {
|
||||
if (newVal > oldVal) {
|
||||
persistentArrows[key] = "<i class='arrow chevron fa-solid fa-angle-double-up bounce-up' style='color: green;'></i>";
|
||||
} else if (newVal < oldVal) {
|
||||
persistentArrows[key] = "<i class='arrow chevron fa-solid fa-angle-double-down bounce-down' style='color: red; position: relative; top: -2px;'></i>";
|
||||
}
|
||||
} else {
|
||||
if (newMetrics.arrow_history && newMetrics.arrow_history[key] && newMetrics.arrow_history[key].length > 0) {
|
||||
const historyArr = newMetrics.arrow_history[key];
|
||||
for (let i = historyArr.length - 1; i >= 0; i--) {
|
||||
if (historyArr[i].arrow !== "") {
|
||||
if (historyArr[i].arrow === "↑") {
|
||||
persistentArrows[key] = "<i class='arrow chevron fa-solid fa-angle-double-up bounce-up' style='color: green;'></i>";
|
||||
} else if (historyArr[i].arrow === "↓") {
|
||||
persistentArrows[key] = "<i class='arrow chevron fa-solid fa-angle-double-down bounce-down' style='color: red; position: relative; top: -2px;'></i>";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const indicator = document.getElementById("indicator_" + key);
|
||||
if (indicator) {
|
||||
indicator.innerHTML = persistentArrows[key] || "";
|
||||
}
|
||||
});
|
||||
|
||||
previousMetrics = { ...newMetrics };
|
||||
}
|
||||
|
||||
// Helper function to safely update element text content
|
||||
function updateElementText(elementId, text) {
|
||||
const element = document.getElementById(elementId);
|
||||
if (element) {
|
||||
element.textContent = text;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to safely update element HTML content
|
||||
function updateElementHTML(elementId, html) {
|
||||
const element = document.getElementById(elementId);
|
||||
if (element) {
|
||||
element.innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for block updates and show congratulatory messages
|
||||
function checkForBlockUpdates(data) {
|
||||
if (previousMetrics.last_block_height !== undefined &&
|
||||
data.last_block_height !== previousMetrics.last_block_height) {
|
||||
showCongrats("Congrats! New Block Found: " + data.last_block_height);
|
||||
}
|
||||
|
||||
if (previousMetrics.blocks_found !== undefined &&
|
||||
data.blocks_found !== previousMetrics.blocks_found) {
|
||||
showCongrats("Congrats! Blocks Found updated: " + data.blocks_found);
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to show congratulatory messages
|
||||
function showCongrats(message) {
|
||||
const $congrats = $("#congratsMessage");
|
||||
$congrats.text(message).fadeIn(500, function() {
|
||||
setTimeout(function() {
|
||||
$congrats.fadeOut(500);
|
||||
}, 3000);
|
||||
});
|
||||
}
|
||||
|
||||
// Main UI update function
|
||||
function updateUI() {
|
||||
if (!latestMetrics) {
|
||||
console.warn("No metrics data available");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const data = latestMetrics;
|
||||
|
||||
// If there's execution time data, log it
|
||||
if (data.execution_time) {
|
||||
console.log(`Server metrics fetch took ${data.execution_time.toFixed(2)}s`);
|
||||
}
|
||||
|
||||
// Cache jQuery selectors for performance and use safe update methods
|
||||
updateElementText("pool_total_hashrate",
|
||||
(data.pool_total_hashrate != null ? data.pool_total_hashrate : "N/A") + " " +
|
||||
(data.pool_total_hashrate_unit ? data.pool_total_hashrate_unit.slice(0,-2).toUpperCase() + data.pool_total_hashrate_unit.slice(-2) : "")
|
||||
);
|
||||
|
||||
updateElementText("hashrate_24hr",
|
||||
(data.hashrate_24hr != null ? data.hashrate_24hr : "N/A") + " " +
|
||||
(data.hashrate_24hr_unit ? data.hashrate_24hr_unit.slice(0,-2).toUpperCase() + data.hashrate_24hr_unit.slice(-2) : "")
|
||||
);
|
||||
|
||||
updateElementText("hashrate_3hr",
|
||||
(data.hashrate_3hr != null ? data.hashrate_3hr : "N/A") + " " +
|
||||
(data.hashrate_3hr_unit ? data.hashrate_3hr_unit.slice(0,-2).toUpperCase() + data.hashrate_3hr_unit.slice(-2) : "")
|
||||
);
|
||||
|
||||
updateElementText("hashrate_10min",
|
||||
(data.hashrate_10min != null ? data.hashrate_10min : "N/A") + " " +
|
||||
(data.hashrate_10min_unit ? data.hashrate_10min_unit.slice(0,-2).toUpperCase() + data.hashrate_10min_unit.slice(-2) : "")
|
||||
);
|
||||
|
||||
updateElementText("hashrate_60sec",
|
||||
(data.hashrate_60sec != null ? data.hashrate_60sec : "N/A") + " " +
|
||||
(data.hashrate_60sec_unit ? data.hashrate_60sec_unit.slice(0,-2).toUpperCase() + data.hashrate_60sec_unit.slice(-2) : "")
|
||||
);
|
||||
|
||||
updateElementText("block_number", numberWithCommas(data.block_number));
|
||||
|
||||
updateElementText("btc_price",
|
||||
data.btc_price != null ? "$" + numberWithCommas(parseFloat(data.btc_price).toFixed(2)) : "N/A"
|
||||
);
|
||||
|
||||
updateElementText("network_hashrate", numberWithCommas(Math.round(data.network_hashrate)) + " EH/s");
|
||||
updateElementText("difficulty", numberWithCommas(Math.round(data.difficulty)));
|
||||
updateElementText("daily_revenue", "$" + numberWithCommas(data.daily_revenue.toFixed(2)));
|
||||
updateElementText("daily_power_cost", "$" + numberWithCommas(data.daily_power_cost.toFixed(2)));
|
||||
updateElementText("daily_profit_usd", "$" + numberWithCommas(data.daily_profit_usd.toFixed(2)));
|
||||
updateElementText("monthly_profit_usd", "$" + numberWithCommas(data.monthly_profit_usd.toFixed(2)));
|
||||
updateElementText("daily_mined_sats", numberWithCommas(data.daily_mined_sats) + " sats");
|
||||
updateElementText("monthly_mined_sats", numberWithCommas(data.monthly_mined_sats) + " sats");
|
||||
updateElementText("workers_hashing", data.workers_hashing || 0);
|
||||
|
||||
// Update miner status with online/offline indicator
|
||||
if (data.workers_hashing > 0) {
|
||||
updateElementHTML("miner_status", "ONLINE <span class='online-dot'></span>");
|
||||
$("#miner_status").css("color", "#32CD32");
|
||||
} else {
|
||||
updateElementHTML("miner_status", "OFFLINE <span class='offline-dot'></span>");
|
||||
$("#miner_status").css("color", "red");
|
||||
}
|
||||
|
||||
updateElementText("unpaid_earnings", data.unpaid_earnings + " BTC");
|
||||
|
||||
// Update payout estimation with color coding
|
||||
const payoutText = data.est_time_to_payout;
|
||||
updateElementText("est_time_to_payout", payoutText);
|
||||
|
||||
if (payoutText && payoutText.toLowerCase().includes("next block")) {
|
||||
$("#est_time_to_payout").css({
|
||||
"color": "#32CD32",
|
||||
"animation": "glowPulse 1s infinite"
|
||||
});
|
||||
} else {
|
||||
const days = parseFloat(payoutText);
|
||||
if (!isNaN(days)) {
|
||||
if (days < 4) {
|
||||
$("#est_time_to_payout").css({"color": "#32CD32", "animation": "none"});
|
||||
} else if (days > 20) {
|
||||
$("#est_time_to_payout").css({"color": "red", "animation": "none"});
|
||||
} else {
|
||||
$("#est_time_to_payout").css({"color": "#ffd700", "animation": "none"});
|
||||
}
|
||||
} else {
|
||||
$("#est_time_to_payout").css({"color": "#ffd700", "animation": "none"});
|
||||
}
|
||||
}
|
||||
|
||||
updateElementText("last_block_height", data.last_block_height || "");
|
||||
updateElementText("last_block_time", data.last_block_time || "");
|
||||
updateElementText("blocks_found", data.blocks_found || "0");
|
||||
updateElementText("last_share", data.total_last_share || "");
|
||||
|
||||
// Update Estimated Earnings metrics
|
||||
updateElementText("estimated_earnings_per_day_sats", numberWithCommas(data.estimated_earnings_per_day_sats) + " sats");
|
||||
updateElementText("estimated_earnings_next_block_sats", numberWithCommas(data.estimated_earnings_next_block_sats) + " sats");
|
||||
updateElementText("estimated_rewards_in_window_sats", numberWithCommas(data.estimated_rewards_in_window_sats) + " sats");
|
||||
|
||||
// Update last updated timestamp
|
||||
const now = new Date(Date.now() + serverTimeOffset);
|
||||
updateElementHTML("lastUpdated", "<strong>Last Updated:</strong> " + now.toLocaleString());
|
||||
|
||||
// Update chart if it exists
|
||||
if (trendChart) {
|
||||
try {
|
||||
// Always update the 24hr average line even if we don't have data points yet
|
||||
const avg24hr = parseFloat(data.hashrate_24hr || 0);
|
||||
if (!isNaN(avg24hr) &&
|
||||
trendChart.options.plugins.annotation &&
|
||||
trendChart.options.plugins.annotation.annotations &&
|
||||
trendChart.options.plugins.annotation.annotations.averageLine) {
|
||||
const annotation = trendChart.options.plugins.annotation.annotations.averageLine;
|
||||
annotation.yMin = avg24hr;
|
||||
annotation.yMax = avg24hr;
|
||||
annotation.label.content = '24hr Avg: ' + avg24hr + ' TH/s';
|
||||
}
|
||||
|
||||
// Update data points if we have any (removed minimum length requirement)
|
||||
if (data.arrow_history && data.arrow_history.hashrate_60sec) {
|
||||
const historyData = data.arrow_history.hashrate_60sec;
|
||||
if (historyData && historyData.length > 0) {
|
||||
console.log(`Updating chart with ${historyData.length} data points`);
|
||||
trendChart.data.labels = historyData.map(item => item.time);
|
||||
trendChart.data.datasets[0].data = historyData.map(item => {
|
||||
const val = parseFloat(item.value);
|
||||
return isNaN(val) ? 0 : val;
|
||||
});
|
||||
} else {
|
||||
console.log("No history data points available yet");
|
||||
}
|
||||
} else {
|
||||
console.log("No hashrate_60sec history available yet");
|
||||
|
||||
// If there's no history data, create a starting point using current hashrate
|
||||
if (data.hashrate_60sec) {
|
||||
const currentTime = new Date().toLocaleTimeString('en-US', {hour12: false, hour: '2-digit', minute: '2-digit'});
|
||||
trendChart.data.labels = [currentTime];
|
||||
trendChart.data.datasets[0].data = [parseFloat(data.hashrate_60sec) || 0];
|
||||
console.log("Created initial data point with current hashrate");
|
||||
}
|
||||
}
|
||||
|
||||
// Always update the chart, even if we just updated the average line
|
||||
trendChart.update('none');
|
||||
} catch (chartError) {
|
||||
console.error("Error updating chart:", chartError);
|
||||
}
|
||||
}
|
||||
|
||||
// Update indicators and check for block updates
|
||||
updateIndicators(data);
|
||||
checkForBlockUpdates(data);
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error updating UI:", error);
|
||||
}
|
||||
}
|
||||
|
||||
// Document ready initialization
|
||||
$(document).ready(function() {
|
||||
// Initialize the chart
|
||||
trendChart = initializeChart();
|
||||
|
||||
// Initialize the progress bar
|
||||
initProgressBar();
|
||||
|
||||
// Set up direct monitoring of data refreshes
|
||||
$(document).on('dataRefreshed', function() {
|
||||
console.log("Data refresh event detected, resetting progress bar");
|
||||
lastUpdateTime = Date.now();
|
||||
currentProgress = 0;
|
||||
updateProgressBar(currentProgress);
|
||||
});
|
||||
|
||||
// Wrap the updateUI function to detect changes and trigger events
|
||||
const originalUpdateUI = updateUI;
|
||||
updateUI = function() {
|
||||
const previousMetricsTimestamp = latestMetrics ? latestMetrics.server_timestamp : null;
|
||||
|
||||
// Call the original function
|
||||
originalUpdateUI.apply(this, arguments);
|
||||
|
||||
// Check if we got new data by comparing timestamps
|
||||
if (latestMetrics && latestMetrics.server_timestamp !== previousMetricsTimestamp) {
|
||||
console.log("New data detected, triggering refresh event");
|
||||
$(document).trigger('dataRefreshed');
|
||||
}
|
||||
};
|
||||
|
||||
// Set up event source for SSE
|
||||
setupEventSource();
|
||||
|
||||
// Start server time polling
|
||||
updateServerTime();
|
||||
setInterval(updateServerTime, 30000);
|
||||
|
||||
// Start uptime timer
|
||||
setInterval(updateUptime, 1000);
|
||||
updateUptime();
|
||||
|
||||
// Add a manual refresh button for fallback
|
||||
$("body").append('<button id="refreshButton" style="position: fixed; bottom: 20px; left: 20px; z-index: 1000; background: #f7931a; color: black; border: none; padding: 8px 16px; display: none; border-radius: 4px; cursor: pointer;">Refresh Data</button>');
|
||||
|
||||
$("#refreshButton").on("click", function() {
|
||||
$(this).text("Refreshing...");
|
||||
$(this).prop("disabled", true);
|
||||
manualRefresh();
|
||||
setTimeout(function() {
|
||||
$("#refreshButton").text("Refresh Data");
|
||||
$("#refreshButton").prop("disabled", false);
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
// Force a data refresh when the page loads
|
||||
manualRefresh();
|
||||
|
||||
// Add emergency refresh button functionality
|
||||
$("#forceRefreshBtn").show().on("click", function() {
|
||||
$(this).text("Refreshing...");
|
||||
$(this).prop("disabled", true);
|
||||
|
||||
$.ajax({
|
||||
url: '/api/force-refresh',
|
||||
method: 'POST',
|
||||
timeout: 15000,
|
||||
success: function(data) {
|
||||
console.log("Force refresh successful:", data);
|
||||
manualRefresh(); // Immediately get the new data
|
||||
$("#forceRefreshBtn").text("Force Refresh").prop("disabled", false);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error("Force refresh failed:", error);
|
||||
$("#forceRefreshBtn").text("Force Refresh").prop("disabled", false);
|
||||
alert("Refresh failed: " + error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Add stale data detection
|
||||
setInterval(function() {
|
||||
if (latestMetrics && latestMetrics.server_timestamp) {
|
||||
const lastUpdate = new Date(latestMetrics.server_timestamp);
|
||||
const timeSinceUpdate = Math.floor((Date.now() - lastUpdate.getTime()) / 1000);
|
||||
if (timeSinceUpdate > 120) { // More than 2 minutes
|
||||
showConnectionIssue(`Data stale (${timeSinceUpdate}s old). Use Force Refresh.`);
|
||||
$("#forceRefreshBtn").show();
|
||||
}
|
||||
}
|
||||
}, 30000); // Check every 30 seconds
|
||||
});
|
76
minify.py
Normal file
76
minify.py
Normal file
@ -0,0 +1,76 @@
|
||||
import os
|
||||
import htmlmin
|
||||
import logging
|
||||
|
||||
# Set up logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
TEMPLATES_DIR = "templates"
|
||||
HTML_FILES = ["index.html", "error.html"]
|
||||
|
||||
def minify_html_file(file_path):
|
||||
"""
|
||||
Minify an HTML file with error handling
|
||||
"""
|
||||
try:
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
# Check if file has content
|
||||
if not content.strip():
|
||||
logging.warning(f"File {file_path} is empty. Skipping.")
|
||||
return
|
||||
|
||||
# Minify the content
|
||||
try:
|
||||
minified = htmlmin.minify(content,
|
||||
remove_comments=True,
|
||||
remove_empty_space=True,
|
||||
remove_all_empty_space=False,
|
||||
reduce_boolean_attributes=True)
|
||||
|
||||
# Make sure minification worked and didn't remove everything
|
||||
if not minified.strip():
|
||||
logging.error(f"Minification of {file_path} resulted in empty content. Using original.")
|
||||
minified = content
|
||||
|
||||
# Write back the minified content
|
||||
with open(file_path, "w", encoding="utf-8") as f:
|
||||
f.write(minified)
|
||||
|
||||
logging.info(f"Minified {file_path}")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"Error minifying {file_path}: {e}")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"Error reading file {file_path}: {e}")
|
||||
|
||||
def ensure_templates_dir():
|
||||
"""
|
||||
Ensure templates directory exists
|
||||
"""
|
||||
if not os.path.exists(TEMPLATES_DIR):
|
||||
try:
|
||||
os.makedirs(TEMPLATES_DIR)
|
||||
logging.info(f"Created templates directory: {TEMPLATES_DIR}")
|
||||
except Exception as e:
|
||||
logging.error(f"Error creating templates directory: {e}")
|
||||
return False
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.info("Starting HTML minification process")
|
||||
|
||||
if not ensure_templates_dir():
|
||||
logging.error("Templates directory does not exist and could not be created. Exiting.")
|
||||
exit(1)
|
||||
|
||||
for filename in HTML_FILES:
|
||||
file_path = os.path.join(TEMPLATES_DIR, filename)
|
||||
if os.path.exists(file_path):
|
||||
minify_html_file(file_path)
|
||||
else:
|
||||
logging.warning(f"File {file_path} not found.")
|
||||
|
||||
logging.info("HTML minification process completed")
|
9
requirements.txt
Normal file
9
requirements.txt
Normal file
@ -0,0 +1,9 @@
|
||||
Flask==2.3.3
|
||||
requests==2.31.0
|
||||
beautifulsoup4==4.12.2
|
||||
Flask-Caching==2.1.0
|
||||
gunicorn==22.0.0
|
||||
htmlmin==0.1.12
|
||||
redis==5.0.1
|
||||
APScheduler==3.10.4
|
||||
psutil==5.9.5
|
Loading…
Reference in New Issue
Block a user