mirror of
https://github.com/hubHarmony/servii-backend.git
synced 2024-11-17 21:40:31 +00:00
Merge branch 'master' into plugin-management-system
This commit is contained in:
commit
a935792c24
@ -81,6 +81,7 @@
|
|||||||
<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>
|
<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="FetchPlayersStatus">Fetch Players Status</button>
|
||||||
|
<button type="button" class="actionButton" data-action="FetchDirContent">Fetch Directory Content</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<h2>Update Property</h2>
|
<h2>Update Property</h2>
|
||||||
@ -105,10 +106,6 @@
|
|||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
const uploadForm = document.getElementById('uploadForm');
|
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');
|
const messageDiv = document.getElementById('message');
|
||||||
|
|
||||||
// File Upload functionality
|
// File Upload functionality
|
||||||
@ -183,6 +180,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
case 'FetchPlayersStatus':
|
case 'FetchPlayersStatus':
|
||||||
data = {token, name};
|
data = {token, name};
|
||||||
break;
|
break;
|
||||||
|
case 'FetchDirContent':
|
||||||
|
data = {token, name};
|
||||||
|
break;
|
||||||
case 'AccountCreate':
|
case 'AccountCreate':
|
||||||
data = {email, port, token};
|
data = {email, port, token};
|
||||||
break;
|
break;
|
||||||
|
1
app.py
1
app.py
@ -92,6 +92,7 @@ route_handlers = {
|
|||||||
'FetchLogs': generic_executor.fetch_logs,
|
'FetchLogs': generic_executor.fetch_logs,
|
||||||
'FetchHistory': generic_executor.fetch_history,
|
'FetchHistory': generic_executor.fetch_history,
|
||||||
'FetchPlayersStatus': generic_executor.fetch_players_status,
|
'FetchPlayersStatus': generic_executor.fetch_players_status,
|
||||||
|
'FetchDirContent': generic_executor.fetch_dir_content,
|
||||||
'AccountCreate': generic_executor.account_create,
|
'AccountCreate': generic_executor.account_create,
|
||||||
'AccountDelete': generic_executor.account_delete,
|
'AccountDelete': generic_executor.account_delete,
|
||||||
'ServerCreate': generic_executor.server_create,
|
'ServerCreate': generic_executor.server_create,
|
||||||
|
@ -2,8 +2,8 @@ import datetime
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
|
|
||||||
supported_versions = ["bukkit", "paper", "spigot"]
|
supported_versions = ["bukkit", "paper", "spigot"]
|
||||||
|
|
||||||
@ -102,6 +102,15 @@ def get_path_from_extension(filename) -> str or None:
|
|||||||
return 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:
|
def kebab_to_camel_case(s: str) -> str:
|
||||||
parts = s.split('-')
|
parts = s.split('-')
|
||||||
return parts[0] + ''.join(part.title() for part in parts[1:])
|
return parts[0] + ''.join(part.title() for part in parts[1:])
|
||||||
|
@ -121,6 +121,26 @@ def fetch_players_status(user: UserRecord, name: str) -> tuple[HTTPStatus, Union
|
|||||||
return HTTPStatus.INTERNAL_SERVER_ERROR, "Unknown error."
|
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]]:
|
def account_create(user: UserRecord) -> tuple[HTTPStatus, Union[str, None]]:
|
||||||
if firebase_manager.user_field_exists(user.uid):
|
if firebase_manager.user_field_exists(user.uid):
|
||||||
return HTTPStatus.FORBIDDEN, "User already exists."
|
return HTTPStatus.FORBIDDEN, "User already exists."
|
||||||
|
32
unit_test.py
32
unit_test.py
@ -1,5 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
import file_manager
|
||||||
import firebase_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__)
|
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__':
|
if __name__ == '__main__':
|
||||||
#ban_user("MpkbDMOO8PQddQgB5VgBQdTMWF53")
|
#ban_user("MpkbDMOO8PQddQgB5VgBQdTMWF53")
|
||||||
#file_manager.log_action("gqZN3eCHF3V2er3Py3rlgk8u2t83", "test", "DeleteServer")
|
#file_manager.log_action("gqZN3eCHF3V2er3Py3rlgk8u2t83", "test", "DeleteServer")
|
||||||
#firebase_manager.set_servers_not_running()
|
#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))
|
||||||
|
Loading…
Reference in New Issue
Block a user