mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-09-24 18:31:43 +01:00
@@ -153,6 +153,15 @@ if DEBUG:
|
||||
logger.error_trace(f"Debug endpoint error: {e}")
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
if DEBUG:
|
||||
@app.route('/api/restart', methods=['GET'])
|
||||
@login_required
|
||||
def restart() -> Union[Response, Tuple[Response, int]]:
|
||||
"""
|
||||
Restart the application
|
||||
"""
|
||||
os._exit(0)
|
||||
|
||||
@app.route('/api/search', methods=['GET'])
|
||||
@login_required
|
||||
def api_search() -> Union[Response, Tuple[Response, int]]:
|
||||
|
||||
@@ -32,6 +32,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
form: document.getElementById('debug-form'),
|
||||
button: document.getElementById('debug-button'),
|
||||
spinner: document.getElementById('debug-spinner')
|
||||
},
|
||||
restart: {
|
||||
form: document.getElementById('restart-form'),
|
||||
button: document.getElementById('restart-button'),
|
||||
spinner: document.getElementById('restart-spinner')
|
||||
}
|
||||
};
|
||||
|
||||
@@ -753,6 +758,49 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Restart Functions
|
||||
const restart = {
|
||||
init() {
|
||||
if (!elements.restart.form) return;
|
||||
|
||||
elements.restart.form.addEventListener('submit', (e) => {
|
||||
e.preventDefault(); // Prevent default form submission
|
||||
|
||||
if (elements.restart.button.disabled) {
|
||||
return; // Prevent multiple submissions
|
||||
}
|
||||
|
||||
// Show confirmation dialog
|
||||
UIkit.modal.confirm('Are you sure you want to restart the application? This will interrupt any ongoing downloads.').then(() => {
|
||||
// User confirmed, proceed with restart
|
||||
elements.restart.spinner.classList.remove('uk-hidden');
|
||||
elements.restart.button.disabled = true;
|
||||
|
||||
// Show restarting message
|
||||
UIkit.notification({
|
||||
message: 'Application restarting...',
|
||||
status: 'warning',
|
||||
pos: 'top-center',
|
||||
timeout: 5000
|
||||
});
|
||||
|
||||
// Make the restart request - this will kill the server
|
||||
fetch(elements.restart.form.action)
|
||||
.catch(() => {
|
||||
// Expected to fail when server shuts down
|
||||
});
|
||||
|
||||
// Wait a bit then refresh the page to reconnect to the restarted server
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 3000);
|
||||
}, () => {
|
||||
// User cancelled, do nothing
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Event Listeners
|
||||
function setupEventListeners() {
|
||||
// Search events
|
||||
@@ -830,6 +878,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
setupEventListeners();
|
||||
theme.init(); // Initialize theme management
|
||||
debug.init(); // Initialize debug functionality
|
||||
restart.init(); // Initialize restart functionality
|
||||
status.fetch();
|
||||
setInterval(() => status.fetch(), REFRESH_INTERVAL);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
<h1 class="uk-heading-medium" style="color: white;">Book Search & Download</h1>
|
||||
<div class="uk-margin-right">
|
||||
{% if debug %}
|
||||
<form action="/api/restart" method="get" style="display: inline;" id="restart-form">
|
||||
<button class="uk-button uk-button-danger uk-margin-small-right" id="restart-button" type="submit">
|
||||
RESTART <span uk-spinner="ratio: 0.8" class="uk-hidden" id="restart-spinner"></span>
|
||||
</button>
|
||||
</form>
|
||||
<form action="/debug" method="get" style="display: inline;" id="debug-form">
|
||||
<button class="uk-button uk-button-danger uk-margin-small-right" id="debug-button" type="submit">
|
||||
DEBUG <span uk-spinner="ratio: 0.8" class="uk-hidden" id="debug-spinner"></span>
|
||||
|
||||
Reference in New Issue
Block a user