mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Implement paper builds using mineacademy API
Big shoutout to zed for fnding this
This commit is contained in:
parent
1d32afa09d
commit
e274b0c677
@ -11,12 +11,14 @@ from app.classes.models.server_permissions import PermissionsServers
|
|||||||
from app.classes.shared.websocket_manager import WebSocketManager
|
from app.classes.shared.websocket_manager import WebSocketManager
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
MINEACADEMYJARS = ["paper", "folia"]
|
||||||
|
|
||||||
|
|
||||||
class ServerJars:
|
class ServerJars:
|
||||||
def __init__(self, helper):
|
def __init__(self, helper):
|
||||||
self.helper = helper
|
self.helper = helper
|
||||||
self.base_url = "https://serverjars.com"
|
self.base_url = "https://serverjars.com"
|
||||||
|
self.academy = "https://mineacademy.org"
|
||||||
|
|
||||||
def _get_api_result(self, call_url: str):
|
def _get_api_result(self, call_url: str):
|
||||||
full_url = f"{self.base_url}{call_url}"
|
full_url = f"{self.base_url}{call_url}"
|
||||||
@ -38,6 +40,23 @@ class ServerJars:
|
|||||||
|
|
||||||
return api_response
|
return api_response
|
||||||
|
|
||||||
|
def get_paper_versions(self, project):
|
||||||
|
try:
|
||||||
|
response = requests.get(
|
||||||
|
f"https://api.papermc.io/v2/projects/{project}/", timeout=2
|
||||||
|
)
|
||||||
|
response.raise_for_status()
|
||||||
|
api_data = json.loads(response.content)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(
|
||||||
|
f"Unable to load https://api.papermc.io/v2/projects/{project}/"
|
||||||
|
f"api due to error: {e}"
|
||||||
|
)
|
||||||
|
return {}
|
||||||
|
versions = api_data.get("versions", [])
|
||||||
|
versions.reverse()
|
||||||
|
return versions
|
||||||
|
|
||||||
def _read_cache(self):
|
def _read_cache(self):
|
||||||
cache_file = self.helper.serverjar_cache
|
cache_file = self.helper.serverjar_cache
|
||||||
cache = {}
|
cache = {}
|
||||||
@ -95,6 +114,8 @@ class ServerJars:
|
|||||||
for j in data["types"].get(s):
|
for j in data["types"].get(s):
|
||||||
versions = self._get_jar_details(j, s)
|
versions = self._get_jar_details(j, s)
|
||||||
data["types"][s].update({j: versions})
|
data["types"][s].update({j: versions})
|
||||||
|
for item in MINEACADEMYJARS:
|
||||||
|
data["types"]["servers"][item] = self.get_paper_versions(item)
|
||||||
# save our cache
|
# save our cache
|
||||||
try:
|
try:
|
||||||
with open(cache_file, "w", encoding="utf-8") as f:
|
with open(cache_file, "w", encoding="utf-8") as f:
|
||||||
@ -133,6 +154,8 @@ class ServerJars:
|
|||||||
for j in data["types"].get(s):
|
for j in data["types"].get(s):
|
||||||
versions = self._get_jar_details(j, s)
|
versions = self._get_jar_details(j, s)
|
||||||
data["types"][s].update({j: versions})
|
data["types"][s].update({j: versions})
|
||||||
|
for item in MINEACADEMYJARS:
|
||||||
|
data["types"]["servers"][item] = self.get_paper_versions()
|
||||||
# save our cache
|
# save our cache
|
||||||
try:
|
try:
|
||||||
with open(cache_file, "w", encoding="utf-8") as f:
|
with open(cache_file, "w", encoding="utf-8") as f:
|
||||||
@ -171,7 +194,12 @@ class ServerJars:
|
|||||||
def a_download_jar(self, jar, server, version, path, server_id):
|
def a_download_jar(self, jar, server, version, path, server_id):
|
||||||
# delaying download for server register to finish
|
# delaying download for server register to finish
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
fetch_url = f"{self.base_url}/api/fetchJar/{jar}/{server}/{version}"
|
if server not in MINEACADEMYJARS:
|
||||||
|
fetch_url = f"{self.base_url}/api/fetchJar/{jar}/{server}/{version}"
|
||||||
|
else:
|
||||||
|
fetch_url = (
|
||||||
|
f"https://mineacademy.org/api/{server}/{str(version).replace('.', '_')}"
|
||||||
|
)
|
||||||
server_users = PermissionsServers.get_server_user_list(server_id)
|
server_users = PermissionsServers.get_server_user_list(server_id)
|
||||||
|
|
||||||
# We need to make sure the server is registered before
|
# We need to make sure the server is registered before
|
||||||
|
Loading…
Reference in New Issue
Block a user