image fix

main
Satur@it-depot.ru 2025-03-06 16:47:58 +03:00
parent 0d7cb6f8d1
commit d0899f178f
2 changed files with 13 additions and 10 deletions

4
app.py
View File

@ -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")

View File

@ -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 @@
}
</script>
</body>
</html>
</html>