45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
import logging, os
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
)
|
|
|
|
from flask import Flask, render_template, jsonify, send_from_directory
|
|
from base.modulemanager import ModuleManager
|
|
import base.notificationmanager as ntfy
|
|
|
|
app = Flask(__name__, static_folder=os.path.join(".", "base", "static"))
|
|
|
|
mod_manager = ModuleManager()
|
|
mod_manager.load(app, "modules")
|
|
|
|
# a warm welcome
|
|
ntfy.NOTIFICATION_MANAGER.notify(ntfy.Notification(
|
|
module = "server",
|
|
status = ntfy.Notification.Status.INFO,
|
|
msg = "Server started!",
|
|
))
|
|
|
|
@app.route("/notifications", methods=["GET"])
|
|
def api_notifications():
|
|
return jsonify(ntfy.NOTIFICATION_MANAGER.serialized())
|
|
|
|
@app.route("/notifications/delete/<nid>", methods=["DELETE"])
|
|
def api_delete_notification(nid):
|
|
is_deleted = ntfy.NOTIFICATION_MANAGER.delete(nid)
|
|
if is_deleted:
|
|
return jsonify({}), 200
|
|
return jsonify({}), 400
|
|
|
|
@app.route("/modules")
|
|
def api_modules():
|
|
return jsonify(mod_manager.get_mod_list())
|
|
|
|
@app.route("/")
|
|
def main_page():
|
|
return app.send_static_file("index.html")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(debug=True, use_reloader=False)
|