feat: add hytale-presskit module for Creator Presskit tracking
Adds new module to track CreatorPressKit.zip file size changes via HEAD requests. Alerts with old/new size and diff. Also updates sign-token.ts with correct account ID. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e0ec995068
commit
be1102119a
5 changed files with 153 additions and 1 deletions
46
src/modules/hytale-presskit/tracker.ts
Normal file
46
src/modules/hytale-presskit/tracker.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import type { StateStore } from '../../core/state-store.js'
|
||||
|
||||
export interface PresskitUpdate {
|
||||
size: number
|
||||
previousSize: number | null
|
||||
sizeDiff: number
|
||||
date: string
|
||||
}
|
||||
|
||||
const ENDPOINT = 'https://cdn.hytale.com/CreatorPressKit.zip'
|
||||
const STATE_KEY = 'hytale-presskit'
|
||||
|
||||
export async function checkPresskitUpdate(stateStore: StateStore): Promise<PresskitUpdate | null> {
|
||||
const response = await fetch(ENDPOINT, { method: 'HEAD' })
|
||||
if (!response.ok) {
|
||||
throw new Error(`Presskit endpoint returned ${response.status}`)
|
||||
}
|
||||
|
||||
const contentLength = response.headers.get('content-length')
|
||||
const date = response.headers.get('date')
|
||||
|
||||
if (!contentLength) {
|
||||
throw new Error('Content-Length header missing')
|
||||
}
|
||||
|
||||
const size = parseInt(contentLength, 10)
|
||||
|
||||
const state = stateStore.get<{ lastSize?: number, lastDate?: string }>(STATE_KEY)
|
||||
const lastSize = state?.lastSize ?? null
|
||||
|
||||
if (lastSize === size) {
|
||||
// No update, just update check time
|
||||
stateStore.set(STATE_KEY, { lastSize: size, lastDate: date || new Date().toISOString() })
|
||||
return null
|
||||
}
|
||||
|
||||
// Update detected
|
||||
stateStore.set(STATE_KEY, { lastSize: size, lastDate: date || new Date().toISOString() })
|
||||
|
||||
return {
|
||||
size,
|
||||
previousSize: lastSize,
|
||||
sizeDiff: lastSize !== null ? size - lastSize : 0,
|
||||
date: date || new Date().toISOString(),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue