Merge branch 'master' into plugin-management-system

This commit is contained in:
Charles Le Maux 2024-09-12 12:37:18 +02:00
commit a935792c24
5 changed files with 40 additions and 32 deletions

View File

@ -81,6 +81,7 @@
<button type="button" class="actionButton" data-action="FetchServers">Fetch Servers</button>
<button type="button" class="actionButton" data-action="FetchLogs">Fetch Logs</button>
<button type="button" class="actionButton" data-action="FetchPlayersStatus">Fetch Players Status</button>
<button type="button" class="actionButton" data-action="FetchDirContent">Fetch Directory Content</button>
</form>
<h2>Update Property</h2>
@ -105,10 +106,6 @@
<script>
document.addEventListener('DOMContentLoaded', () => {
const uploadForm = document.getElementById('uploadForm');
const genericForm = document.getElementById('genericForm');
const updatePropertyForm = document.getElementById('updatePropertyForm');
const sendCommandForm = document.getElementById('sendCommandForm');
const setSubdomainForm = document.getElementById('setSubdomainForm');
const messageDiv = document.getElementById('message');
// File Upload functionality
@ -183,6 +180,9 @@ document.addEventListener('DOMContentLoaded', () => {
case 'FetchPlayersStatus':
data = {token, name};
break;
case 'FetchDirContent':
data = {token, name};
break;
case 'AccountCreate':
data = {email, port, token};
break;

1
app.py
View File

@ -92,6 +92,7 @@ route_handlers = {
'FetchLogs': generic_executor.fetch_logs,
'FetchHistory': generic_executor.fetch_history,
'FetchPlayersStatus': generic_executor.fetch_players_status,
'FetchDirContent': generic_executor.fetch_dir_content,
'AccountCreate': generic_executor.account_create,
'AccountDelete': generic_executor.account_delete,
'ServerCreate': generic_executor.server_create,

View File

@ -2,8 +2,8 @@ import datetime
import json
import logging
import os
import shutil
import re
import shutil
supported_versions = ["bukkit", "paper", "spigot"]
@ -102,6 +102,15 @@ def get_path_from_extension(filename) -> str or None:
return None
def filter_directory_contents(desired_extension: str, directory_contents: list[str]):
filtered_list = []
for item in directory_contents:
_, ext = os.path.splitext(item)
if ext.lower() == desired_extension:
filtered_list.append(item)
return filtered_list
def kebab_to_camel_case(s: str) -> str:
parts = s.split('-')
return parts[0] + ''.join(part.title() for part in parts[1:])

View File

@ -121,6 +121,26 @@ def fetch_players_status(user: UserRecord, name: str) -> tuple[HTTPStatus, Union
return HTTPStatus.INTERNAL_SERVER_ERROR, "Unknown error."
def fetch_dir_content(user: UserRecord, name: str) -> tuple[HTTPStatus, Union[str, list]]:
user_id: str = user.uid
server_path: str = f"users/{user_id}/{name}/"
dirs: dict[str, [str, str]] = {
'plugins': ['plugins', '.jar'],
'datapack' : ['world/datapacks', '.zip'],
}
files: list[dict[str, list[str]]] = []
try:
for key, (path, extension) in dirs.items():
final_path = f"{server_path}/{path}"
if os.path.exists(final_path):
parsed_content = file_manager.filter_directory_contents( extension, os.listdir(final_path))
files.append({key: parsed_content})
return HTTPStatus.OK, files
except Exception as e:
file_manager.log_error(type(e).__name__, str(e))
return HTTPStatus.INTERNAL_SERVER_ERROR, f"Error fetching files for server {name}"
def account_create(user: UserRecord) -> tuple[HTTPStatus, Union[str, None]]:
if firebase_manager.user_field_exists(user.uid):
return HTTPStatus.FORBIDDEN, "User already exists."

View File

@ -1,5 +1,7 @@
import asyncio
import os
import file_manager
import firebase_manager
@ -11,34 +13,10 @@ def ban_user(user_id: str):
print("Error banning user " + user_id, "|", str(e), type(e).__name__)
async def one() -> int:
return 1
async def two() -> int:
await asyncio.sleep(2)
return 2
async def three() -> int:
await asyncio.sleep(3)
return 3
coroutines = [
one(),
two(),
three()
]
async def main() -> None:
results = await asyncio.gather(*coroutines)
#for result in results:
# print(result)
print(f"0: {results[0]}")
print(f"1: {results[1]}")
print(f"2: {results[2]}")
if __name__ == '__main__':
#ban_user("MpkbDMOO8PQddQgB5VgBQdTMWF53")
#file_manager.log_action("gqZN3eCHF3V2er3Py3rlgk8u2t83", "test", "DeleteServer")
#firebase_manager.set_servers_not_running()
asyncio.run(main())
current_dir_content: list[str] = os.listdir(".")
parsed_extension: str = '.py'
print(file_manager.filter_directory_contents(parsed_extension, current_dir_content))