import os
from flask import Blueprint, request, jsonify
from config import TEMP_FOLDER
import datetime
from utils import ensure_correct_permissions
upload_bp = Blueprint('upload', __name__)

@upload_bp.route('/upload_images', methods=['POST'])
def upload_images():
    files = request.files.getlist("images")
    if not files:
        return jsonify({"error": "No files received"}), 400

    saved_files = []
    skipped_files = []

    for file in files:
        file_path = os.path.join(TEMP_FOLDER, file.filename)

        if os.path.exists(file_path):  
            skipped_files.append(file.filename)
            continue

        file.save(file_path)
        saved_files.append(file.filename)

    return jsonify({
        "message": "Upload completed!",
        "saved": saved_files,
        "skipped": skipped_files
    }), 200
