diff --git a/site/static/files.js b/site/static/files.js index 02092e3..1f44a12 100644 --- a/site/static/files.js +++ b/site/static/files.js @@ -211,59 +211,36 @@ window.toggleClassifyDetail = async function(i) { * uploadFile(file, onProgress) — загрузка одного файла на бэкенд. * * v2.0.1: fetch() вместо XHR — XHR давал ERR_CONNECTION_RESET (drhider v0.0.29) + * v2.0.2: убрана конвертация .doc (libreoffice недоступен на Штурвале) * Прогресс: без процентов (fetch не поддерживает), только статус. - * - * Особенности: - * - .doc (не .docx!) конвертируется через CONVERT_URL перед загрузкой - * - onProgress(pct) — сохранён для совместимости, вызывается с 0 и 100 - * - Возвращает Promise<ответ API> + * Возвращает Promise<ответ API> */ function uploadFile(file, onProgress, zipSource) { - // .doc → конвертация в docx (старый формат Word) - var isDoc = file.name.toLowerCase().endsWith('.doc') && !file.name.toLowerCase().endsWith('.docx'); + if (onProgress) onProgress(0); + var fd = new FormData(); + fd.append('files', file, file.name); + if (state.contractId) fd.append('contract_id', state.contractId); + fd.append('batch_id', state.batchId); + if (zipSource) fd.append('zip_source', zipSource); - function doUpload(uploadFile, uploadName) { - if (onProgress) onProgress(0); - var fd = new FormData(); - fd.append('files', uploadFile, uploadName); - if (state.contractId) fd.append('contract_id', state.contractId); - fd.append('batch_id', state.batchId); - if (zipSource) fd.append('zip_source', zipSource); - - return fetch(UPLOAD_URL + '?_=' + Date.now(), { method: 'POST', body: fd }) - .then(function(r) { - if (!r.ok) throw new Error('HTTP ' + r.status); - return r.json(); - }) - .then(function(data) { - if (data.ok) { - if (onProgress) onProgress(100); - return data; - } - throw new Error(data.error || 'Неизвестная ошибка'); - }) - .catch(function(e) { - // Перезапись fetch-ошибок в понятные сообщения - if (e.message === 'Failed to fetch' || e.name === 'TypeError') { - throw new Error('Сеть'); - } - throw e; - }); - } - - if (isDoc) { - return fetch(CONVERT_URL, { method: 'POST', body: file }) - .then(function(r) { - if (!r.ok) throw new Error('Конвертация .doc'); - return r.blob(); - }) - .then(function(blob) { - if (blob.size < 100) throw new Error('Конвертация .doc'); - return doUpload(blob, file.name.replace(/\.doc$/i, '.docx')); - }); - } else { - return doUpload(file, file.name); - } + return fetch(UPLOAD_URL + '?_=' + Date.now(), { method: 'POST', body: fd }) + .then(function(r) { + if (!r.ok) throw new Error('HTTP ' + r.status); + return r.json(); + }) + .then(function(data) { + if (data.ok) { + if (onProgress) onProgress(100); + return data; + } + throw new Error(data.error || 'Неизвестная ошибка'); + }) + .catch(function(e) { + if (e.message === 'Failed to fetch' || e.name === 'TypeError') { + throw new Error('Сеть'); + } + throw e; + }); } /** diff --git a/site/templates/index.html b/site/templates/index.html index 90f811a..30755a6 100644 --- a/site/templates/index.html +++ b/site/templates/index.html @@ -90,7 +90,7 @@ Загрузка договоров/приложений/спецификаций