fix: voorkom duplicate repo-IDs bij toevoegen via UI

This commit is contained in:
bes-r 2026-05-30 00:55:16 +02:00
parent e5ef3b02b7
commit f96a9407d5

View file

@ -316,7 +316,13 @@ def api_repos_add():
if not url:
return jsonify(ok=False, msg="URL vereist")
repos = list(cfg.load().get("APP_REPOS", []))
rid = d.get("id", url.split("/")[-1].replace(".git", "")).strip()[:30] or str(int(time.time()))
existing_ids = {r["id"] for r in repos}
base_rid = d.get("id", url.split("/")[-1].replace(".git", "")).strip()[:30] or str(int(time.time()))
rid = base_rid
counter = 1
while rid in existing_ids:
rid = f"{base_rid}-{counter}"
counter += 1
repos.append({"id": rid, "name": d.get("name", "").strip() or url.split("/")[-1],
"url": url, "branch": d.get("branch", "main"),
"token": d.get("token", ""), "subdir": d.get("subdir", "")})
@ -877,8 +883,14 @@ def api_modrepos_add():
if not url:
return jsonify(ok=False, msg="URL vereist")
repos = list(cfg.load().get("MODULE_REPOS", []))
repos.append({"id": d.get("id", url.split("/")[-1].replace(".git", ""))[:30],
"name": d.get("name", "") or url.split("/")[-1],
existing_ids = {r["id"] for r in repos}
base_rid = d.get("id", url.split("/")[-1].replace(".git", ""))[:30]
rid = base_rid
counter = 1
while rid in existing_ids:
rid = f"{base_rid}-{counter}"
counter += 1
repos.append({"id": rid, "name": d.get("name", "") or url.split("/")[-1],
"url": url, "branch": d.get("branch", "main"),
"subdir": d.get("subdir", "")})
cfg.patch({"MODULE_REPOS": repos})