refactor: scenes use manifest.json (same structure as dashboards)
This commit is contained in:
+8
-8
@@ -87,9 +87,9 @@ class SceneManager:
|
||||
for item in SCENES_DIR.iterdir():
|
||||
if not item.is_dir():
|
||||
continue
|
||||
f = item / "scene.json"
|
||||
if not f.exists():
|
||||
continue
|
||||
f = item / "manifest.json"
|
||||
if not f.exists():
|
||||
continue
|
||||
try:
|
||||
with open(f, "r", encoding="utf-8") as fp:
|
||||
data = json.load(fp)
|
||||
@@ -107,7 +107,7 @@ class SceneManager:
|
||||
|
||||
def get(self, scene_id: str) -> dict[str, Any] | None:
|
||||
item = SCENES_DIR / scene_id
|
||||
f = item / "scene.json"
|
||||
f = item / "manifest.json"
|
||||
if not f.exists():
|
||||
return None
|
||||
try:
|
||||
@@ -128,7 +128,7 @@ class SceneManager:
|
||||
item = SCENES_DIR / scene.id
|
||||
item.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
with open(item / "scene.json", "w", encoding="utf-8") as f:
|
||||
with open(item / "manifest.json", "w", encoding="utf-8") as f:
|
||||
json.dump(scene.to_dict(), f, indent=2, ensure_ascii=False)
|
||||
logger.info("Scene saved: %s", scene.id)
|
||||
return True
|
||||
@@ -160,10 +160,10 @@ class SceneManager:
|
||||
def import_scene_zip(self, zip_data: bytes) -> bool:
|
||||
try:
|
||||
with zipfile.ZipFile(io.BytesIO(zip_data), 'r') as zf:
|
||||
if "scene.json" not in zf.namelist():
|
||||
logger.error("No scene.json found in zip")
|
||||
if "manifest.json" not in zf.namelist():
|
||||
logger.error("No manifest.json found in zip")
|
||||
return False
|
||||
data = json.loads(zf.read("scene.json").decode('utf-8'))
|
||||
data = json.loads(zf.read("manifest.json").decode('utf-8'))
|
||||
scene = Scene.from_dict(data)
|
||||
item = SCENES_DIR / scene.id
|
||||
if item.exists():
|
||||
|
||||
+7
-7
@@ -668,11 +668,11 @@ async def api_market_upload_scene(file: UploadFile = File(...), token: str = "")
|
||||
try:
|
||||
zip_data = await file.read()
|
||||
with zipfile.ZipFile(io.BytesIO(zip_data), 'r') as zf:
|
||||
if 'scene.json' not in zf.namelist():
|
||||
return {"error": "缺少 scene.json"}
|
||||
scene = _json.loads(zf.read('scene.json').decode('utf-8'))
|
||||
if 'manifest.json' not in zf.namelist():
|
||||
return {"error": "缺少 manifest.json"}
|
||||
scene = _json.loads(zf.read('manifest.json').decode('utf-8'))
|
||||
if not scene.get('name'):
|
||||
return {"error": "scene.json 缺少 name"}
|
||||
return {"error": "manifest.json 缺少 name"}
|
||||
deps = set()
|
||||
for canvas in scene.get('canvases', []):
|
||||
for p in canvas.get('placements', []):
|
||||
@@ -712,8 +712,8 @@ async def api_market_install_scene(id: str = "", filename: str = ""):
|
||||
zip_data = resp.content
|
||||
missing = []
|
||||
with zipfile.ZipFile(io.BytesIO(zip_data), 'r') as zf:
|
||||
if 'scene.json' in zf.namelist():
|
||||
scene = _json.loads(zf.read('scene.json').decode('utf-8'))
|
||||
if 'manifest.json' in zf.namelist():
|
||||
scene = _json.loads(zf.read('manifest.json').decode('utf-8'))
|
||||
from models.dashboard import dashboard_manager
|
||||
for canvas in scene.get('canvases', []):
|
||||
for p in canvas.get('placements', []):
|
||||
@@ -788,7 +788,7 @@ async def api_market_publish_local(data: dict):
|
||||
|
||||
buf = io.BytesIO()
|
||||
with zipfile.ZipFile(buf, 'w', zipfile.ZIP_DEFLATED) as zf:
|
||||
zf.writestr("scene.json", _json.dumps(scene, indent=2, ensure_ascii=False))
|
||||
zf.writestr("manifest.json", _json.dumps(scene, indent=2, ensure_ascii=False))
|
||||
zip_data = buf.getvalue()
|
||||
|
||||
cfg = get_config()
|
||||
|
||||
Reference in New Issue
Block a user