From d0899f178f1c342ca56ea52e57bc17a17d550bd9 Mon Sep 17 00:00:00 2001 From: "Satur@it-depot.ru" Date: Thu, 6 Mar 2025 16:47:58 +0300 Subject: [PATCH] image fix --- app.py | 4 ++-- templates/index.html | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app.py b/app.py index e83daa8..2dbfc12 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, HTTPException, File, UploadFile, Query +from fastapi import FastAPI, HTTPException, File, UploadFile, Form from pydantic import BaseModel import sqlite3 import datetime @@ -289,7 +289,7 @@ async def import_csv(file: UploadFile = File(...), folder_id: int | None = Query # Новый эндпоинт для загрузки изображений @api_app.post("/api/upload-image") -async def upload_image(install_id: int = Query(..., description="ID записи для ассоциации изображения"), file: UploadFile = File(...)): +async def upload_image(install_id: int = Form(...), file: UploadFile = File(...)): if not file.filename: raise HTTPException(status_code=400, detail="No file provided") diff --git a/templates/index.html b/templates/index.html index 2eccce8..7ec18b3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -983,11 +983,14 @@ function uploadImage() { const fileInput = document.getElementById('image-upload-input'); const file = fileInput.files[0]; - if (!file) return; + if (!file || !selectedInstallId) { + alert('Пожалуйста, выберите запись и изображение.'); + return; + } const formData = new FormData(); - formData.append('image', file); - formData.append('install_id', selectedInstallId); + formData.append('install_id', selectedInstallId); // Отправляем как часть формы + formData.append('file', file); // Отправляем файл $.ajax({ url: `${API_URL}/upload-image`, @@ -1009,7 +1012,7 @@ }, error: function (xhr, status, error) { console.error('Error uploading image:', status, error); - alert(`Не удалось загрузить изображение: ${xhr.responseJSON?.detail || error}`); + alert(`Не удалось загрузить изображение: ${xhr.responseJSON?.detail || 'Неизвестная ошибка'}`); } }); } @@ -1047,7 +1050,7 @@ } function closeNoteModal() { - $('#note-modal').hide(); // + $('#note-modal').hide(); $('#modal-overlay').hide(); $('#note-textarea').val(''); // Очищаем текстовое поле selectedInstallId = null; // Сбрасываем выбранный ID @@ -1106,7 +1109,7 @@ function formatItalic() { const textarea = $('#note-textarea'); const start = textarea[0].selectionStart; - end = textarea[0].selectionEnd; + const end = textarea[0].selectionEnd; const text = textarea.val(); const selected = text.substring(start, end); const newText = `*${selected}*`; @@ -1154,7 +1157,7 @@ $('#folder-tree').jstree(true).refresh(); }, error: function (xhr, status, error) { - console.error("Error saving folder position:", status, error); + console.error("Error saving folder position:", status, error); console.error("Response:", xhr.responseText); alert("Не удалось сохранить новое положение папки. Проверьте консоль."); $('#folder-tree').jstree(true).refresh(); @@ -1163,4 +1166,4 @@ } - \ No newline at end of file + \ No newline at end of file