mirror of
https://github.com/Radiquum/YAMPD.git
synced 2025-05-20 23:59:35 +05:00
feat: add view of all packs
This commit is contained in:
parent
802b755d29
commit
e109b5393a
7 changed files with 114 additions and 3 deletions
|
@ -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")
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue