minor fixes

This commit is contained in:
SashegDev
2026-06-07 16:36:50 +03:00
parent ec7ef01760
commit b493b3278b
15 changed files with 138 additions and 106 deletions
+12 -12
View File
@@ -5,6 +5,8 @@ from pathlib import Path
import json
from typing import Optional, Dict
import structlog
import asyncio
import aiofiles
from models import PackMeta, FileEntry
@@ -33,9 +35,9 @@ def calculate_sha256_sync(file_path: Path) -> str:
return hash_sha.hexdigest()
async def calculate_sha256(file_path: Path) -> str:
"""Calculate SHA256 hash of a file (async wrapper)"""
# Используем синхронную версию для простоты
return calculate_sha256_sync(file_path)
"""Calculate SHA256 hash of a file (async)"""
loop = asyncio.get_running_loop()
return await loop.run_in_executor(None, calculate_sha256_sync, file_path)
async def scan_pack(pack_name: str, force_rescan: bool = False) -> PackMeta:
"""Scan pack directory and update manifest if needed"""
@@ -51,11 +53,11 @@ async def scan_pack(pack_name: str, force_rescan: bool = False) -> PackMeta:
if not force_rescan and pack_name in _manifest_cache:
return _manifest_cache[pack_name]
# Load existing meta if available (синхронно)
# Load existing meta if available
if meta_path.exists():
try:
with open(meta_path, 'r', encoding='utf-8') as f:
data = json.load(f)
async with aiofiles.open(meta_path, 'r', encoding='utf-8') as f:
data = json.loads(await f.read())
current_meta = PackMeta.model_validate(data)
except Exception as e:
logger.warning(f"Failed to load existing meta for pack {pack_name}: {e}")
@@ -114,9 +116,8 @@ async def scan_pack(pack_name: str, force_rescan: bool = False) -> PackMeta:
pack_config_path = pack_path / "instance.json"
if pack_config_path.exists():
try:
# Синхронное чтение конфига
with open(pack_config_path, 'r', encoding='utf-8') as f:
config = json.load(f)
async with aiofiles.open(pack_config_path, 'r', encoding='utf-8') as f:
config = json.loads(await f.read())
minecraft_version = config.get("minecraftVersion", minecraft_version)
loader_type = config.get("loaderType", loader_type)
loader_version = config.get("loaderVersion")
@@ -137,9 +138,8 @@ async def scan_pack(pack_name: str, force_rescan: bool = False) -> PackMeta:
asset_index=asset_index
)
# Save to disk (синхронно)
with open(meta_path, 'w', encoding='utf-8') as f:
f.write(new_meta.model_dump_json(indent=2))
async with aiofiles.open(meta_path, 'w', encoding='utf-8') as f:
await f.write(new_meta.model_dump_json(indent=2))
# Update cache
_manifest_cache[pack_name] = new_meta