mirror of
https://github.com/Radiquum/YAMPD.git
synced 2025-05-20 15:49:34 +05:00
feat: mod delete
This commit is contained in:
parent
e453f336a8
commit
34df17d4dd
3 changed files with 133 additions and 399 deletions
|
@ -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",
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue