From 40bddd1449484986f22983d7d5d62f9606042ad4 Mon Sep 17 00:00:00 2001 From: ilyastar9999 Date: Thu, 4 Dec 2025 14:41:44 +0300 Subject: [PATCH] ads --- web/app.py | 27 ++++++++++++++ web/templates/services.html | 72 +++++++++++++++++++++++++++++++++++-- 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/web/app.py b/web/app.py index b844415..cfd3b17 100644 --- a/web/app.py +++ b/web/app.py @@ -138,6 +138,33 @@ def api_service_action(service_id): finally: loop.close() +@app.route('/api/services//update', methods=['PATCH']) +@login_required +def api_service_update(service_id): + """Update service (e.g., alias)""" + updates = request.json + + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + + try: + async def patch_call(): + headers = {"Authorization": f"Bearer {SECRET_TOKEN}"} + async with aiohttp.ClientSession() as session: + async with session.patch( + f"{CONTROLLER_API}/services/{service_id}", + headers=headers, + json=updates + ) as resp: + if resp.status == 200: + return await resp.json() + return {"error": f"Status {resp.status}"} + + data = loop.run_until_complete(patch_call()) + return jsonify(data) + finally: + loop.close() + @app.route('/api/services//logs') @login_required def api_service_logs(service_id): diff --git a/web/templates/services.html b/web/templates/services.html index 8fd47fb..7584f03 100644 --- a/web/templates/services.html +++ b/web/templates/services.html @@ -18,6 +18,7 @@ Name + Alias Path Status Last Updated @@ -26,7 +27,7 @@ - Loading... + Loading... @@ -51,6 +52,38 @@ + + + {% endblock %} {% block extra_js %} @@ -64,14 +97,22 @@ ? 'Running' : 'Stopped'; + let aliasDisplay = service.alias + ? `${service.alias}` + : 'Not set'; + html += ` ${service.name} + ${aliasDisplay} ${service.path} ${statusBadge} ${new Date(service.last_updated).toLocaleString()}
+ @@ -91,7 +132,7 @@ }); $('#servicesTable').html(html); } else { - $('#servicesTable').html('No services registered'); + $('#servicesTable').html('No services registered'); } }); } @@ -121,6 +162,33 @@ }); } + function editAlias(serviceId, serviceName, currentAlias) { + $('#editServiceId').val(serviceId); + $('#editServiceName').val(serviceName); + $('#editServiceAlias').val(currentAlias); + new bootstrap.Modal(document.getElementById('editAliasModal')).show(); + } + + function saveAlias() { + const serviceId = $('#editServiceId').val(); + const alias = $('#editServiceAlias').val().trim(); + + $.ajax({ + url: `/api/services/${serviceId}/update`, + method: 'PATCH', + contentType: 'application/json', + data: JSON.stringify({ alias: alias }), + success: function (data) { + alert('Alias updated successfully!'); + bootstrap.Modal.getInstance(document.getElementById('editAliasModal')).hide(); + loadServices(); + }, + error: function (xhr) { + alert(`Failed to update alias: ${xhr.responseJSON?.detail || 'Unknown error'}`); + } + }); + } + $(document).ready(function () { loadServices(); $('#refreshServices').click(loadServices);