refactor: api routes

This commit is contained in:
Kentai Radiquum 2025-05-05 20:46:49 +05:00
parent c74170a14d
commit 802b755d29
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
6 changed files with 95 additions and 55 deletions

41
src/api/packs.py Normal file
View file

@ -0,0 +1,41 @@
import os
from . import apiPacks
from flask import request, jsonify
from config import PACKS_FOLDER
import json
@apiPacks.route("/new", methods=["POST"])
def createPack():
pack = {
"formatVersion": 0,
"modpackVersion": 0,
"title": request.json.get("title"),
"author": request.json.get("author"),
"version": request.json.get("version"),
"modloader": request.json.get("modloader"),
"updateURL": "",
"mods": [],
}
title = pack.get("title").replace(" ", "_")
if os.path.exists(f"{PACKS_FOLDER}/{title}"):
return jsonify({"status": "error", "message": "pack already exists"})
os.makedirs(f"{PACKS_FOLDER}/{title}", exist_ok=True)
with open(
os.path.abspath(f"{PACKS_FOLDER}/{title}/packfile.json"),
mode="w",
encoding="utf-8",
) as fp:
json.dump(pack, fp)
fp.close()
return jsonify(
{
"status": "ok",
"message": f"pack {pack.get('title')} created",
"id": title,
}
)