@iksdev/shard-cli 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/shard.js +16 -1
- package/package.json +1 -1
package/bin/shard.js
CHANGED
|
@@ -260,6 +260,18 @@ function guessMime(filePath) {
|
|
|
260
260
|
return map[ext] || 'application/octet-stream';
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
function formatBytes(bytes) {
|
|
264
|
+
const value = Number(bytes || 0);
|
|
265
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
266
|
+
let size = value;
|
|
267
|
+
let idx = 0;
|
|
268
|
+
while (size >= 1024 && idx < units.length - 1) {
|
|
269
|
+
size /= 1024;
|
|
270
|
+
idx += 1;
|
|
271
|
+
}
|
|
272
|
+
return `${size.toFixed(idx === 0 ? 0 : 2)} ${units[idx]}`;
|
|
273
|
+
}
|
|
274
|
+
|
|
263
275
|
async function uploadOneFile(server, token, file) {
|
|
264
276
|
const blob = await fs.openAsBlob(file.absPath, { type: guessMime(file.absPath) });
|
|
265
277
|
const form = new FormData();
|
|
@@ -332,7 +344,10 @@ async function syncFolder(positionals, flags) {
|
|
|
332
344
|
const file = changed[i];
|
|
333
345
|
const label = `[${i + 1}/${changed.length}]`;
|
|
334
346
|
try {
|
|
347
|
+
const startedAt = Date.now();
|
|
348
|
+
console.log(`${label} UPLOAD ${file.relPath} (${formatBytes(file.size)})`);
|
|
335
349
|
const result = await uploadOneFile(server, token, file);
|
|
350
|
+
const tookSeconds = ((Date.now() - startedAt) / 1000).toFixed(1);
|
|
336
351
|
success += 1;
|
|
337
352
|
state.files[file.relPath] = {
|
|
338
353
|
size: file.size,
|
|
@@ -340,7 +355,7 @@ async function syncFolder(positionals, flags) {
|
|
|
340
355
|
uploadedAt: new Date().toISOString(),
|
|
341
356
|
remoteId: result?.file?.id || null
|
|
342
357
|
};
|
|
343
|
-
console.log(`${label} OK ${file.relPath}`);
|
|
358
|
+
console.log(`${label} OK ${file.relPath} (${tookSeconds}s)`);
|
|
344
359
|
} catch (error) {
|
|
345
360
|
failed += 1;
|
|
346
361
|
console.error(`${label} FAIL ${file.relPath} -> ${error.message}`);
|