From e4704c2dc69361318d9aab490128f30c4d875bda Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 24 Sep 2026 11:21:58 +0300 Subject: [PATCH] fix(index): paste fills only project files, photo stays webcam-only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - pasted images/files always go to "Файлы проекта", never to the entry photo - drop the photo paste hint and the capturedName plumbing: the entry photo is captured from the camera only (submit still requires it) - keep paste naming ("Вставка .") and server-mirrored limits --- public/index.html | 1 - public/js/index.js | 25 ++++--------------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/public/index.html b/public/index.html index d267719..fd88bcf 100644 --- a/public/index.html +++ b/public/index.html @@ -113,7 +113,6 @@ nav a:hover{color:var(--text)}
-

Ctrl+V — вставить фото из буфера

diff --git a/public/js/index.js b/public/js/index.js index 9473b6e..d0012c5 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -13,9 +13,7 @@ const toast = document.getElementById('toast'); const camVideo = document.getElementById('camVideo'); const camCanvas = document.getElementById('camCanvas'); const camModal = document.getElementById('camModal'); -const photoPasteHint = document.getElementById('photoPasteHint'); let capturedBlob = null; -let capturedName = 'photo.jpg'; let stream = null; const descInput = document.getElementById('descInput'); const filesInput = document.getElementById('filesInput'); @@ -124,7 +122,6 @@ const MAX_FILES = 10; const MAX_FILE_BYTES = 10 * 1024 * 1024; const MAX_TOTAL_BYTES = 30 * 1024 * 1024; const BLOCKED_FILE_EXT = /\.(?:html?|js|mjs|cjs|svg|xml|json|map|wasm|php\d?|phtml|asp|aspx|jsp|sh|bat|cmd|cgi|exe|dll|com|msi|scr|hta|vbs|py|r|rb|htaccess)$/i; -const IMAGE_FILE_EXT = new Set(['.jpg', '.jpeg', '.png', '.gif', '.webp', '.bmp', '.avif', '.ico', '.heic', '.heif', '.jfif']); const MIME_EXT = { 'image/png': '.png', 'image/jpeg': '.jpg', 'image/jpg': '.jpg', 'image/gif': '.gif', 'image/webp': '.webp', 'image/bmp': '.bmp', 'image/avif': '.avif', 'image/heic': '.heic', 'image/heif': '.heif', 'image/svg+xml': '.svg', @@ -208,31 +205,21 @@ document.addEventListener('paste', (e) => { if (!pasted.length && clip.files && clip.files.length) pasted.push(...Array.from(clip.files)); if (!pasted.length) return; e.preventDefault(); - let photoSet = false; let filesAdded = 0; const skipped = []; for (const raw of pasted) { const name = pasteFileName(raw); const file = raw.name === name ? raw : new File([raw], name, { type: raw.type || 'application/octet-stream', lastModified: raw.lastModified }); - if (!capturedBlob && IMAGE_FILE_EXT.has(extFromFile(file))) { - capturedBlob = file; - capturedName = name; - showPreview(URL.createObjectURL(file)); - photoSet = true; - continue; - } const res = addFiles([file]); filesAdded += res.added.length; skipped.push(...res.skipped); } - const parts = []; - if (photoSet) parts.push('Фото вставлено из буфера'); - if (filesAdded) parts.push(filesAdded === 1 ? 'Файл добавлен' : `Файлов добавлено: ${filesAdded}`); - if (!parts.length) { + if (!filesAdded) { if (skipped.length) notify(skipped[0], true); return; } - notify(parts.join('. ') + (skipped.length ? '. ' + skipped[0] : ''), skipped.length > 0); + const summary = filesAdded === 1 ? 'Файл добавлен' : `Файлов добавлено: ${filesAdded}`; + notify(summary + (skipped.length ? '. ' + skipped[0] : ''), skipped.length > 0); }); const params = new URLSearchParams(location.search); @@ -339,16 +326,13 @@ function showPreview(src) { preview.src = src; preview.classList.add('has-photo'); removePhotoBtn.classList.add('show'); - photoPasteHint.style.display = 'none'; } function removePhoto() { preview.src = placeholderSrc; preview.classList.remove('has-photo'); removePhotoBtn.classList.remove('show'); - photoPasteHint.style.display = ''; capturedBlob = null; - capturedName = 'photo.jpg'; } async function openCam() { @@ -375,7 +359,6 @@ function capture() { ctx.drawImage(camVideo, 0, 0); camCanvas.toBlob(blob => { capturedBlob = blob; - capturedName = 'photo.jpg'; showPreview(URL.createObjectURL(blob)); closeCam(); }, 'image/jpeg', captureQuality); @@ -404,7 +387,7 @@ form.addEventListener('submit', async (e) => { btn.textContent = 'Отправка...'; const fd = new FormData(); - fd.append('photo', capturedBlob, capturedName); + fd.append('photo', capturedBlob, 'photo.jpg'); selectedFiles.forEach(f => fd.append('files', f, f.name)); fd.append('student_name', studentName || document.getElementById('nameInput').value); fd.append('group_id', groupInput.value);