feat: add view of all packs

This commit is contained in:
Kentai Radiquum 2025-05-05 21:45:34 +05:00
parent 802b755d29
commit e109b5393a
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
7 changed files with 114 additions and 3 deletions

View file

@ -1,7 +1,7 @@
import os
import re
from . import apiPack
from flask import request, jsonify, send_file, redirect
from flask import request, jsonify, send_file, redirect, url_for
from config import PACKS_FOLDER, IMG_ALLOWED_MIME
from PIL import Image
from io import BytesIO
@ -11,7 +11,7 @@ import base64
@apiPack.route("/<id>/image", methods=["GET"])
def getPackImage(id):
if not os.path.exists(f"{PACKS_FOLDER}/{id}/packicon.png"):
return redirect("/favicon.ico")
return redirect(url_for("static", filename="defaulticon.png"))
return send_file(f"{PACKS_FOLDER}/{id}/packicon.png")

View file

@ -5,6 +5,26 @@ from config import PACKS_FOLDER
import json
@apiPacks.route("/all", methods=["GET"])
def getPacks():
packs = []
if not os.path.exists(f"{PACKS_FOLDER}"):
os.makedirs(f"{PACKS_FOLDER}", exist_ok=True)
return jsonify(packs)
pack_folders = [f.name for f in os.scandir(PACKS_FOLDER) if f.is_dir()]
for pack_folder in pack_folders:
if not os.path.exists(f"{PACKS_FOLDER}/{pack_folder}/packfile.json"):
continue
with open(f"{PACKS_FOLDER}/{pack_folder}/packfile.json") as fp:
pack = json.load(fp)
pack["_id"] = pack_folder
packs.append(pack)
fp.close()
return jsonify(packs)
@apiPacks.route("/new", methods=["POST"])
def createPack():
pack = {