Remove VM upload layer; keep file picker only
This commit is contained in:
@@ -10,7 +10,6 @@ export function initUploadTable(cfg) {
|
||||
folderInputEl: cfg.folderInputEl,
|
||||
tableBodyEl: cfg.tableBodyEl,
|
||||
countEl: cfg.countEl,
|
||||
uploadBtnEl: cfg.uploadBtnEl,
|
||||
};
|
||||
const state = { files: [], fileMeta: new Map(), overNames: new Set(), busy: false };
|
||||
elements.fileInputEl.addEventListener('change', onFilesChange(state, cfg, elements));
|
||||
@@ -36,7 +35,6 @@ export function initUploadTable(cfg) {
|
||||
state.busy = busy;
|
||||
elements.fileInputEl.disabled = busy;
|
||||
elements.folderInputEl.disabled = busy;
|
||||
elements.uploadBtnEl.disabled = busy || api.getFiles().length === 0;
|
||||
},
|
||||
};
|
||||
api.render();
|
||||
|
||||
@@ -18,5 +18,4 @@ export function render(state, elements) {
|
||||
elements.countEl.textContent = `${included.length} учитываются`
|
||||
+ (overCount ? ` + ${overCount} свыше лимита` : '')
|
||||
+ ` · ${fs(size)}`;
|
||||
elements.uploadBtnEl.disabled = included.length === 0;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
export function putToVm(file, url, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('PUT', url);
|
||||
xhr.timeout = options.timeoutMs || 300000;
|
||||
xhr.upload.onprogress = (event) => {
|
||||
if (event.lengthComputable && options.onProgress) {
|
||||
options.onProgress(Math.round(event.loaded / event.total * 100));
|
||||
}
|
||||
};
|
||||
xhr.onload = () => {
|
||||
if (xhr.status >= 200 && xhr.status < 300) resolve();
|
||||
else reject(new Error(`ВМ: HTTP ${xhr.status}`));
|
||||
};
|
||||
xhr.onerror = () => reject(new Error('Сеть (ВМ)'));
|
||||
xhr.ontimeout = () => reject(new Error('Таймаут загрузки на ВМ'));
|
||||
xhr.send(file);
|
||||
});
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import { putToVm } from './put_to_vm.js';
|
||||
|
||||
export async function uploadViaVM(files, vmUploadUrl, options = {}) {
|
||||
const token = crypto.randomUUID();
|
||||
const refs = [];
|
||||
for (let index = 0; index < files.length; index += 1) {
|
||||
const file = files[index];
|
||||
const url = `${vmUploadUrl}${token}_${index}`;
|
||||
options.onUploadStatus?.(`Загрузка на ВМ ${index + 1}/${files.length}: ${file.name}`);
|
||||
try {
|
||||
await putToVm(file, url, {
|
||||
onProgress: (percent) => options.onStatus?.(file.name, `${percent}%`),
|
||||
});
|
||||
refs.push({ name: file.name, size: file.size, url });
|
||||
} catch (error) {
|
||||
options.onStatus?.(file.name, `Ошибка: ${error.message}`);
|
||||
return { ok: false, error: `Ошибка загрузки на ВМ: ${error.message}` };
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${options.apiBase || ''}/api/upload_refs`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ session: options.session || '', files: refs }),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok || !data.ok) throw new Error(data.error || `HTTP ${response.status}`);
|
||||
return { ok: true, session: data.session, count: data.count || refs.length };
|
||||
} catch (error) {
|
||||
return { ok: false, error: `Ошибка передачи ссылок: ${error.message}` };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user