import fs from 'node:fs/promises'; import path from 'node:path'; import { createHash } from 'node:crypto'; // Public documentation only. Never read a credential or follow an upstream redirect. const output = path.resolve(process.argv[2] || 'output/pi-compatibility-20261021/public-docs'); await fs.mkdir(output, { recursive: true }); const paths = ['/api/v2/catalog/models?format=skill', '/api/v2/catalog/models', '/docs', '/openapi.json']; const results = await Promise.all(paths.map(async (pathname, index) => { try { const response = await fetch('https://api.vip98k.com' + pathname, { method: 'GET', redirect: 'manual', signal: AbortSignal.timeout(25000), headers: { Accept: 'application/json, text/markdown, text/html;q=0.8' }, }); const text = await response.text(); if (Buffer.byteLength(text) > 8 * 1024 * 1024) throw Error('公开文档超过8MB验证上限'); const file = path.join(output, `${index}.txt`); await fs.writeFile(file, text); let value; try { value = JSON.parse(text); } catch { /* A documentation page can be Markdown or HTML. */ } return { path: pathname, status: response.status, contentType: response.headers.get('content-type'), bytes: Buffer.byteLength(text), sha256: createHash('sha256').update(text).digest('hex'), file, keys: value ? Object.keys(value) : undefined, title: text.match(/