From 313c9973cd0f3a09248cd4096c668828261d8b10 Mon Sep 17 00:00:00 2001 From: nate Date: Tue, 24 Mar 2026 15:55:47 +0400 Subject: [PATCH] fix: server time different than client --- apps/web/src/dashboard/app.js | 3 ++- apps/web/src/routes/dashboard.ts | 4 ++-- deploy.sh | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/apps/web/src/dashboard/app.js b/apps/web/src/dashboard/app.js index 79c21e7..58d0d8f 100644 --- a/apps/web/src/dashboard/app.js +++ b/apps/web/src/dashboard/app.js @@ -31,7 +31,8 @@ async function api(path, opts = {}) { // Format relative time function formatAgo(ms) { - const s = Math.floor(ms / 1000); + const s = Math.max(0, Math.floor(ms / 1000)); + if (s < 2) return 'just now'; if (s < 60) return `${s}s ago`; if (s < 3600) return `${Math.floor(s / 60)}m ago`; if (s < 86400)return `${Math.floor(s / 3600)}h ago`; diff --git a/apps/web/src/routes/dashboard.ts b/apps/web/src/routes/dashboard.ts index 90a2ca3..f35d27e 100644 --- a/apps/web/src/routes/dashboard.ts +++ b/apps/web/src/routes/dashboard.ts @@ -16,8 +16,8 @@ const eta = new Eta({ views: resolve(import.meta.dir, "../views"), cache: true, function timeAgoSSR(date: string | Date): string { const ts = new Date(date).getTime(); - const s = Math.floor((Date.now() - ts) / 1000); - const text = s < 60 ? `${s}s ago` : s < 3600 ? `${Math.floor(s/60)}m ago` : s < 86400 ? `${Math.floor(s/3600)}h ago` : `${Math.floor(s/86400)}d ago`; + const s = Math.max(0, Math.floor((Date.now() - ts) / 1000)); + const text = s < 2 ? 'just now' : s < 60 ? `${s}s ago` : s < 3600 ? `${Math.floor(s/60)}m ago` : s < 86400 ? `${Math.floor(s/3600)}h ago` : `${Math.floor(s/86400)}d ago`; return `${text}`; } diff --git a/deploy.sh b/deploy.sh index 2e0a8e1..978ae81 100755 --- a/deploy.sh +++ b/deploy.sh @@ -95,14 +95,15 @@ REMOTE echo "[monitor] All monitors deployed" } -# Parse args +# Parse args — supports both "./deploy.sh web api" and "./deploy.sh web,api" if [ $# -eq 0 ]; then echo "Usage: $0 [web|api|pay|monitor|db|all] [...]" + echo " $0 web,api,pay (comma-separated)" exit 1 fi -for arg in "$@"; do - case "$arg" in +deploy_target() { + case "$1" in db) deploy_db ;; api) deploy_api ;; pay) deploy_pay ;; @@ -110,8 +111,15 @@ for arg in "$@"; do monitor) deploy_monitor ;; nuke-db) nuke_db ;; all) deploy_db; deploy_api; deploy_pay; deploy_web; deploy_monitor ;; - *) echo "Unknown target: $arg (valid: web, api, pay, monitor, db, nuke-db, all)"; exit 1 ;; + *) echo "Unknown target: $1 (valid: web, api, pay, monitor, db, nuke-db, all)"; exit 1 ;; esac +} + +for arg in "$@"; do + IFS=',' read -ra targets <<< "$arg" + for target in "${targets[@]}"; do + deploy_target "$target" + done done echo "Deploy complete."