Compare commits

...

1 commit
v0.2 ... main

Author SHA1 Message Date
8ea8fd3567 Manager modów/pluginów pobiera zależności 2025-04-14 19:06:02 +02:00
2 changed files with 71 additions and 38 deletions

View file

@ -330,31 +330,64 @@ def download_mod():
server_version = data['version']
base_path = f"./servers/mc-{username}/{'plugins' if server_type == 'paper' else 'mods'}"
os.makedirs(base_path, exist_ok=True)
downloaded = []
downloaded_files = []
visited_versions = set()
def download_project(pid, version_id=None):
if version_id:
version_data = requests.get(f"https://api.modrinth.com/v2/version/{version_id}").json()
else:
all_versions = requests.get(f"https://api.modrinth.com/v2/project/{pid}/version").json()
version_data = next((v for v in all_versions if server_version in v['game_versions'] and server_type in v['loaders']), None)
version_data = next(
(v for v in all_versions
if server_version in v['game_versions']
and server_type in v['loaders']
and v.get('server_side') != 'unsupported'),
None)
if not version_data:
print(f"[SKIP] No compatible version found for {pid}")
return
file = version_data['files'][0]
file_path = f"{base_path}/{file['filename']}"
if file['filename'] not in downloaded:
if version_data["id"] in visited_versions:
return
visited_versions.add(version_data["id"])
if version_data.get('server_side') == 'unsupported':
print(f"[SKIP] {version_data.get('name', 'Nieznana nazwa')} is client-only")
return
file = next((f for f in version_data['files'] if f.get('primary', True)), version_data['files'][0])
file_path = os.path.join(base_path, file['filename'])
if not os.path.exists(file_path):
print(f"[DOWNLOAD] {file['filename']}")
with requests.get(file['url'], stream=True) as r:
with open(file_path, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
downloaded.append(file['filename'])
downloaded_files.append({
"filename": file['filename'],
"name": version_data.get("name") or version_data.get("version_number") or "Nieznana wersja",
"project_id": version_data["project_id"],
"version_id": version_data["id"]
})
for dep in version_data.get('dependencies', []):
if dep.get('version_id'):
try:
download_project(dep['project_id'], dep['version_id'])
except Exception as e:
print(f"[ERROR] Failed to fetch dep version {dep['version_id']}: {e}")
elif dep.get('project_id'):
try:
download_project(dep['project_id'])
except Exception as e:
print(f"[ERROR] Failed to fetch dep project {dep['project_id']}: {e}")
download_project(project_id)
return jsonify({"success": True, "downloaded": downloaded})
return jsonify({"success": True, "downloaded": downloaded_files})

View file

@ -36,7 +36,6 @@ function installMod(projectId) {
fetch('/api/config')
.then(response => response.json())
.then(configData => {
console.log(configData);
if (configData.success) {
const serverType = configData.type;
const serverVersion = configData.version;
@ -49,7 +48,8 @@ function installMod(projectId) {
.then(r => r.json())
.then(data => {
if (data.success) {
alert(`Zainstalowano: ${data.file}`);
const modFiles = data.downloaded.map(mod => "- " + mod.filename).join("\n");
alert(`Zainstalowano:\n${modFiles}`);
loadFileList();
} else {
alert("Nie udało się zainstalować moda.");