Compare changes

Choose any two refs to compare.

+1
.gitignore
··· 22 22 *.njsproj 23 23 *.sln 24 24 *.sw? 25 + .wrangler
+6
bun.lock
··· 6 6 "dependencies": { 7 7 "@tailwindcss/vite": "^4.1.16", 8 8 "date-fns": "^4.1.0", 9 + "filesize": "^11.0.13", 9 10 "lodash": "^4.17.21", 10 11 "numeral": "^2.0.6", 11 12 "tailwindcss": "^4.1.16", ··· 15 16 "@skeletonlabs/skeleton-svelte": "^4.2.2", 16 17 "@sveltejs/vite-plugin-svelte": "^6.2.1", 17 18 "@tsconfig/svelte": "^5.0.5", 19 + "@types/lodash": "^4.17.20", 18 20 "@types/node": "^24.6.0", 19 21 "svelte": "^5.39.6", 20 22 "svelte-check": "^4.3.2", ··· 186 188 187 189 "@types/estree": ["@types/estree@1.0.8", "", {}, "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w=="], 188 190 191 + "@types/lodash": ["@types/lodash@4.17.20", "", {}, "sha512-H3MHACvFUEiujabxhaI/ImO6gUrd8oOurg7LQtS7mbwIXA/cUqWrvBsaeJ23aZEPk1TAYkurjfMbSELfoCXlGA=="], 192 + 189 193 "@types/node": ["@types/node@24.9.2", "", { "dependencies": { "undici-types": "7.16.0" } }, "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA=="], 190 194 191 195 "@zag-js/accordion": ["@zag-js/accordion@1.26.4", "", { "dependencies": { "@zag-js/anatomy": "1.26.4", "@zag-js/core": "1.26.4", "@zag-js/dom-query": "1.26.4", "@zag-js/types": "1.26.4", "@zag-js/utils": "1.26.4" } }, "sha512-gjKu1i3Z3fGzrGazMDHskbgdqj/DtHw9ZOW8L9X/G37CNkIe4EQyy1GbzyM91gYncSFNShquBawxuaGK3VvSdw=="], ··· 297 301 "esrap": ["esrap@2.1.2", "", { "dependencies": { "@jridgewell/sourcemap-codec": "1.5.5" } }, "sha512-DgvlIQeowRNyvLPWW4PT7Gu13WznY288Du086E751mwwbsgr29ytBiYeLzAGIo0qk3Ujob0SDk8TiSaM5WQzNg=="], 298 302 299 303 "fdir": ["fdir@6.5.0", "", { "optionalDependencies": { "picomatch": "4.0.3" } }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], 304 + 305 + "filesize": ["filesize@11.0.13", "", {}, "sha512-mYJ/qXKvREuO0uH8LTQJ6v7GsUvVOguqxg2VTwQUkyTPXXRRWPdjuUPVqdBrJQhvci48OHlNGRnux+Slr2Rnvw=="], 300 306 301 307 "fsevents": ["fsevents@2.3.3", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="], 302 308
+2
package.json
··· 16 16 "@sveltejs/vite-plugin-svelte": "^6.2.1", 17 17 "@tsconfig/svelte": "^5.0.5", 18 18 "@types/node": "^24.6.0", 19 + "@types/lodash": "^4.17.20", 19 20 "svelte": "^5.39.6", 20 21 "svelte-check": "^4.3.2", 21 22 "typescript": "~5.9.3", ··· 24 25 "dependencies": { 25 26 "@tailwindcss/vite": "^4.1.16", 26 27 "date-fns": "^4.1.0", 28 + "filesize": "^11.0.13", 27 29 "lodash": "^4.17.21", 28 30 "numeral": "^2.0.6", 29 31 "tailwindcss": "^4.1.16"
+266 -85
src/App.svelte
··· 1 1 <script lang="ts"> 2 + 2 3 import { onMount } from 'svelte'; 3 - import { formatDistanceToNow, addSeconds, formatDate, formatISO9075 } from 'date-fns'; 4 + import { filesize } from 'filesize'; 5 + import { formatDistanceToNow, addSeconds, subSeconds, formatDate, formatISO9075, differenceInSeconds } from 'date-fns'; 4 6 import { Progress, Switch } from '@skeletonlabs/skeleton-svelte'; 5 - import orderBy from "lodash/orderBy"; 7 + import orderBy from 'lodash/orderBy'; 8 + import BundleDownloader from './BundleDownloader.svelte'; 9 + import { formatNumber, formatUptime } from './lib/utils'; 6 10 import instancesData from './instances.json'; 7 - import numeral from 'numeral'; 8 - 11 + 9 12 const APP_TITLE = 'plcbundle instances' 10 13 const PLC_DIRECTORY = 'plc.directory' 11 - const ROOT = 'cbab6809a136d6a621906ee11199d3b0faf85b422fe0d0d2c346ce8e9dcd7485' 14 + const ROOT = 'f743c3ae1e3f6023e89e492bce63b52a9ed03ee46a163c2f4a3b997eaf2aaf85' 12 15 const AUTO_REFRESH_INTERVAL = 10 // in seconds 13 16 const BUNDLE_OPS = 10_000 17 + const PAST_ROOTS = [ 18 + // November 2025: https://bsky.app/profile/atproto.com/post/3m4e3mnxb7s2p 19 + "cbab6809a136d6a621906ee11199d3b0faf85b422fe0d0d2c346ce8e9dcd7485" 20 + ] 21 + 22 + type StatusResponse = { 23 + ok: boolean; 24 + bundles: { 25 + last_bundle: number; 26 + root_hash: string; 27 + head_hash: string; 28 + end_time?: string; 29 + total_size?: number; 30 + uncompressed_size?: number; 31 + updated_at?: string; 32 + }; 33 + server: { 34 + uptime: number; 35 + }; 36 + mempool?: { 37 + count: number; 38 + eta_next_bundle_seconds: number; 39 + last_time: Date; 40 + }; 41 + latency?: number; 42 + } 43 + 44 + type StatusResponseError = { 45 + error: string; 46 + } 14 47 15 48 type Instance = { 16 - url: string, 17 - cors?: boolean, 18 - status?: object, 19 - modern?: boolean, 49 + url: string; 50 + cors?: boolean; 51 + status?: StatusResponse | StatusResponseError; 52 + modern?: boolean; 53 + _head?: boolean; 54 + _oldRoot?: boolean; 55 + _conflict?: boolean; 20 56 } 21 57 22 - let lastKnownBundle = $state({ 58 + type LastKnownBundle = { 59 + number: number; 60 + hash: string | null; 61 + mempool: number | null; 62 + mempoolPercent: number; 63 + mempoolBundle: number; 64 + lastTime?: Date; 65 + time?: string; 66 + etaNext?: Date | null; 67 + totalSize?: number | null; 68 + totalSizeUncompressed?: number | null; 69 + } 70 + 71 + let lastKnownBundle = $state<LastKnownBundle>({ 23 72 number: 0, 24 73 hash: null, 25 74 mempool: null, 75 + mempoolBundle: 0, 26 76 mempoolPercent: 0, 27 77 }) 28 78 29 79 let isUpdating = $state(false) 30 80 let canRefresh = $state(true) 31 - let isConflict = $state(false) 81 + let consensus = $state({}) 82 + let isConflict = $state(consensus) 83 + let instancesInConflict = $state<string[]>([]) 32 84 let lastUpdated = $state(new Date()) 33 85 let autoRefreshEnabled = $state(true) 34 - let instances = $state(instancesData.sort(() => Math.random() - 0.5)) 35 - 36 - const instanceOrderBy = [['_head', 'status.latency'], ['desc', 'asc']] 86 + let instances = $state<Instance[]>(instancesData.sort(() => Math.random() - 0.5)) 37 87 38 - function formatNumber(n: number) { 39 - return numeral(n).format() 40 - } 88 + const instanceOrderBy = [ 89 + ['status.error', '_head', '_oldRoot' , 'status.bundles.last_bundle', 'status.latency'], 90 + ['desc', 'desc', 'asc', 'desc', 'asc'] 91 + ] 41 92 42 - async function getStatus(instance: Instance) { 43 - let statusResp: object | undefined; 93 + async function getStatus(instance: Instance): Promise<StatusResponse | StatusResponseError> { 94 + let statusResp: StatusResponse | undefined; 44 95 let url: string = instance.url; 96 + let lastError: string | undefined; 45 97 const start = performance.now(); 46 98 try { 47 99 statusResp = await (await fetch(`${url}/status?${Number(new Date())}`)).json() 48 - } catch (e) {} 100 + } catch (e: any) { 101 + lastError = e.message; 102 + } 49 103 if (!statusResp) { 50 104 url = `https://keyoxide.org/api/3/get/http?url=${encodeURIComponent(url)}&format=text&time=${Date.now()}` 51 - const indexResp = await (await fetch(url)).text() 52 - const [ _, from, to ] = indexResp?.match(/Range:\s+(\d{6}) - (\d{6})/) 53 - statusResp = { 54 - bundles: { 55 - last_bundle: Number(to), 56 - root_hash: indexResp?.match(/Root: ([a-f0-9]{64})/)[1], 57 - head_hash: indexResp?.match(/Head: ([a-f0-9]{64})/)[1], 58 - }, 59 - server: { 60 - uptime: 1, 105 + 106 + let indexResp: string | undefined; 107 + try { 108 + indexResp = await (await fetch(url)).text() 109 + } catch(e: any) { 110 + lastError = e.message; 111 + } 112 + const match = indexResp?.match(/Range:\s+(\d{6}) - (\d{6})/) 113 + if (match) { 114 + const [, from, to] = match 115 + const rootMatch = indexResp?.match(/Root: ([a-f0-9]{64})/) 116 + const headMatch = indexResp?.match(/Head: ([a-f0-9]{64})/) 117 + 118 + statusResp = { 119 + ok: true, 120 + bundles: { 121 + last_bundle: Number(to), 122 + root_hash: rootMatch ? rootMatch[1] : '', 123 + head_hash: headMatch ? headMatch[1] : '', 124 + }, 125 + server: { 126 + uptime: 1, 127 + } 61 128 } 62 129 } 63 130 } 64 131 if (statusResp) { 132 + statusResp.ok = true 65 133 statusResp.latency = performance.now() - start; 66 134 } 67 135 //if (instance.url === 'https://plc.j4ck.xyz') { statusResp.bundles.head_hash = 'f3ad3544452b2c078cba24990486bb9c277a1155'; } 68 - return statusResp 136 + return statusResp ?? { error: lastError || 'unknown error' } 69 137 } 70 138 71 139 function recalculateHead() { 72 140 isConflict = false 73 - const headHashes = [] 141 + instancesInConflict = [] 142 + const headHashes: any = {} 74 143 for (const instance of instances) { 75 - instance._head = instance.status?.bundles?.last_bundle === lastKnownBundle.number 76 - if (instance._head) { 77 - headHashes.push(instance.status?.bundles?.head_hash) 144 + if ((instance.status && 'error' in instance.status) || !instance.status) { 145 + continue 146 + } 147 + const { head_hash, root_hash, last_bundle } = instance.status.bundles 148 + instance._oldRoot = PAST_ROOTS.includes(root_hash) 149 + instance._head = !instance._oldRoot && (last_bundle === lastKnownBundle.number) 150 + 151 + if (instance._head && head_hash) { 152 + if (!headHashes[head_hash]) { 153 + headHashes[head_hash] = [] 154 + } 155 + headHashes[head_hash].push(instance.url) 78 156 } 79 157 } 80 - isConflict = [...new Set(headHashes)].length > 1 158 + console.log(headHashes) 159 + // second pass 160 + const sorted: any = Object.fromEntries( 161 + Object.entries(headHashes).sort(([, a]: any, [, b]: any) => b.length - a.length) 162 + ) 163 + for (const instance of instances) { 164 + if (Object.keys(sorted).length > 1 && Object.keys(sorted)[0] && !sorted[Object.keys(sorted)[0]].includes(instance.url)) { 165 + instance._conflict = true 166 + instancesInConflict.push(instance.url) 167 + } 168 + } 169 + //const uniq = [...new Set(headHashes)] 170 + isConflict = instancesInConflict.length > Math.ceil(instances.length/2) 81 171 } 82 172 83 173 async function doCheck() { 84 174 isUpdating = true 85 175 canRefresh = false 86 176 for (const i of instances) { 87 - i.status = undefined 177 + if (i.status && 'ok' in i.status) { 178 + i.status.ok = false 179 + } 88 180 } 89 - 90 - const statuses = [] 91 181 92 182 await Promise.all(instances.map(async (instance) => { 93 183 const status = await getStatus(instance) 184 + if (!status) { 185 + return false 186 + } 187 + 94 188 instance.status = status 95 - if (status?.bundles?.last_bundle > lastKnownBundle.number) { 96 - lastKnownBundle.number = status?.bundles?.last_bundle 97 - lastKnownBundle.hash = status?.bundles?.head_hash 98 - lastKnownBundle.time = status?.bundles?.end_time 189 + if ('ok' in status && status.ok) { 190 + 191 + if (status?.bundles?.last_bundle && status.bundles.last_bundle >= lastKnownBundle.number && !PAST_ROOTS.includes(status.bundles.root_hash)) { 192 + lastKnownBundle.number = status.bundles.last_bundle 193 + lastKnownBundle.hash = status.bundles.head_hash 194 + lastKnownBundle.time = status.bundles.end_time 99 195 100 - if (status?.mempool?.count > lastKnownBundle.mempool) { 101 - lastKnownBundle.mempool = status?.mempool?.count 102 - lastKnownBundle.mempoolPercent = Math.round((lastKnownBundle.mempool/100)*100)/100 103 - lastKnownBundle.etaNext = addSeconds(new Date(), status?.mempool?.eta_next_bundle_seconds) 196 + if (status?.mempool?.count && (!lastKnownBundle.mempool || status.mempool.count > lastKnownBundle.mempool || status.bundles.last_bundle > lastKnownBundle.mempoolBundle)) { 197 + lastKnownBundle.mempoolBundle = status.bundles.last_bundle 198 + lastKnownBundle.mempool = status.mempool.count 199 + lastKnownBundle.lastTime = status.mempool.last_time 200 + lastKnownBundle.mempoolPercent = Math.round((lastKnownBundle.mempool/100)*100)/100 201 + lastKnownBundle.etaNext = status.mempool.eta_next_bundle_seconds ? addSeconds(new Date(), status.mempool.eta_next_bundle_seconds) : null 202 + lastKnownBundle.totalSize = status.bundles.total_size 203 + lastKnownBundle.totalSizeUncompressed = status.bundles.uncompressed_size 204 + } 104 205 } 105 206 } 207 + 106 208 lastUpdated = new Date() 107 209 108 210 recalculateHead() ··· 112 214 setTimeout(() => { canRefresh = true }, 500) 113 215 } 114 216 115 - function updateTitle () { 116 - const arr = [] 117 - if (lastUpdated > 0) { 118 - const upCount = instances.filter(i => i._head) 217 + function normalizedVersion(version: string) { 218 + const m = version.trim().match(/^([^\s]+)\.\d+\.\d+\-[0-9a-f]+(\+dirty|)$/) 219 + if (m) { 220 + return `${m[1]}+dirty` 221 + } 222 + return version 223 + } 224 + 225 + function updateTitle() { 226 + const arr: string[] = [] 227 + if (lastUpdated) { 228 + const upCount = instances.filter(i => i._head && !i._conflict) 119 229 arr.push(`${isConflict ? 'โš ๏ธ' : 'โœ…'} [${upCount.length}/${instances.length}]`) 120 230 } 121 231 document.title = [...arr, APP_TITLE].join(' ') 122 232 return true 123 233 } 124 234 125 - onMount(async () => { 126 - await doCheck() 235 + function bundleAge(instance: Instance) { 236 + if (!instance.status || !('bundles' in instance.status) || !instance.status.bundles?.updated_at) { 237 + return '-' 238 + } 239 + const str = instance.status?.bundles.updated_at ? instance.status?.bundles.updated_at : instance.status?.bundles.end_time || '' 240 + const diff = differenceInSeconds(new Date(), new Date(str)) 241 + return diff > 300 ? '>5m' : diff + 's' 242 + } 243 + 244 + function secondsAge(seconds: number) { 245 + return seconds > 300 ? '>5m' : seconds + 's' 246 + } 127 247 128 - setTimeout(() => { 129 - if (autoRefreshEnabled) { 130 - doCheck() 248 + let autoRefreshTimer: ReturnType<typeof setTimeout> | null = null; 249 + 250 + onMount(() => { 251 + doCheck().then(() => { 252 + const scheduleRefresh = () => { 253 + autoRefreshTimer = setTimeout(() => { 254 + if (autoRefreshEnabled) { 255 + doCheck() 256 + } 257 + scheduleRefresh() 258 + }, AUTO_REFRESH_INTERVAL * 1000) 131 259 } 132 - }, AUTO_REFRESH_INTERVAL * 1000) 260 + 261 + scheduleRefresh() 262 + 263 + }) 264 + 265 + return () => { 266 + if (autoRefreshTimer) { 267 + clearTimeout(autoRefreshTimer) 268 + } 269 + } 133 270 }) 134 271 </script> 135 272 136 - <main class="w-full mt-10"> 137 - <div class="max-w-4xl mx-auto px-3"> 273 + <main class="w-full mt-10 mb-16"> 274 + <div class="max-w-5xl mx-auto px-3"> 138 275 139 276 <header class="flex items-center gap-10 flex-wrap"> 140 277 <div class="grow"> 141 - <h1 class="text-3xl linear-text-gradient">plcbundle instances</h1> 278 + <h1 class="text-3xl linear-text-gradient"><a href="https://plcbundle-watch.pages.dev/" class="no-style">plcbundle instances</a></h1> 142 279 </div> 143 280 <div class="flex items-center gap-6"> 144 281 <Switch class="opacity-75" checked={autoRefreshEnabled} onCheckedChange={(x) => autoRefreshEnabled = x.checked} disabled={isUpdating}> 145 - <Switch.Control className="data-[state=checked]:preset-filled-success-500"> 282 + <Switch.Control class="data-[state=checked]:preset-filled-success-500"> 146 283 <Switch.Thumb /> 147 284 </Switch.Control> 148 285 <Switch.Label>Auto-refresh ({AUTO_REFRESH_INTERVAL}s)</Switch.Label> ··· 152 289 </div> 153 290 </header> 154 291 155 - <div class="flex gap-10 mt-6 grid grid-cols-2"> 292 + <div class="gap-10 mt-6 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3"> 156 293 <div> 157 294 <h2 class="opacity-75 text-sm">Last known bundle</h2> 158 295 <div> ··· 167 304 <div> 168 305 <span class="opacity-50">{#if lastKnownBundle?.time} {formatDistanceToNow(lastKnownBundle.time, { addSuffix: true })}{/if}</span> 169 306 </div> 307 + <div class="mt-1"> 308 + {#if instancesInConflict.length > 0} 309 + โš ๏ธ Fork alert on {instancesInConflict.length} instances! 310 + {:else if !isConflict} 311 + โœ… Everything fine! 312 + {/if} 313 + </div> 170 314 </div> 171 315 </div> 172 316 <div> ··· 176 320 <div class="flex gap-4"> 177 321 <div class="mt-4"> 178 322 <Progress value={lastKnownBundle.mempoolPercent} class="items-center"> 179 - <Progress.Circle style="--size: 48px; --thickness: 6px;"> 323 + <Progress.Circle style="--size: 64px; --thickness: 10px;" class={lastKnownBundle.mempoolPercent > 95 ? 'animate-pulse' : ''}> 180 324 <Progress.CircleTrack /> 181 325 <Progress.CircleRange /> 182 326 </Progress.Circle> ··· 186 330 {#if lastKnownBundle.number > 0} 187 331 <div> 188 332 <div class="font-semibold text-2xl animate-pulse">{lastKnownBundle.number + 1}</div> 189 - <div>{formatNumber(lastKnownBundle.mempool)} / {formatNumber(BUNDLE_OPS)} <span class="opacity-50">({lastKnownBundle.mempoolPercent}%)</span></div> 333 + <div>{formatNumber(lastKnownBundle.mempool || 0)} / {formatNumber(BUNDLE_OPS)} <span class="opacity-50">({lastKnownBundle.mempoolPercent}%)</span></div> 190 334 {#if lastKnownBundle.etaNext} 191 - <div class="mt-2 opacity-50">ETA: {formatDistanceToNow(lastKnownBundle.etaNext)}</div> 335 + <div class="mt-1 opacity-50">ETA: {formatDistanceToNow(lastKnownBundle.etaNext)}</div> 192 336 {/if} 193 337 </div> 194 338 {/if} 195 339 </div> 196 340 </div> 341 + {#if lastKnownBundle.number > 0} 342 + <div class=""> 343 + <div> 344 + <h2 class="opacity-75 text-sm">Statistics</h2> 345 + </div> 346 + <div class="mt-2 grid grid-cols-1 gap-1"> 347 + <div><span class="opacity-50">Instances:</span> {instances.filter(i => i._head && !i._conflict).length} latest / {instances.length} total</div> 348 + <div><span class="opacity-50">PLC Operations:</span> {formatNumber((lastKnownBundle.number * BUNDLE_OPS) + (lastKnownBundle.mempool || 0))}</div> 349 + <div><span class="opacity-50">Bundles Size:</span> {#if lastKnownBundle.totalSize}{filesize(lastKnownBundle.totalSize)}{/if}</div> 350 + <div><span class="opacity-50">Uncompressed:</span> {#if lastKnownBundle.totalSizeUncompressed}{filesize(lastKnownBundle.totalSizeUncompressed)}{/if}</div> 351 + </div> 352 + </div> 353 + {/if} 197 354 </div> 198 355 199 356 <table class="table mt-10"> 200 357 <thead> 201 358 <tr> 202 359 <th>endpoint</th> 203 - <th>status</th> 204 - <th>last bundle</th> 205 - <th>mempool</th> 360 + <th>ok?</th> 361 + <th>last</th> 362 + <th>mempool</th> 363 + <th>age</th> 206 364 <th>head</th> 207 365 <th>root</th> 208 366 <th>version</th> 367 + <th>rsv?</th> 368 + <th>ws?</th> 369 + <th>uptime</th> 209 370 <th>latency</th> 210 371 </tr> 211 372 </thead> 212 - <tbody> 373 + <tbody class="[&>tr]:hover:bg-primary-500/10"> 213 374 {#each orderBy(instances, ...instanceOrderBy) as instance} 214 375 <tr> 215 376 <td><a href={instance.url} target="_blank" class="font-semibold">{instance.url.replace("https://", "")}</a></td> 216 - <td>{#if instance._head}{#if isConflict}โš ๏ธ{:else}โœ…{/if}{:else if instance.status}๐Ÿ”„{:else}โŒ›{/if}</td> 217 - <td>{#if instance.status?.bundles?.last_bundle}{instance.status?.bundles?.last_bundle}{/if}</td> 218 - <td>{#if instance.status?.mempool && instance.status?.bundles?.last_bundle === lastKnownBundle.number}{formatNumber(instance.status?.mempool.count)}{:else if instance.status}<span class="opacity-25">syncing</span>{/if}</td> 219 - <td><span class="font-mono text-xs {instance._head ? (isConflict ? 'text-error-600' : 'text-success-600') : 'opacity-50'}">{#if instance.status?.bundles?.head_hash}{instance.status?.bundles?.head_hash.slice(0, 7)}{/if}</span></td> 220 - <td><span class="font-mono text-xs {instance.status ? (instance.status?.bundles?.root_hash === ROOT ? 'text-success-600' : 'text-error-600') : ''}">{#if instance.status?.bundles?.root_hash}{instance.status?.bundles?.root_hash.slice(0, 7)}{/if}</span></td> 221 - <td>{#if instance.status?.server?.version}{instance.status?.server?.version}{/if}</td> 222 - <td class="opacity-50">{#if instance.status?.latency}{Math.round(instance.status?.latency)}ms{/if}</td> 377 + <td>{#if instance._head && instance.status?.ok}{#if instance._conflict}โš ๏ธ{:else}โœ…{/if}{:else if instance.status?.ok && instance._oldRoot}๐Ÿฆ‡{:else if instance.status?.ok}๐Ÿ”„{:else if instance.status?.error}โŒ{:else}โŒ›{/if}</td> 378 + {#if instance.status?.error} 379 + <td colspan="8" class="opacity-50 text-xs">Error: {instance.status?.error}</td> 380 + {:else} 381 + <td>{#if instance.status?.bundles?.last_bundle}<span class="{instance._conflict ? 'text-error-600' : ''}">{instance.status?.bundles?.last_bundle}</span>{/if}</td> 382 + <td>{#if instance.status?.mempool && (instance._head || instance._oldRoot)}<span class="{instance._conflict ? 'text-error-600' : (instance._oldRoot ? 'text-warning-500 opacity-50' : '')}">{formatNumber(instance.status?.mempool.count)}</span>{:else if instance.status?.error}<span class="opacity-25 text-xs">error</span>{:else if instance.status}<span class="opacity-25 text-xs">syncing</span>{/if}</td> 383 + <td> 384 + {#if instance.status?.mempool} 385 + <span class="text-xs opacity-50 {instance._conflict ? 'text-error-600' : (instance._oldRoot ? 'text-warning-500' : '')}"> 386 + {#if instance._head || instance._oldRoot} 387 + {secondsAge(instance.status?.mempool.last_op_age_seconds || 0)} 388 + {:else} 389 + {bundleAge(instance)} 390 + {/if} 391 + </span> 392 + {/if} 393 + </td> 394 + <td><span class="font-mono text-xs {instance._head ? (instance._conflict ? 'text-error-600' : 'text-success-600') : (instance._oldRoot ? 'text-warning-500 opacity-50' : 'opacity-50')}">{#if instance.status?.bundles?.head_hash}{instance.status?.bundles?.head_hash.slice(0, 7)}{/if}</span></td> 395 + <td><span class="font-mono text-xs {instance.status ? (instance.status?.bundles?.root_hash === ROOT ? 'text-success-600' : (PAST_ROOTS.includes(instance.status?.bundles?.root_hash) ? 'text-warning-500' : 'text-error-600')) : ''}">{#if instance.status?.bundles?.root_hash}{instance.status?.bundles?.root_hash.slice(0, 7)}{/if}</span></td> 396 + <td class="text-xs">{#if instance.status?.server?.version}<span title={instance.status?.server?.version}>{normalizedVersion(instance.status?.server?.version)}</span>{/if}</td> 397 + <td class="text-xs">{#if instance.status?.server?.resolver_enabled}โœ”๏ธŽ{:else if instance.status}<span class="opacity-25">-</span>{/if}</td> 398 + <td class="text-xs">{#if instance.status?.server?.websocket_enabled}โœ”๏ธŽ{:else if instance.status}<span class="opacity-25">-</span>{/if}</td> 399 + {/if} 400 + <td class="text-xs">{#if instance.status?.server?.uptime_seconds}{formatUptime(instance.status?.server?.uptime_seconds)}{/if}</td> 401 + <td class="text-xs opacity-50">{#if instance.status?.latency}<a href="{instance.url}/status">{Math.round(instance.status?.latency)}ms</a>{/if}</td> 223 402 </tr> 224 403 {/each} 225 404 </tbody> ··· 231 410 <span class="opacity-75">PLC Directory:</span> <a href="https://{PLC_DIRECTORY}">{PLC_DIRECTORY}</a> <span class="opacity-50">(origin)</span> 232 411 </div> 233 412 <div class="mt-2"> 234 - <span class="opacity-75">Root:</span> <span class="font-mono text-xs">{ROOT.slice(0)}</span> 413 + <span class="opacity-75">First hash (root):</span> <span class="font-mono text-xs">{ROOT.slice(0)}</span> 235 414 </div> 236 - </div> 237 415 238 - <hr class="hr mt-6" /> 239 - <div class="mt-2 opacity-50"> 240 - <div> 416 + <div class="mt-6 opacity-50"> 241 417 Last updated: {formatISO9075(lastUpdated)} 242 418 </div> 243 - <div class="mt-4"> 244 - Source: <a href="https://tangled.org/@tree.fail/plcbundle-watch">https://tangled.org/@tree.fail/plcbundle-watch</a> 419 + </div> 420 + <!--hr class="hr my-10" /--> 421 + <!--BundleDownloader instances={instances} /--> 422 + 423 + <hr class="hr mb-6 mt-12" /> 424 + <div class="opacity-50"> 425 + <div class="mt-4 text-sm"> 426 + <a href="https://tangled.org/@tree.fail/plcbundle-watch">Source Code</a> | โค๏ธ Made with love for <a href="https://atproto.com/">#atproto</a> community by <a href="https://bsky.app/profile/tree.fail">@tree.fail</a> using <a href="https://vite.dev/">Vite</a> & <a href="https://svelte.dev/">Svelte</a> 245 427 </div> 246 428 </div> 247 - 248 - 429 + 249 430 250 431 </div> 251 432 </main>
+508
src/BundleDownloader.svelte
··· 1 + <script lang="ts"> 2 + import { Progress } from '@skeletonlabs/skeleton-svelte'; 3 + import { tick } from 'svelte'; 4 + 5 + type Instance = { 6 + url: string; 7 + name?: string; 8 + } 9 + 10 + type InstanceStatus = { 11 + url: string; 12 + lastBundle: number; 13 + } 14 + 15 + type DownloadedBundle = { 16 + number: number; 17 + status: 'downloading' | 'success' | 'error' | 'cancelled'; 18 + size?: number; 19 + error?: string; 20 + source?: string; 21 + } 22 + 23 + let { instances = [] }: { instances: Instance[] } = $props(); 24 + 25 + let selectedInstance = $state('random'); 26 + let bundlesInput = $state(''); 27 + let isDownloading = $state(false); 28 + let downloadedBundles = $state<DownloadedBundle[]>([]); 29 + let progress = $state(0); 30 + let totalBundles = $state(0); 31 + let abortController: AbortController | null = null; 32 + let isStopping = $state(false); 33 + let instanceStatuses = $state<InstanceStatus[]>([]); 34 + let useDirectory = $state(true); 35 + let directoryHandle: FileSystemDirectoryHandle | null = null; 36 + let hasFileSystemAccess = $state(false); 37 + 38 + // Check if File System Access API is available 39 + $effect(() => { 40 + hasFileSystemAccess = 'showDirectoryPicker' in window; 41 + if (!hasFileSystemAccess) { 42 + useDirectory = false; 43 + } 44 + }); 45 + 46 + async function pickDirectory(): Promise<boolean> { 47 + if (!hasFileSystemAccess) { 48 + return false; 49 + } 50 + 51 + try { 52 + directoryHandle = await (window as any).showDirectoryPicker({ 53 + mode: 'readwrite' 54 + }); 55 + return true; 56 + } catch (e) { 57 + if ((e as Error).name !== 'AbortError') { 58 + console.error('Failed to pick directory:', e); 59 + } 60 + return false; 61 + } 62 + } 63 + 64 + async function fetchInstanceStatuses() { 65 + const statuses: InstanceStatus[] = []; 66 + 67 + await Promise.all(instances.map(async (instance) => { 68 + try { 69 + const response = await fetch(`${instance.url}/status`, { 70 + signal: abortController?.signal 71 + }); 72 + const data = await response.json(); 73 + statuses.push({ 74 + url: instance.url, 75 + lastBundle: data.bundles.last_bundle 76 + }); 77 + } catch (e) { 78 + console.warn(`Failed to fetch status from ${instance.url}`, e); 79 + } 80 + })); 81 + 82 + return statuses; 83 + } 84 + 85 + function getAvailableInstancesForBundle(bundleNumber: number): string[] { 86 + return instanceStatuses 87 + .filter(s => s.lastBundle >= bundleNumber) 88 + .map(s => s.url); 89 + } 90 + 91 + function getRandomInstance(bundleNumber?: number): Instance | null { 92 + let availableUrls: string[]; 93 + 94 + if (bundleNumber !== undefined && instanceStatuses.length > 0) { 95 + availableUrls = getAvailableInstancesForBundle(bundleNumber); 96 + if (availableUrls.length === 0) { 97 + return null; 98 + } 99 + } else { 100 + availableUrls = instances.map(i => i.url); 101 + } 102 + 103 + const randomUrl = availableUrls[Math.floor(Math.random() * availableUrls.length)]; 104 + return instances.find(i => i.url === randomUrl) || null; 105 + } 106 + 107 + function getInstanceUrl(bundleNumber?: number): string | null { 108 + if (selectedInstance === 'random') { 109 + const instance = getRandomInstance(bundleNumber); 110 + return instance?.url || null; 111 + } 112 + return selectedInstance; 113 + } 114 + 115 + function getInstanceName(url: string): string { 116 + const instance = instances.find(i => i.url === url); 117 + return instance?.name || new URL(url).hostname; 118 + } 119 + 120 + function parseBundlesInput(input: string): number[] | 'all' { 121 + const trimmed = input.trim(); 122 + 123 + if (!trimmed) { 124 + return 'all'; 125 + } 126 + 127 + if (trimmed.includes('-')) { 128 + const [start, end] = trimmed.split('-').map(s => parseInt(s.trim())); 129 + if (isNaN(start) || isNaN(end) || start > end) { 130 + throw new Error('Invalid range format'); 131 + } 132 + const bundles = []; 133 + for (let i = start; i <= end; i++) { 134 + bundles.push(i); 135 + } 136 + return bundles; 137 + } 138 + 139 + const num = parseInt(trimmed); 140 + if (isNaN(num)) { 141 + throw new Error('Invalid bundle number'); 142 + } 143 + return [num]; 144 + } 145 + 146 + async function getLastBundle(instanceUrl: string): Promise<number> { 147 + const response = await fetch(`${instanceUrl}/status`, { 148 + signal: abortController?.signal 149 + }); 150 + const data = await response.json(); 151 + return data.bundles.last_bundle; 152 + } 153 + 154 + async function downloadBundle(instanceUrl: string, bundleNumber: number): Promise<Blob> { 155 + const response = await fetch(`${instanceUrl}/data/${bundleNumber}`, { 156 + signal: abortController?.signal 157 + }); 158 + if (!response.ok) { 159 + throw new Error(`HTTP ${response.status}`); 160 + } 161 + return await response.blob(); 162 + } 163 + 164 + function padBundleNumber(num: number): string { 165 + return num.toString().padStart(6, '0'); 166 + } 167 + 168 + async function saveFileToDirectory(blob: Blob, bundleNumber: number) { 169 + if (!directoryHandle) { 170 + throw new Error('No directory selected'); 171 + } 172 + 173 + const fileName = `${padBundleNumber(bundleNumber)}.jsonl.zst`; 174 + const fileHandle = await directoryHandle.getFileHandle(fileName, { create: true }); 175 + const writable = await fileHandle.createWritable(); 176 + await writable.write(blob); 177 + await writable.close(); 178 + } 179 + 180 + function saveFileBrowser(blob: Blob, bundleNumber: number) { 181 + const url = URL.createObjectURL(blob); 182 + const link = document.createElement('a'); 183 + link.href = url; 184 + link.download = `${padBundleNumber(bundleNumber)}.jsonl.zst`; 185 + link.click(); 186 + URL.revokeObjectURL(url); 187 + } 188 + 189 + function stopDownload() { 190 + if (abortController) { 191 + isStopping = true; 192 + abortController.abort(); 193 + } 194 + } 195 + 196 + async function handleDownload() { 197 + if (!selectedInstance) { 198 + alert('Please select an instance'); 199 + return; 200 + } 201 + 202 + // If using directory mode, pick directory first 203 + if (useDirectory && hasFileSystemAccess) { 204 + const picked = await pickDirectory(); 205 + if (!picked) { 206 + return; // User cancelled 207 + } 208 + } 209 + 210 + let bundleNumbers: number[]; 211 + abortController = new AbortController(); 212 + isStopping = false; 213 + 214 + try { 215 + if (selectedInstance === 'random') { 216 + instanceStatuses = await fetchInstanceStatuses(); 217 + if (instanceStatuses.length === 0) { 218 + alert('No instances available'); 219 + return; 220 + } 221 + } 222 + 223 + const parsed = parseBundlesInput(bundlesInput); 224 + 225 + if (parsed === 'all') { 226 + let lastBundle: number; 227 + 228 + if (selectedInstance === 'random') { 229 + lastBundle = Math.max(...instanceStatuses.map(s => s.lastBundle)); 230 + } else { 231 + lastBundle = await getLastBundle(selectedInstance); 232 + } 233 + 234 + bundleNumbers = []; 235 + for (let i = 1; i <= lastBundle; i++) { 236 + bundleNumbers.push(i); 237 + } 238 + } else { 239 + bundleNumbers = parsed; 240 + } 241 + } catch (e) { 242 + if (e instanceof Error && e.name === 'AbortError') { 243 + return; 244 + } 245 + alert(e instanceof Error ? e.message : 'Invalid input'); 246 + return; 247 + } 248 + 249 + isDownloading = true; 250 + downloadedBundles = []; 251 + progress = 0; 252 + totalBundles = bundleNumbers.length; 253 + 254 + for (let i = 0; i < bundleNumbers.length; i++) { 255 + if (abortController?.signal.aborted) { 256 + break; 257 + } 258 + 259 + const bundleNum = bundleNumbers[i]; 260 + const instanceUrl = getInstanceUrl(bundleNum); 261 + 262 + if (!instanceUrl) { 263 + downloadedBundles = [...downloadedBundles, { 264 + number: bundleNum, 265 + status: 'error', 266 + error: 'No instance has this bundle', 267 + }]; 268 + progress = Math.round(((i + 1) / totalBundles) * 100); 269 + await tick(); 270 + continue; 271 + } 272 + 273 + downloadedBundles = [...downloadedBundles, { 274 + number: bundleNum, 275 + status: 'downloading', 276 + source: instanceUrl, 277 + }]; 278 + 279 + await tick(); 280 + 281 + try { 282 + const blob = await downloadBundle(instanceUrl, bundleNum); 283 + 284 + if (abortController?.signal.aborted) { 285 + downloadedBundles = downloadedBundles.map(b => 286 + b.number === bundleNum ? { ...b, status: 'cancelled' as const } : b 287 + ); 288 + break; 289 + } 290 + 291 + // Save file 292 + if (useDirectory && directoryHandle) { 293 + await saveFileToDirectory(blob, bundleNum); 294 + } else { 295 + saveFileBrowser(blob, bundleNum); 296 + } 297 + 298 + downloadedBundles = downloadedBundles.map(b => 299 + b.number === bundleNum 300 + ? { ...b, status: 'success' as const, size: blob.size } 301 + : b 302 + ); 303 + 304 + } catch (e) { 305 + if (e instanceof Error && e.name === 'AbortError') { 306 + downloadedBundles = downloadedBundles.map(b => 307 + b.number === bundleNum ? { ...b, status: 'cancelled' as const } : b 308 + ); 309 + break; 310 + } 311 + 312 + downloadedBundles = downloadedBundles.map(b => 313 + b.number === bundleNum 314 + ? { ...b, status: 'error' as const, error: e instanceof Error ? e.message : 'Unknown error' } 315 + : b 316 + ); 317 + } 318 + 319 + progress = Math.round(((i + 1) / totalBundles) * 100); 320 + await tick(); 321 + } 322 + 323 + isDownloading = false; 324 + isStopping = false; 325 + abortController = null; 326 + directoryHandle = null; 327 + } 328 + 329 + function formatBytes(bytes: number): string { 330 + if (bytes === 0) return '0 B'; 331 + const k = 1024; 332 + const sizes = ['B', 'KB', 'MB', 'GB']; 333 + const i = Math.floor(Math.log(bytes) / Math.log(k)); 334 + return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i]; 335 + } 336 + 337 + function clearResults() { 338 + downloadedBundles = []; 339 + progress = 0; 340 + totalBundles = 0; 341 + } 342 + 343 + let successCount = $derived(downloadedBundles.filter(b => b.status === 'success').length); 344 + let errorCount = $derived(downloadedBundles.filter(b => b.status === 'error').length); 345 + let cancelledCount = $derived(downloadedBundles.filter(b => b.status === 'cancelled').length); 346 + let totalSize = $derived(downloadedBundles.reduce((sum, b) => sum + (b.size || 0), 0)); 347 + </script> 348 + 349 + <div class="bundle-downloader card space-y-4"> 350 + <h2 class="text-2xl">Bundle Downloader</h2> 351 + 352 + <div class="space-y-3"> 353 + <label class="label"> 354 + <span>Instance</span> 355 + <select 356 + class="select p-3 text-sm" 357 + bind:value={selectedInstance} 358 + disabled={isDownloading} 359 + > 360 + <option value="random">๐ŸŽฒ Random (each bundle from different source)</option> 361 + {#each instances as instance} 362 + <option value={instance.url}> 363 + {instance.name || instance.url} 364 + </option> 365 + {/each} 366 + </select> 367 + </label> 368 + 369 + <label class="label"> 370 + <span>Bundles</span> 371 + <input 372 + class="input text-sm" 373 + type="text" 374 + bind:value={bundlesInput} 375 + disabled={isDownloading} 376 + placeholder="empty = all, 5 = single, 1-10 = range" 377 + /> 378 + <p class="text-xs opacity-75 mt-1"> 379 + Leave empty for all bundles, enter a number (e.g., <code>5</code>) or range (e.g., <code>1-10</code>) 380 + </p> 381 + </label> 382 + 383 + {#if hasFileSystemAccess} 384 + <label class="flex items-center space-x-2"> 385 + <input 386 + type="checkbox" 387 + class="checkbox" 388 + bind:checked={useDirectory} 389 + disabled={isDownloading} 390 + /> 391 + <span class="text-sm"> 392 + ๐Ÿ“ Save to directory (recommended for multiple files) 393 + </span> 394 + </label> 395 + {:else} 396 + <div class="alert variant-ghost-warning p-2 text-xs"> 397 + <span>โš ๏ธ Directory mode not available in this browser. Files will download individually.</span> 398 + </div> 399 + {/if} 400 + 401 + <div class="flex gap-2"> 402 + {#if !isDownloading} 403 + <button 404 + class="btn preset-tonal-primary flex-1" 405 + onclick={handleDownload} 406 + > 407 + {useDirectory && hasFileSystemAccess ? '๐Ÿ“ Choose Directory & Download' : '๐Ÿ“ฅ Download'} 408 + </button> 409 + {#if downloadedBundles.length > 0} 410 + <button 411 + class="btn preset-tonal-surface" 412 + onclick={clearResults} 413 + > 414 + ๐Ÿ—‘๏ธ Clear 415 + </button> 416 + {/if} 417 + {:else} 418 + <button 419 + class="btn preset-filled-error-500 flex-1" 420 + onclick={stopDownload} 421 + disabled={isStopping} 422 + > 423 + {isStopping ? 'โณ Stopping...' : 'โ›” Stop'} 424 + </button> 425 + {/if} 426 + </div> 427 + 428 + {#if isDownloading} 429 + <div class="space-y-2"> 430 + <Progress value={progress} max={100} /> 431 + <p class="text-sm text-center font-semibold"> 432 + {progress}% ({successCount}/{totalBundles}) 433 + </p> 434 + </div> 435 + {/if} 436 + </div> 437 + 438 + {#if downloadedBundles.length > 0} 439 + <div class="space-y-2"> 440 + <h3 class="text-2xl"> 441 + {isDownloading ? 'Downloading...' : 'Results'} 442 + ({successCount}/{downloadedBundles.length}) 443 + </h3> 444 + 445 + <div class="table-container max-h-64 overflow-y-auto"> 446 + <table class="table table-compact table-hover"> 447 + <thead> 448 + <tr> 449 + <th>File</th> 450 + <th>Source</th> 451 + <th>Status</th> 452 + <th class="text-right">Size</th> 453 + </tr> 454 + </thead> 455 + <tbody> 456 + {#each downloadedBundles as bundle (bundle.number)} 457 + <tr> 458 + <td class="font-mono text-xs">{padBundleNumber(bundle.number)}.jsonl.zst</td> 459 + <td class="text-xs" title={bundle.source}> 460 + {bundle.source ? getInstanceName(bundle.source) : '-'} 461 + </td> 462 + <td> 463 + {#if bundle.status === 'downloading'} 464 + <span class="badge variant-filled text-xs">โณ Downloading</span> 465 + {:else if bundle.status === 'success'} 466 + <span class="badge variant-filled-success text-xs">โœ… Success</span> 467 + {:else if bundle.status === 'cancelled'} 468 + <span class="badge variant-filled-warning text-xs">โš ๏ธ Cancelled</span> 469 + {:else} 470 + <span class="badge variant-filled-error text-xs" title={bundle.error}>โŒ Error</span> 471 + {/if} 472 + </td> 473 + <td class="text-sm text-right">{bundle.size ? formatBytes(bundle.size) : '-'}</td> 474 + </tr> 475 + {/each} 476 + </tbody> 477 + </table> 478 + </div> 479 + 480 + <div class="card p-3 variant-ghost-surface grid grid-cols-4 gap-2 text-sm"> 481 + <div> 482 + <div class="font-bold text-success-500"> 483 + {successCount} 484 + </div> 485 + <div class="opacity-75">Success</div> 486 + </div> 487 + <div> 488 + <div class="font-bold text-error-500"> 489 + {errorCount} 490 + </div> 491 + <div class="opacity-75">Failed</div> 492 + </div> 493 + <div> 494 + <div class="font-bold text-warning-500"> 495 + {cancelledCount} 496 + </div> 497 + <div class="opacity-75">Cancelled</div> 498 + </div> 499 + <div> 500 + <div class="font-bold"> 501 + {formatBytes(totalSize)} 502 + </div> 503 + <div class="opacity-75">Total</div> 504 + </div> 505 + </div> 506 + </div> 507 + {/if} 508 + </div>
+1 -1
src/app.css
··· 12 12 @apply py-1.5 px-2; 13 13 } 14 14 15 - a { 15 + a:not(.no-style) { 16 16 @apply underline hover:no-underline; 17 17 } 18 18
+50 -13
src/instances.json
··· 1 1 [ 2 - { 3 - "url": "https://plcbundle.atscan.net" 4 - }, 5 - { 6 - "url": "https://plc.j4ck.xyz" 7 - }, 8 - { 9 - "url": "https://plc.indexx.dev" 10 - }, 11 - { 12 - "url": "https://plc.nyxt.dev" 13 - } 14 - ] 2 + { 3 + "url": "https://plcbundle.atscan.net", 4 + "country": "AT", 5 + "maintainer": "@tree.fail" 6 + }, 7 + { 8 + "url": "https://plcbundle2.atscan.net", 9 + "country": "CZ", 10 + "maintainer": "@tree.fail" 11 + }, 12 + { 13 + "url": "https://plcbundle3.atscan.net", 14 + "country": "CZ", 15 + "maintainer": "@tree.fail" 16 + }, 17 + { 18 + "url": "https://plc.j4ck.xyz", 19 + "country": "UK", 20 + "maintainer": "@j4ck.xyz" 21 + }, 22 + { 23 + "url": "https://plc.indexx.dev", 24 + "country": "US", 25 + "maintainer": "@indexx.dev" 26 + }, 27 + { 28 + "url": "https://plc.nyxt.dev" 29 + }, 30 + { 31 + "url": "https://plc.madebydanny.uk", 32 + "country": "US", 33 + "maintainer": "@madebydanny.uk" 34 + }, 35 + { 36 + "url": "https://plc.tartarus.us" 37 + }, 38 + { 39 + "url": "https://plcbundle.snek.cc", 40 + "country": "US", 41 + "maintainer": "@jackvalinsky.com" 42 + }, 43 + { 44 + "url": "https://plc.dane.computer", 45 + "country": "CA", 46 + "maintainer": "@dane.is.extraordinarily.cool" 47 + }, 48 + { 49 + "url": "https://plc.witchcraft.systems" 50 + } 51 + ]
+53
src/lib/utils.ts
··· 1 + import numeral from 'numeral'; 2 + 3 + export function formatNumber(n: number) { 4 + return numeral(n).format() 5 + } 6 + 7 + export function formatUptime(totalSeconds: number): string { 8 + if (totalSeconds < 0) { 9 + return "Invalid input: seconds cannot be negative"; 10 + } 11 + if (totalSeconds === 0) { 12 + return "0s"; 13 + } 14 + 15 + let parts: string[] = []; 16 + let displayUnits: [string, number][]; 17 + 18 + const SECONDS_IN_MINUTE = 60; 19 + const SECONDS_IN_HOUR = 3600; // 60 minutes * 60 seconds/minute 20 + const SECONDS_IN_DAY = 24 * SECONDS_IN_HOUR; 21 + 22 + if (totalSeconds > SECONDS_IN_DAY) { // If uptime is bigger than 1 day 23 + displayUnits = [ 24 + ['d', SECONDS_IN_DAY], 25 + ['h', SECONDS_IN_HOUR], 26 + ]; 27 + } else if (totalSeconds > SECONDS_IN_MINUTE) { // If uptime is bigger than 60 seconds but not bigger than 60 minutes 28 + displayUnits = [ 29 + ['d', SECONDS_IN_DAY], 30 + ['h', SECONDS_IN_HOUR], 31 + ['m', SECONDS_IN_MINUTE], 32 + ]; 33 + } else { // If uptime is 60 seconds or less 34 + displayUnits = [ 35 + ['d', SECONDS_IN_DAY], 36 + ['h', SECONDS_IN_HOUR], 37 + ['m', SECONDS_IN_MINUTE], 38 + ['s', 1], 39 + ]; 40 + } 41 + 42 + let remainingSeconds = totalSeconds; 43 + 44 + for (const [unitChar, unitSeconds] of displayUnits) { 45 + if (remainingSeconds >= unitSeconds) { 46 + const value = Math.floor(remainingSeconds / unitSeconds); 47 + parts.push(`${value}${unitChar}`); 48 + remainingSeconds %= unitSeconds; 49 + } 50 + } 51 + 52 + return parts.join(""); 53 + }
+1
src/types/lodash.d.ts
··· 1 + declare module 'lodash/orderBy';