mirror of
https://github.com/NohamR/AM-Exporter.git
synced 2026-05-25 04:07:11 +00:00
opti
This commit is contained in:
24
back/app.py
24
back/app.py
@@ -1,6 +1,7 @@
|
|||||||
from flask import Flask, request, jsonify
|
from flask import Flask, request, jsonify
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
import json
|
import json
|
||||||
|
#import hashlib
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
CORS(app, resources={r"/music/*": {"origins": "http://*"}})
|
CORS(app, resources={r"/music/*": {"origins": "http://*"}})
|
||||||
@@ -8,25 +9,24 @@ CORS(app, resources={r"/music/*": {"origins": "http://*"}})
|
|||||||
with open('.users', 'r') as file:
|
with open('.users', 'r') as file:
|
||||||
users = json.load(file)
|
users = json.load(file)
|
||||||
|
|
||||||
|
cache = {}
|
||||||
|
|
||||||
@app.route('/music/set', methods=['POST'])
|
@app.route('/music/set', methods=['POST'])
|
||||||
def set_content():
|
def set_content():
|
||||||
global cache
|
data = request.get_json()
|
||||||
cache = request.get_json()
|
user = data.get('user')
|
||||||
if cache['user'] in users and users[cache['user']] == cache['password']:
|
password = data.get('password')
|
||||||
for key in ['user', 'password']:
|
if data['user'] in users and users[data['user']] == data['password']:
|
||||||
if key in cache:
|
# if user in users and users[user] == hashlib.sha256(password.encode()).hexdigest():
|
||||||
del cache[key]
|
cache.update(data)
|
||||||
# with open('cache.txt', 'w') as f:
|
cache.pop('user', None)
|
||||||
# f.write(str(cache))
|
cache.pop('password', None)
|
||||||
return jsonify({'message': 'Content set successfully.'})
|
return jsonify({'message': 'Content set successfully.'})
|
||||||
else:
|
else:
|
||||||
return jsonify({'message': 'Invalid user or password.'})
|
return jsonify({'message': 'Invalid user or password.'}), 401
|
||||||
|
|
||||||
@app.route('/music/get', methods=['GET'])
|
@app.route('/music/get', methods=['GET'])
|
||||||
def display_content():
|
def display_content():
|
||||||
global cache
|
|
||||||
# with open('cache.txt', 'r') as f:
|
|
||||||
# cache = f.read()
|
|
||||||
return jsonify(cache)
|
return jsonify(cache)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user