fix(ui): ETA includes waiting jobs — folder-added files now ship with bytesTotal
This commit is contained in:
parent
127807d62a
commit
d3fda31243
29
main.js
29
main.js
@ -1379,6 +1379,17 @@ ipcMain.handle('select-folder', async () => {
|
|||||||
});
|
});
|
||||||
if (result.canceled || !result.filePaths.length) return null;
|
if (result.canceled || !result.filePaths.length) return null;
|
||||||
|
|
||||||
|
const files = [];
|
||||||
|
for (const folder of result.filePaths) await walkFolderAsync(folder, files);
|
||||||
|
return files.length > 0 ? files.map(f => f.path) : null;
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('select-folder-with-sizes', async () => {
|
||||||
|
const result = await dialog.showOpenDialog(mainWindow, {
|
||||||
|
properties: ['openDirectory', 'multiSelections']
|
||||||
|
});
|
||||||
|
if (result.canceled || !result.filePaths.length) return null;
|
||||||
|
|
||||||
const files = [];
|
const files = [];
|
||||||
for (const folder of result.filePaths) await walkFolderAsync(folder, files);
|
for (const folder of result.filePaths) await walkFolderAsync(folder, files);
|
||||||
return files.length > 0 ? files : null;
|
return files.length > 0 ? files : null;
|
||||||
@ -1396,7 +1407,11 @@ async function walkFolderAsync(rootDir, outFiles) {
|
|||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
const full = path.join(dir, entry.name);
|
const full = path.join(dir, entry.name);
|
||||||
if (entry.isDirectory()) stack.push(full);
|
if (entry.isDirectory()) stack.push(full);
|
||||||
else if (entry.isFile()) outFiles.push(full);
|
else if (entry.isFile()) {
|
||||||
|
let size = 0;
|
||||||
|
try { size = (await fsp.stat(full)).size; } catch {}
|
||||||
|
outFiles.push({ path: full, name: entry.name, size });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ((++scanned % 8) === 0) await new Promise(setImmediate);
|
if ((++scanned % 8) === 0) await new Promise(setImmediate);
|
||||||
}
|
}
|
||||||
@ -1408,6 +1423,18 @@ ipcMain.handle('resolve-folder-files', async (_event, folderPath) => {
|
|||||||
return files;
|
return files;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('get-file-sizes', async (_event, paths) => {
|
||||||
|
if (!Array.isArray(paths)) return {};
|
||||||
|
const fsp = fs.promises;
|
||||||
|
const out = {};
|
||||||
|
let i = 0;
|
||||||
|
for (const p of paths) {
|
||||||
|
try { out[p] = (await fsp.stat(p)).size; } catch { out[p] = 0; }
|
||||||
|
if ((++i % 32) === 0) await new Promise(setImmediate);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
});
|
||||||
|
|
||||||
ipcMain.handle('start-upload', (_event, payload) => {
|
ipcMain.handle('start-upload', (_event, payload) => {
|
||||||
const config = configStore.load();
|
const config = configStore.load();
|
||||||
const files = payload && Array.isArray(payload.files) ? payload.files : [];
|
const files = payload && Array.isArray(payload.files) ? payload.files : [];
|
||||||
|
|||||||
@ -30,7 +30,9 @@ contextBridge.exposeInMainWorld('api', {
|
|||||||
// File selection
|
// File selection
|
||||||
selectFiles: () => ipcRenderer.invoke('select-files'),
|
selectFiles: () => ipcRenderer.invoke('select-files'),
|
||||||
selectFolder: () => ipcRenderer.invoke('select-folder'),
|
selectFolder: () => ipcRenderer.invoke('select-folder'),
|
||||||
|
selectFolderWithSizes: () => ipcRenderer.invoke('select-folder-with-sizes'),
|
||||||
resolveFolderFiles: (folderPath) => ipcRenderer.invoke('resolve-folder-files', folderPath),
|
resolveFolderFiles: (folderPath) => ipcRenderer.invoke('resolve-folder-files', folderPath),
|
||||||
|
getFileSizes: (paths) => ipcRenderer.invoke('get-file-sizes', paths),
|
||||||
|
|
||||||
// Upload control
|
// Upload control
|
||||||
startUpload: (payload) => ipcRenderer.invoke('start-upload', payload),
|
startUpload: (payload) => ipcRenderer.invoke('start-upload', payload),
|
||||||
|
|||||||
@ -695,11 +695,12 @@ async function addDroppedFiles(fileList) {
|
|||||||
const folderFiles = await window.api.resolveFolderFiles(filePath);
|
const folderFiles = await window.api.resolveFolderFiles(filePath);
|
||||||
if (folderFiles && folderFiles.length > 0) {
|
if (folderFiles && folderFiles.length > 0) {
|
||||||
for (const fp of folderFiles) {
|
for (const fp of folderFiles) {
|
||||||
if (!existingPaths.has(fp)) {
|
const p = typeof fp === 'string' ? fp : (fp && fp.path);
|
||||||
const name = fp.split('\\').pop().split('/').pop();
|
if (!p || existingPaths.has(p)) continue;
|
||||||
newFiles.push({ path: fp, name, size: null });
|
const name = typeof fp === 'string' ? p.split('\\').pop().split('/').pop() : (fp.name || p.split('\\').pop().split('/').pop());
|
||||||
existingPaths.add(fp);
|
const size = typeof fp === 'string' ? null : (fp.size || 0);
|
||||||
}
|
newFiles.push({ path: p, name, size });
|
||||||
|
existingPaths.add(p);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -730,28 +731,52 @@ async function pickFiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function pickFolder() {
|
async function pickFolder() {
|
||||||
|
const richFiles = window.api.selectFolderWithSizes ? await window.api.selectFolderWithSizes() : null;
|
||||||
|
if (richFiles && Array.isArray(richFiles)) { addPathsToQueue(richFiles); return; }
|
||||||
const paths = await window.api.selectFolder();
|
const paths = await window.api.selectFolder();
|
||||||
if (!paths) return;
|
if (!paths) return;
|
||||||
addPathsToQueue(paths);
|
addPathsToQueue(paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addPathsToQueue(paths) {
|
function addPathsToQueue(paths) {
|
||||||
// Build path-Set once so dedup is O(1) per candidate instead of O(n+m).
|
|
||||||
// Matters when the user picks a folder with thousands of files.
|
|
||||||
const existing = new Set();
|
const existing = new Set();
|
||||||
for (const f of selectedFiles) existing.add(f.path);
|
for (const f of selectedFiles) existing.add(f.path);
|
||||||
for (const f of _pendingFiles) existing.add(f.path);
|
for (const f of _pendingFiles) existing.add(f.path);
|
||||||
|
|
||||||
const newFiles = [];
|
const newFiles = [];
|
||||||
for (const p of paths) {
|
const pendingSizeFetch = [];
|
||||||
if (existing.has(p)) continue;
|
for (const entry of paths) {
|
||||||
|
const p = typeof entry === 'string' ? entry : (entry && entry.path);
|
||||||
|
if (!p || existing.has(p)) continue;
|
||||||
existing.add(p);
|
existing.add(p);
|
||||||
const name = p.split('\\').pop().split('/').pop();
|
const name = typeof entry === 'string' ? p.split('\\').pop().split('/').pop() : (entry.name || p.split('\\').pop().split('/').pop());
|
||||||
newFiles.push({ path: p, name, size: null });
|
const size = typeof entry === 'string' ? null : (entry.size || 0);
|
||||||
|
newFiles.push({ path: p, name, size });
|
||||||
|
if (size === null || size === undefined || size === 0) pendingSizeFetch.push(p);
|
||||||
}
|
}
|
||||||
if (newFiles.length > 0) {
|
if (newFiles.length > 0) {
|
||||||
_pendingFiles.push(...newFiles);
|
_pendingFiles.push(...newFiles);
|
||||||
openHosterModal();
|
openHosterModal();
|
||||||
|
if (pendingSizeFetch.length > 0 && window.api.getFileSizes) {
|
||||||
|
window.api.getFileSizes(pendingSizeFetch).then((sizeMap) => {
|
||||||
|
if (!sizeMap || typeof sizeMap !== 'object') return;
|
||||||
|
let changed = false;
|
||||||
|
for (const f of _pendingFiles) {
|
||||||
|
if (sizeMap[f.path] && (!f.size || f.size === 0)) { f.size = sizeMap[f.path]; changed = true; }
|
||||||
|
}
|
||||||
|
for (const f of selectedFiles) {
|
||||||
|
if (sizeMap[f.path] && (!f.size || f.size === 0)) { f.size = sizeMap[f.path]; changed = true; }
|
||||||
|
}
|
||||||
|
for (const j of queueJobs) {
|
||||||
|
if (sizeMap[j.file] && (!j.bytesTotal || j.bytesTotal === 0)) { j.bytesTotal = sizeMap[j.file]; changed = true; }
|
||||||
|
}
|
||||||
|
if (changed) {
|
||||||
|
_queueStatsCache = null;
|
||||||
|
if (typeof renderQueueTable === 'function') renderQueueTable();
|
||||||
|
if (typeof updateStatusBar === 'function') updateStatusBar();
|
||||||
|
}
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user