aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/ops.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/ops.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/ops.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/ops.py b/packages/meshbay-node/src/meshbay_node/ops.py
index c111581..20345bb 100644
--- a/packages/meshbay-node/src/meshbay_node/ops.py
+++ b/packages/meshbay-node/src/meshbay_node/ops.py
@@ -315,7 +315,8 @@ async def list_groups(state: dict) -> dict:
return {"groups": out}
-async def attach_group(state: dict, name: str, shared_dir: str) -> dict:
+async def attach_group(state: dict, name: str, shared_dir: str,
+ upload_dir: str = "") -> dict:
"""
Write a new [[groups]] block into node.toml.
@@ -360,19 +361,30 @@ async def attach_group(state: dict, name: str, shared_dir: str) -> dict:
block = (f'\n[[groups]]\n'
f'id = "{group["id"]}"\n'
f'name = "{group["name"]}"\n'
- f'visibility = "{group.get("visibility", "private")}"\n'
- f'\n [[groups.roots]]\n'
- f' path = "{path}"\n'
- f' upload = true\n')
+ f'visibility = "{group.get("visibility", "private")}"\n')
+ if upload_dir:
+ upload_path = Path(upload_dir).expanduser()
+ try:
+ upload_path.mkdir(parents=True, exist_ok=True)
+ except OSError as e:
+ raise OpError(f"Cannot create {upload_path}: {e}") from e
+ block += f'upload_dir = "{upload_path}"\n'
+ block += (f'\n [[groups.roots]]\n'
+ f' path = "{path}"\n')
+ if not upload_dir:
+ block += f' upload = true\n'
try:
with conf_path.open("a") as f:
f.write(block)
except OSError as e:
raise OpError(f"Cannot write {conf_path}: {e}", status=500) from e
- return {"group_id": group["id"], "name": group["name"],
- "shared_dir": str(path), "config": str(conf_path),
- "note": "restart the node to pick it up"}
+ result = {"group_id": group["id"], "name": group["name"],
+ "shared_dir": str(path), "config": str(conf_path),
+ "note": "restart the node to pick it up"}
+ if upload_dir:
+ result["upload_dir"] = str(upload_path)
+ return result
async def add_root(state: dict, group_id: str, path: str, *,