aboutsummaryrefslogtreecommitdiff
path: root/modules/ext
diff options
context:
space:
mode:
Diffstat (limited to 'modules/ext')
-rw-r--r--modules/ext/webdav.js52
1 files changed, 46 insertions, 6 deletions
diff --git a/modules/ext/webdav.js b/modules/ext/webdav.js
index 7f3e7a7..e78e876 100644
--- a/modules/ext/webdav.js
+++ b/modules/ext/webdav.js
@@ -453,7 +453,7 @@ class WebDAVModule {
const isDir = href.endsWith('/');
let size = 0;
if (!isDir && sizeStr !== '-') {
- size = parseInt(sizeStr) || 0;
+ size = this._parseAutoindexSize(sizeStr);
}
entries.push({
name: name,
@@ -506,6 +506,25 @@ class WebDAVModule {
return entries;
}
+ // nginx autoindex with `autoindex_exact_size off` (our template) emits
+ // HUMANISED sizes: '512', '21K', '45K', '1.2M'. parseInt() read the leading
+ // digits and dropped the suffix, so a 21 397-byte file was reported as 21 B.
+ // Parse the suffix here, 1024-based, to match _formatSize() below.
+ _parseAutoindexSize(sizeStr) {
+ if (sizeStr === null || sizeStr === undefined) return 0;
+ const s = String(sizeStr).trim();
+ const m = s.match(/^(\d+(?:\.\d+)?)\s*([KMG]?)i?B?$/i);
+ if (!m) return 0;
+ const num = parseFloat(m[1]);
+ if (!isFinite(num) || num < 0) return 0;
+ const unit = (m[2] || '').toUpperCase();
+ const mult = unit === 'K' ? 1024
+ : unit === 'M' ? 1024 * 1024
+ : unit === 'G' ? 1024 * 1024 * 1024
+ : 1;
+ return Math.round(num * mult);
+ }
+
_parseNginxDate(dateStr) {
if (!dateStr) return null;
// nginx default: 02-Aug-2026 14:30
@@ -1095,8 +1114,26 @@ class WebDAVModule {
const resp = await self._webdavRequest('GET', remotePath);
if (!resp.ok) throw new Error('HTTP ' + resp.status);
const content = await resp.text();
- self.terminal.fs.writeFile(vfsPath, content);
- self.terminal.print('Pulled: ' + remotePath + ' → ' + vfsPath + ' (' + content.length + ' bytes)', 'success');
+ // Create the local parent chain FIRST: fs.writeFile() returns false
+ // when the parent directory is missing (_resolvePath bails), and the
+ // old code ignored that return and printed a success line for a
+ // write that never happened.
+ const slash = vfsPath.lastIndexOf('/');
+ const parentDir = slash > 0 ? vfsPath.slice(0, slash) : '';
+ if (parentDir && typeof self.terminal.fs.mkdirRecursive === 'function') {
+ if (self.terminal.fs.mkdirRecursive(parentDir) === false) {
+ self.terminal.print('Pull failed: cannot create local directory ' + parentDir, 'error');
+ return;
+ }
+ }
+ const wrote = self.terminal.fs.writeFile(vfsPath, content);
+ if (!wrote) {
+ self.terminal.print('Pull failed: cannot write local file ' + vfsPath +
+ ' (missing directory or path is a directory) — nothing saved', 'error');
+ return;
+ }
+ const _bytes = (typeof TextEncoder !== 'undefined') ? new TextEncoder().encode(content).length : content.length;
+ self.terminal.print('Pulled: ' + remotePath + ' → ' + vfsPath + ' (' + _bytes + ' bytes)', 'success');
} catch (e) {
self.terminal.print('Pull error: ' + e.message, 'error');
}
@@ -2442,8 +2479,11 @@ class WebDAVModule {
}
_formatSize(bytes) {
- if (bytes < 1024) return bytes + ' B';
- if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
- return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
+ const n = Number(bytes);
+ if (!Number.isFinite(n) || n < 0) return '—';
+ if (n < 1024) return n + ' B';
+ if (n < 1024 * 1024) return (n / 1024).toFixed(1) + ' KB';
+ if (n < 1024 * 1024 * 1024) return (n / (1024 * 1024)).toFixed(1) + ' MB';
+ return (n / (1024 * 1024 * 1024)).toFixed(1) + ' GB';
}
}