added remove miner functionality
This commit is contained in:
@@ -5,8 +5,8 @@ import os
|
||||
import asyncio
|
||||
import uvicorn
|
||||
import websockets.exceptions
|
||||
from fastapi import FastAPI
|
||||
from fastapi import Request
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import RedirectResponse
|
||||
from fastapi import WebSocket, WebSocketDisconnect
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
@@ -46,7 +46,7 @@ async def dashboard_websocket(websocket: WebSocket):
|
||||
all_miner_data.sort(key=lambda x: x["ip"])
|
||||
await websocket.send_json({"datetime": datetime.datetime.now().isoformat(),
|
||||
"miners": all_miner_data})
|
||||
await asyncio.sleep(.1)
|
||||
await asyncio.sleep(1)
|
||||
except WebSocketDisconnect:
|
||||
print("Websocket disconnected.")
|
||||
pass
|
||||
@@ -180,6 +180,18 @@ def get_miner(request: Request, miner_ip):
|
||||
})
|
||||
|
||||
|
||||
@app.get("/miner/{miner_ip}/remove")
|
||||
def get_miner(request: Request, miner_ip):
|
||||
miners = get_current_miner_list()
|
||||
miners.remove(miner_ip)
|
||||
with open("miner_list.txt", "w") as file:
|
||||
for miner in miners:
|
||||
file.write(miner + "\n")
|
||||
|
||||
return RedirectResponse(request.url_for('dashboard'))
|
||||
|
||||
|
||||
|
||||
def get_current_miner_list():
|
||||
cur_miners = []
|
||||
if os.path.exists(os.path.join(os.getcwd(), "miner_list.txt")):
|
||||
|
||||
@@ -8,7 +8,28 @@
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="d-flex flex-row-reverse">
|
||||
<a class="btn btn-outline-danger mx-1" href="#" role="button">Remove</a>
|
||||
<button type="button" class="btn btn-outline-danger mx-1" data-bs-toggle="modal" data-bs-target="#removeModal">
|
||||
Remove Miner
|
||||
</button>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="removeModal" tabindex="-1" aria-labelledby="removeModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="removeModalLabel">Remove Miner</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Do you really want to remove this miner?
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<a class="btn btn-danger" href="{{url_for('miner')}}/{{miner}}/remove" role="button">Remove</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<a class="btn btn-primary mx-1" target="_blank" href="http://{{miner}}" role="button">Web Interface</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user