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