Commit b8734348 authored by Fence's avatar Fence 🌈

add config stuff

parent 53879a93
from minor import App
app = App()
app = App({"UPLOAD_DIR": "./upload"})
app.run()
\ No newline at end of file
from minor import App
app = App()
# change upload dir!
app = App({"UPLOAD_DIR": "./upload"})
application = app.get_application()
\ No newline at end of file
......@@ -3,21 +3,19 @@ from minor.controller import ApiController, MusicController
class App(object):
def __init__(self):
def __init__(self, config):
self._flask = Flask(__name__)
self._flask.config['MONGODB_SETTINGS'] = {'db': 'minor'}
self._flask.config.update(config)
from minor.model import db
db.init_app(self._flask)
ApiController(self).register(self._flask)
MusicController().register(self._flask)
MusicController(self._flask.config["UPLOAD_DIR"]).register(self._flask)
def run(self):
self._flask.run()
def check_key(self, key):
return key == "sekrit1234"
def get_application(self):
return self._flask
......@@ -19,16 +19,3 @@ class ApiController(FlaskController):
@route("/ping")
def ping(self):
return "pong"
@json_required
@route("/register", methods=["POST"])
def register_major(self):
json = request.get_json()
if "key" in json:
if self._app.check_key(json["key"]):
# add the instance the the trusted list
new_instance = MajorInstance(
issuer=json["issuer"], url=json["url"])
new_instance.save()
return jsonify({"code": 200, "message": "ok"}), 200
return jsonify({"code": 400, "message": "bad_request"}), 400
......@@ -12,6 +12,8 @@ from minor.util import get_ext
@route("/api/music")
class MusicController(FlaskController):
def __init__(self, upload_dir):
self._upload_dir = upload_dir
@auth_required
@route("/listen")
......@@ -19,7 +21,7 @@ class MusicController(FlaskController):
if "song" in payload:
song = Song.objects.get(id=payload["song"])
if song is not None:
filename = "./uploads/" + str(song.id) + ".mp3"
filename = self._upload_dir + str(song.id) + ".mp3"
if os.path.isfile(filename):
def generate():
with open(filename, "rb") as fogg:
......@@ -45,7 +47,7 @@ class MusicController(FlaskController):
def song_has_file(self, id, payload=None):
song = Song.objects.get(id=id)
if song is not None:
filename = "./uploads/" + str(song.id) + ".mp3"
filename = self._upload_dir + str(song.id) + ".mp3"
if os.path.isfile(filename):
return jsonify({"code": 200, "message": "ok", "data": True}), 200
else:
......@@ -90,7 +92,7 @@ class MusicController(FlaskController):
ext = get_ext(file.filename)
if ext is not None:
name = secure_filename(str(db_song.id) + "." + ext)
path = os.path.join("./uploads", name)
path = os.path.join(self._upload_dir, name)
file.save(path)
return jsonify({"code": 200, "message": "ok"}), 200
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment