Refactor photo upload logic to improve file path handling and remove unused imports

This commit is contained in:
Yaro Kasear 2025-07-11 11:58:00 -05:00
parent a2b035f522
commit 7bdbb4ea2a

View file

@ -1,7 +1,7 @@
import os
import posixpath
import datetime
from flask import Blueprint, current_app, request, jsonify, send_from_directory
from flask import Blueprint, current_app, request, jsonify
from .helpers import generate_hashed_filename, get_photo_attachable_class_by_name
from .. import db
@ -12,7 +12,8 @@ photo_bp = Blueprint("photo_api", __name__)
def save_photo(file, model: str) -> str:
assert current_app.static_folder
rel_path = generate_hashed_filename(file, model)
hashed_name = generate_hashed_filename(file, model)
rel_path = posixpath.join("uploads", "photos", hashed_name)
abs_path = os.path.join(current_app.static_folder, "uploads", "photos", rel_path)
dir_path = os.path.dirname(abs_path)
@ -49,6 +50,7 @@ def upload_photo():
# Save file
rel_path = save_photo(file, model)
print(rel_path)
# Create Photo row
photo = Photo(filename=rel_path, caption=caption)