mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
move imgserver to app/api folder
+ add sqlite methods to configure custom root directories + add sqlite.settings module + remove date and app name from logger messages + add api route to browse directories
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
from flask import Blueprint, request
|
||||
from app.db.sqlite.settings import SettingsSQLMethods as sdb
|
||||
|
||||
settingsbp = Blueprint("settings", __name__, url_prefix="/")
|
||||
|
||||
|
||||
@settingsbp.route("/settings/add-root-dirs", methods=["POST"])
|
||||
def add_root_dirs():
|
||||
"""
|
||||
Add custom root directories to the database.
|
||||
"""
|
||||
msg = {"msg": "Failed! No directories were given."}
|
||||
|
||||
data = request.get_json()
|
||||
|
||||
if data is None:
|
||||
return msg, 400
|
||||
|
||||
try:
|
||||
new_dirs = data["new_dirs"]
|
||||
removed_dirs = data["removed"]
|
||||
except KeyError:
|
||||
return msg, 400
|
||||
|
||||
sdb.add_root_dirs(new_dirs)
|
||||
sdb.remove_root_dirs(removed_dirs)
|
||||
|
||||
return {"msg": "Added root directories to the database."}
|
||||
|
||||
|
||||
@settingsbp.route("/settings/get-root-dirs", methods=["GET"])
|
||||
def get_root_dirs():
|
||||
"""
|
||||
Get custom root directories from the database.
|
||||
"""
|
||||
dirs = sdb.get_root_dirs()
|
||||
|
||||
return {"dirs": dirs}
|
||||
|
||||
|
||||
# CURRENTLY UNUSED ROUTE 👇
|
||||
@settingsbp.route("/settings/remove-root-dirs", methods=["POST"])
|
||||
def remove_root_dirs():
|
||||
"""
|
||||
Remove custom root directories from the database.
|
||||
"""
|
||||
msg = {"msg": "Failed! No directories were given."}
|
||||
|
||||
data = request.get_json()
|
||||
|
||||
if data is None:
|
||||
return msg, 400
|
||||
|
||||
try:
|
||||
dirs = data["dirs"]
|
||||
except KeyError:
|
||||
return msg, 400
|
||||
|
||||
sdb.remove_root_dirs(dirs)
|
||||
|
||||
return {"msg": "Removed root directories from the database."}
|
||||
Reference in New Issue
Block a user