feat: mod delete

This commit is contained in:
Kentai Radiquum 2025-05-06 05:38:57 +05:00
parent e453f336a8
commit 34df17d4dd
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
3 changed files with 133 additions and 399 deletions

View file

@ -106,3 +106,31 @@ def addMod(id):
"mod": mod.get("mod"),
}
)
@apiPack.route("/<id>/mod/<slug>/delete", methods=["GET"])
def deleteMod(id, slug):
pack = {}
with open(f"{PACKS_FOLDER}/{id}/packfile.json") as fp:
pack = json.load(fp)
fp.close()
for mod in pack.get("mods"):
if mod.get("slug") == slug:
pack["mods"].remove(mod)
pack["modpackVersion"] += 1
if os.path.exists(
f"{PACKS_FOLDER}/{id}/mods/{mod.get('file').get('filename')}"
):
os.remove(f"{PACKS_FOLDER}/{id}/mods/{mod.get('file').get('filename')}")
with open(f"{PACKS_FOLDER}/{id}/packfile.json", mode="w", encoding="utf-8") as fp:
json.dump(pack, fp)
fp.close()
return jsonify(
{
"status": "ok",
"message": f"mod {slug} has been removed",
}
)