Skip to content

Commit

Permalink
improved upload dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Cart1416 committed Jul 31, 2024
1 parent 5dfa8d4 commit 7b8f1bd
Show file tree
Hide file tree
Showing 4 changed files with 1,247 additions and 39 deletions.
9 changes: 5 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

app = Flask(__name__)

UPLOAD_FOLDER = 'levels'
LEVELS_FOLDER = 'levels'
IMAGES_FOLDER = 'images'

@app.route('/')
def hello_world():
Expand All @@ -27,16 +28,16 @@ def upload_level():
if file:
level_id = ''.join(random.choices(string.ascii_letters + string.digits, k=8))
filename = f"{level_id}.json"
filepath = os.path.join(UPLOAD_FOLDER, filename)
filepath = os.path.join(LEVELS_FOLDER, filename)
file.save(filepath)
return jsonify({"message": f"Level uploaded successfully. ID: {level_id}", "filename": filename}), 200

@app.route('/get_level/<level_id>', methods=['GET'])
def get_level(level_id):
filename = f"{level_id}.json"
filepath = os.path.join(UPLOAD_FOLDER, filename)
filepath = os.path.join(LEVELS_FOLDER, filename)
if os.path.exists(filepath):
return send_from_directory(UPLOAD_FOLDER, filename)
return send_from_directory(LEVELS_FOLDER, filename)
else:
return jsonify({"error": "Level not found"}), 404

Expand Down
Loading

0 comments on commit 7b8f1bd

Please sign in to comment.