feat: add patch size estimation for game updates

- HEAD request to game-patches.hytale.com for content-length
- Track lastPatchId in state to calculate patch delta
- Display formatted size (~55.4 MiB) in update notifications

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
devilreef 2026-01-16 01:38:12 +06:00
parent a7d4df6986
commit 96eb5f754d
2 changed files with 41 additions and 4 deletions

View file

@ -1,7 +1,20 @@
import type { PatchesUpdate } from './tracker.js'
function formatBytes(bytes: number): string {
const units = ['B', 'KiB', 'MiB', 'GiB']
let size = bytes
let unitIndex = 0
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024
unitIndex++
}
return `${size.toFixed(1)} ${units[unitIndex]}`
}
export function formatPatchesUpdate(update: PatchesUpdate): string {
const { patchline, version, previousVersion, patchId } = update
const { patchline, version, previousVersion, patchId, patchSize } = update
const emoji = patchline === 'release' ? '🎮' : '🧪'
return `<b>${emoji} Hytale Game Patch Update</b>
@ -9,5 +22,6 @@ export function formatPatchesUpdate(update: PatchesUpdate): string {
<b>Patchline:</b> <code>${patchline}</code>
<b>New version:</b> <code>${version}</code>
${previousVersion !== 'unknown' ? `<b>Previous:</b> <code>${previousVersion}</code>` : ''}
${patchId ? `<b>Patch ID:</b> <code>${patchId}</code>` : ''}`
${patchId ? `<b>Patch ID:</b> <code>${patchId}</code>` : ''}
${patchSize ? `<b>Size:</b> ~<code>${formatBytes(patchSize)}</code>` : ''}`
}