ccusage-tracker 0.1.6 → 0.1.7
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/dist/index.js +23 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -421,12 +421,20 @@ Hook: ${hookInstalled ? "installed" : "not installed"}`);
|
|
|
421
421
|
if (existsSync3(lastErrorPath)) {
|
|
422
422
|
const reason = readFileSync3(lastErrorPath, "utf-8").trim();
|
|
423
423
|
console.log(`
|
|
424
|
-
|
|
424
|
+
Upload error: ${reason}`);
|
|
425
425
|
console.log(uploadFailureHint(reason));
|
|
426
426
|
} else {
|
|
427
427
|
console.log(`
|
|
428
|
-
|
|
428
|
+
Upload error: none recorded`);
|
|
429
429
|
}
|
|
430
|
+
const lastUploadPath = join3(configDir, "last-upload.txt");
|
|
431
|
+
let lastUploadTs = null;
|
|
432
|
+
if (existsSync3(lastUploadPath)) {
|
|
433
|
+
const parsed = parseInt(readFileSync3(lastUploadPath, "utf-8").trim(), 10);
|
|
434
|
+
if (!isNaN(parsed))
|
|
435
|
+
lastUploadTs = parsed;
|
|
436
|
+
}
|
|
437
|
+
console.log(uploadAgeLine(lastUploadTs, Date.now()));
|
|
430
438
|
const lastFlushPath = join3(configDir, "last-flush.txt");
|
|
431
439
|
if (existsSync3(lastFlushPath)) {
|
|
432
440
|
const ts = parseInt(readFileSync3(lastFlushPath, "utf-8").trim(), 10);
|
|
@@ -438,6 +446,19 @@ Last upload: no recorded failure`);
|
|
|
438
446
|
const probe = probeCcusage();
|
|
439
447
|
console.log(probe ? `ccusage: installed (${probe})` : "ccusage: not found (install with: npx ccusage@latest)");
|
|
440
448
|
}
|
|
449
|
+
var STALE_UPLOAD_MS = 24 * 60 * 60 * 1000;
|
|
450
|
+
function uploadAgeLine(ts, now) {
|
|
451
|
+
if (ts === null) {
|
|
452
|
+
return "Last successful upload: 尚無成功紀錄(剛安裝屬正常,跑完一次 session 後再看)";
|
|
453
|
+
}
|
|
454
|
+
const age = now - ts;
|
|
455
|
+
const when = new Date(ts).toISOString();
|
|
456
|
+
if (age >= STALE_UPLOAD_MS) {
|
|
457
|
+
const hours = Math.floor(age / 3600000);
|
|
458
|
+
return `Last successful upload: ${when} (${hours} 小時前) — 超過 24 小時,上報可能已停擺`;
|
|
459
|
+
}
|
|
460
|
+
return `Last successful upload: ${when} (${Math.floor(age / 60000)} 分鐘前)`;
|
|
461
|
+
}
|
|
441
462
|
function uploadFailureHint(reason) {
|
|
442
463
|
if (reason.includes("ccusage")) {
|
|
443
464
|
return [
|
package/package.json
CHANGED