feat: загрузка картинок работ в модалку отзыва через ImgBB
- Добавлена кнопка 'Картинка из работ' в модалку feedbackModal (справа от тумблера 'В промпт прошлый отзыв' в одной строке) - Сетка миниатюр работ ученика из журнала (GET /api/entries) - Независимый модуль public/js/imgbb.js для загрузки картинок - Бэкенд-прокси POST /api/feedback/imgbb-upload (обход CORS) - Настройки feedback_imgbb_url / feedback_imgbb_key в разделе 'Сторонние сервисы' на settings.html + валидация в PUT /api/settings - Сиды настроек в db/init.sql и db/migration.sql - Вставка в #fbText: 'Последня работа.' + ссылка на ImgBB - charset=utf-8 для HTML-ответов статики (исправление кодировки кириллицы)
This commit is contained in:
@@ -919,6 +919,12 @@ app.get('/favicon.ico', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.use((req, res, next) => {
|
||||
if (req.url.endsWith('.html') || req.url.endsWith('.htm')) {
|
||||
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
||||
}
|
||||
next();
|
||||
});
|
||||
app.use('/vendor', express.static(path.join(__dirname, 'public', 'vendor'), { maxAge: '30d' }));
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
@@ -4448,6 +4454,41 @@ app.post('/api/feedbacks', requireAuth, asyncRoute(async (req, res) => {
|
||||
}
|
||||
}));
|
||||
|
||||
const imgbbUpload = multer({ storage: multer.memoryStorage(), limits: { fileSize: MAX_FILE_UPLOAD_BYTES } });
|
||||
|
||||
app.post('/api/feedback/imgbb-upload', requireAuth, imgbbUpload.single('image'), asyncRoute(async (req, res) => {
|
||||
const { rows } = await pool.query("SELECT key, value FROM settings WHERE key IN ('feedback_imgbb_url','feedback_imgbb_key')");
|
||||
const s = {};
|
||||
rows.forEach(r => { s[r.key] = r.value; });
|
||||
if (!s.feedback_imgbb_url || !s.feedback_imgbb_key) {
|
||||
return res.status(400).json({ error: 'ImgBB не настроен: укажите URL и ключ API в настройках системы' });
|
||||
}
|
||||
if (!req.file) return res.status(400).json({ error: 'Нет файла для загрузки' });
|
||||
const form = new FormData();
|
||||
form.append('key', s.feedback_imgbb_key);
|
||||
form.append('image', new Blob([req.file.buffer], { type: req.file.mimetype || 'application/octet-stream' }), req.file.originalname || 'image.jpg');
|
||||
try {
|
||||
const r = await fetch(s.feedback_imgbb_url, { method: 'POST', body: form });
|
||||
if (!r.ok) {
|
||||
const t = await r.text().catch(() => '');
|
||||
return res.status(r.status).json({ error: 'ImgBB вернул ' + r.status + (t ? ': ' + t : '') });
|
||||
}
|
||||
const j = await r.json().catch(() => ({}));
|
||||
if (!j || !j.data || !j.data.url) {
|
||||
return res.status(502).json({ error: 'Некорректный ответ ImgBB', detail: JSON.stringify(j).slice(0, 500) });
|
||||
}
|
||||
res.json({
|
||||
url: j.data.url,
|
||||
deleteUrl: j.data.delete_url || '',
|
||||
size: j.data.size || 0,
|
||||
name: j.data.name || req.file.originalname || 'image.jpg'
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('ImgBB upload error:', e);
|
||||
return res.status(502).json({ error: 'Ошибка загрузки на ImgBB: ' + e.message });
|
||||
}
|
||||
}));
|
||||
|
||||
app.post('/api/shorts/ai-correct', requireAuth, aiLimiter, async (req, res) => {
|
||||
try {
|
||||
const text = reqStr(req.body?.text, 5000);
|
||||
@@ -5730,7 +5771,7 @@ app.get('/api/settings', requireAdmin, async (_, res) => {
|
||||
|
||||
app.get('/api/public-settings', apiLimiter, async (_, res) => {
|
||||
const out = await cacheWrap('public-settings', PUBLIC_TTL_MS, async () => {
|
||||
const keys = ['system_name', 'system_logo', 'system_favicon', 'footer_left', 'footer_right', 'share_show_student_message', 'share_show_entry_date', 'share_show_student_names', 'share_show_group_photos', 'cookie_notice_text', 'spam_interval_min', 'photo_capture_resolution', 'photo_capture_quality', 'photo_enhance_engine', 'camera_enabled', 'photo_ai_face_mode', 'photo_ai_face_model', 'photo_ai_device_pref', 'timezone', 'time_format'];
|
||||
const keys = ['system_name', 'system_logo', 'system_favicon', 'footer_left', 'footer_right', 'share_show_student_message', 'share_show_entry_date', 'share_show_student_names', 'share_show_group_photos', 'cookie_notice_text', 'spam_interval_min', 'photo_capture_resolution', 'photo_capture_quality', 'photo_enhance_engine', 'camera_enabled', 'photo_ai_face_mode', 'photo_ai_face_model', 'photo_ai_device_pref', 'timezone', 'time_format', 'feedback_imgbb_url', 'feedback_imgbb_key'];
|
||||
const defaults = { system_name: 'WhatIDo', system_logo: '', system_favicon: '', spam_interval_min: '30', photo_capture_resolution: '640x480', photo_capture_quality: '0.92', photo_enhance_engine: 'auto', camera_enabled: 'true', photo_ai_face_mode: PHOTO_AI_DEFAULT_FACE_MODE, photo_ai_face_model: PHOTO_AI_FACE_MODEL, photo_ai_device_pref: 'auto', timezone: DEFAULT_TIMEZONE, time_format: '24h' };
|
||||
const result = {};
|
||||
for (const k of keys) result[k] = await getSetting(k, defaults[k] || '');
|
||||
@@ -5819,6 +5860,17 @@ app.put('/api/settings', requireAdmin, async (req, res) => {
|
||||
if (key === 'notes_ai_enabled' && !['true', 'false'].includes(String(value))) {
|
||||
return res.status(400).json({ error: 'notes_ai_enabled должен быть true или false' });
|
||||
}
|
||||
if (key === 'feedback_imgbb_url' && String(value).trim() !== '') {
|
||||
try {
|
||||
const u = new URL(String(value));
|
||||
if (u.protocol !== 'http:' && u.protocol !== 'https:') throw new Error('bad');
|
||||
} catch (e) {
|
||||
return res.status(400).json({ error: 'feedback_imgbb_url должен быть http(s) URL' });
|
||||
}
|
||||
}
|
||||
if (key === 'feedback_imgbb_key' && String(value).length > 256) {
|
||||
return res.status(400).json({ error: 'feedback_imgbb_key не может быть длиннее 256 символов' });
|
||||
}
|
||||
if (key === 'lesson_ai_prompt' && String(value).length > 8000) {
|
||||
return res.status(400).json({ error: 'lesson_ai_prompt длиннее 8000 символов' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user