/** * GEO 数据库文件的本地状态:多大、多久没更新了。 * * 内核不提供这个信息,但文件就躺在它的工作目录里,和 Patchbay 服务端 * 在同一台机器上,直接 stat 就是。 */ import { readdir, stat } from 'node:fs/promises' import { join } from 'node:path' import { DEFAULT_GEOX_URLS, GEO_FILES } from '../shared/geo.ts' import type { GeoFileStatus } from '../shared/geo.ts' import type { Env } from './env.ts' export async function geoStatus( env: Env, geoxUrl: Record, ): Promise { const entries = await readdir(env.mihomoHome).catch(() => [] as string[]) return Promise.all( GEO_FILES.map(async ({ key, configKey, file }) => { // 内核找 GeoIP.dat/GeoSite.dat 时大小写不敏感(constant/path.go:193-224),这里照做 const actual = entries.find((name) => name.toLowerCase() === file.toLowerCase()) let size: number | null = null let updatedAt: string | null = null if (actual) { const info = await stat(join(env.mihomoHome, actual)).catch(() => null) if (info) { size = info.size updatedAt = info.mtime.toISOString() } } const configured = geoxUrl[configKey] const url = typeof configured === 'string' && configured !== '' ? configured : (DEFAULT_GEOX_URLS[configKey] ?? '') return { key, configKey, url, size, updatedAt } }), ) }