mirror of
https://github.com/hubHarmony/servii-backend.git
synced 2024-11-17 21:40:31 +00:00
[+] Implemented new FetchDirContent API call :)
This commit is contained in:
parent
0fc0c1cdd2
commit
984a2a9acd
@ -120,36 +120,25 @@ def fetch_players_status(user: UserRecord, name: str) -> tuple[HTTPStatus, Union
|
||||
file_manager.log_error(type(e).__name__, str(e))
|
||||
return HTTPStatus.INTERNAL_SERVER_ERROR, "Unknown error."
|
||||
|
||||
def fetch_file_names(user: UserRecord, name: str) -> tuple[HTTPStatus, Union[dict[str, list[str]], str]]:
|
||||
|
||||
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}"
|
||||
plugins_dir: str = f"{server_path}/plugins"
|
||||
datapacks_dir: str = f"{server_path}/world/datapacks"
|
||||
|
||||
file_names = {
|
||||
"plugins": [],
|
||||
"datapacks": []
|
||||
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:
|
||||
#plugins
|
||||
if os.path.exists(plugins_dir):
|
||||
file_names["plugins"] = os.listdir(plugins_dir)
|
||||
else:
|
||||
return HTTPStatus.NOT_FOUND, f"Plugins directory not found for server '{name}'."
|
||||
|
||||
#datapacks
|
||||
if os.path.exists(datapacks_dir):
|
||||
file_names["datapacks"] = os.listdir(datapacks_dir)
|
||||
else:
|
||||
return HTTPStatus.NOT_FOUND, f"Datapacks directory not found for server '{name}'."
|
||||
|
||||
return HTTPStatus.OK, file_names
|
||||
|
||||
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 file names: {str(e)}"
|
||||
|
||||
return HTTPStatus.INTERNAL_SERVER_ERROR, f"Error fetching files for server {name}"
|
||||
|
||||
|
||||
def account_create(user: UserRecord) -> tuple[HTTPStatus, Union[str, None]]:
|
||||
|
Loading…
Reference in New Issue
Block a user