diff --git a/api/app.py b/api/app.py index eb56ef5..5839aad 100644 --- a/api/app.py +++ b/api/app.py @@ -1,5 +1,6 @@ from flask import Flask, request, jsonify from database import * +from werkzeug.utils import secure_filename app = Flask(__name__) @@ -151,7 +152,6 @@ def settings_collection(): print(result) return jsonify(result), 201 - @app.route("/settings/", methods=["GET", "PUT"]) def setting_detail(name: str): """Retrieve or update a single setting. @@ -177,6 +177,32 @@ def setting_detail(name: str): print(result) return jsonify(result) +# ----------------------------- Photos ----------------------------- + +@app.route('/api/providers//photos', methods=['POST']) +def upload_photos(provider_id): + if 'photos' not in request.files: + return jsonify({'error': 'No files uploaded'}), 400 + + # Secure filename + save to persistent storage + upload_folder = f'{os.path.dirname(__file__)}/photos' + os.makedirs(upload_folder, exist_ok=True) + + photo_paths = [] + for file in request.files.getlist('photos'): + if file.filename == '': + continue + + filename = secure_filename(file.filename) + file.save(os.path.join(upload_folder, filename)) + photo_paths.append(f"/uploads/{filename}") + + # Store paths in DB (e.g., PostgreSQL JSON field) + db.execute("UPDATE providers SET photos = %s WHERE id = %s", + (json.dumps(photo_paths), provider_id)) + + return jsonify({'success': True, 'paths': photo_paths}), 200 + # Run the app if this file is executed directly if __name__ == "__main__": app.run(host="0.0.0.0", port=5000, debug=False) diff --git a/web/photos-old.php b/web/photos-old.php new file mode 100644 index 0000000..a90dd79 --- /dev/null +++ b/web/photos-old.php @@ -0,0 +1,38 @@ + + +
+ Drag photo here or click to choose +
+ + \ No newline at end of file diff --git a/web/photos.php b/web/photos.php index a90dd79..5caa74d 100644 --- a/web/photos.php +++ b/web/photos.php @@ -1,38 +1,37 @@ - - -
- Drag photo here or click to choose -
+ + + - \ No newline at end of file + + +