[+] New 'FetchLogs' API call

[+] New 'FetchLogs' API call
This commit is contained in:
charleslemaux 2024-08-15 12:08:45 +02:00 committed by GitHub
commit 66d6483f46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 2 deletions

View File

@ -12,7 +12,7 @@
Port: <label for="accountPort"></label><input type="number" id="accountPort"><br> Port: <label for="accountPort"></label><input type="number" id="accountPort"><br>
Name: <label for="serverName"></label><input type="text" id="serverName"><br> Name: <label for="serverName"></label><input type="text" id="serverName"><br>
Version: <label for="serverVersion"></label><input type="text" id="serverVersion"><br> Version: <label for="serverVersion"></label><input type="text" id="serverVersion"><br>
Framework: <label for="serverVersion"></label><input type="text" id="serverFramework"><br> Framework: <label for="serverFramework"></label><input type="text" id="serverFramework"><br>
<button type="button" class="actionButton" data-action="AccountCreate">Create Account</button> <button type="button" class="actionButton" data-action="AccountCreate">Create Account</button>
<button type="button" class="actionButton" data-action="AccountDelete">Delete Account</button> <button type="button" class="actionButton" data-action="AccountDelete">Delete Account</button>
<button type="button" class="actionButton" data-action="ServerCreate">Create Server</button> <button type="button" class="actionButton" data-action="ServerCreate">Create Server</button>
@ -20,6 +20,8 @@
<button type="button" class="actionButton" data-action="ServerRun">Start Server</button> <button type="button" class="actionButton" data-action="ServerRun">Start Server</button>
<button type="button" class="actionButton" data-action="ServerStop">Stop Server</button> <button type="button" class="actionButton" data-action="ServerStop">Stop Server</button>
<button type="button" class="actionButton" data-action="FetchServers">Fetch Servers</button> <button type="button" class="actionButton" data-action="FetchServers">Fetch Servers</button>
<button type="button" class="actionButton" data-action="FetchLogs">Fetch Logs</button>
</form> </form>
<h2>Update Property</h2> <h2>Update Property</h2>
@ -64,6 +66,9 @@ document.addEventListener('DOMContentLoaded', () => {
case 'FetchServers': case 'FetchServers':
data = {token}; data = {token};
break; break;
case 'FetchLogs':
data = {token, name};
break;
case 'AccountCreate': case 'AccountCreate':
data = {email, port, token}; data = {email, port, token};
break; break;

1
app.py
View File

@ -81,6 +81,7 @@ def parse_and_validate_request(parameters: list[str]) -> Union[list[str], None]:
route_handlers = { route_handlers = {
'SetSubdomain': generic_executor.set_subdomain, 'SetSubdomain': generic_executor.set_subdomain,
'FetchServers': generic_executor.fetch_servers, 'FetchServers': generic_executor.fetch_servers,
'FetchLogs': generic_executor.fetch_logs,
'AccountCreate': generic_executor.account_create, 'AccountCreate': generic_executor.account_create,
'ServerCreate': generic_executor.server_create, 'ServerCreate': generic_executor.server_create,
'ServerDelete': generic_executor.server_delete, 'ServerDelete': generic_executor.server_delete,

View File

@ -68,7 +68,16 @@ def fetch_servers(user: UserRecord) -> tuple[HTTPStatus, Union[str, list]]:
def fetch_logs(user: UserRecord, name: str) -> tuple[HTTPStatus, Union[str, None]]: def fetch_logs(user: UserRecord, name: str) -> tuple[HTTPStatus, Union[str, None]]:
pass user_id: str = user.uid
lines_to_read: int = 200
log_file = f"users/{user_id}/{name}/logs/latest.log"
try:
with open(log_file, "r") as f:
logs = f.readlines()[-lines_to_read:]
text_logs = f.read()
return HTTPStatus.OK, str(logs)
except FileNotFoundError:
return HTTPStatus.NOT_FOUND, "Log file not found."
def account_create(user: UserRecord) -> tuple[HTTPStatus, Union[str, None]]: def account_create(user: UserRecord) -> tuple[HTTPStatus, Union[str, None]]: