feat(tl): added blogfork domain, auto-choose domain for docs
This commit is contained in:
parent
b7fa085b88
commit
afb07534f9
3 changed files with 39 additions and 11 deletions
|
@ -10,7 +10,8 @@ export const MTP_SCHEMA_JSON_FILE = join(__dirname, '../mtp-schema.json')
|
||||||
export const ERRORS_JSON_FILE = join(__dirname, '../raw-errors.json')
|
export const ERRORS_JSON_FILE = join(__dirname, '../raw-errors.json')
|
||||||
|
|
||||||
export const CORE_DOMAIN = 'https://core.telegram.org'
|
export const CORE_DOMAIN = 'https://core.telegram.org'
|
||||||
export const COREFORK_DOMAIN = 'https://core.telegram.org'
|
export const COREFORK_DOMAIN = 'https://corefork.telegram.org'
|
||||||
|
export const BLOGFORK_DOMAIN = 'https://blogfork.telegram.org'
|
||||||
|
|
||||||
export const TDESKTOP_SCHEMA =
|
export const TDESKTOP_SCHEMA =
|
||||||
'https://raw.githubusercontent.com/telegramdesktop/tdesktop/dev/Telegram/Resources/tl/api.tl'
|
'https://raw.githubusercontent.com/telegramdesktop/tdesktop/dev/Telegram/Resources/tl/api.tl'
|
||||||
|
|
|
@ -4,7 +4,9 @@ import { splitNameToNamespace } from '@mtcute/tl-utils/src/utils'
|
||||||
import { camelToPascal, snakeToCamel } from '@mtcute/tl-utils/src/codegen/utils'
|
import { camelToPascal, snakeToCamel } from '@mtcute/tl-utils/src/codegen/utils'
|
||||||
import {
|
import {
|
||||||
API_SCHEMA_JSON_FILE,
|
API_SCHEMA_JSON_FILE,
|
||||||
|
BLOGFORK_DOMAIN,
|
||||||
CORE_DOMAIN,
|
CORE_DOMAIN,
|
||||||
|
COREFORK_DOMAIN,
|
||||||
DESCRIPTIONS_YAML_FILE,
|
DESCRIPTIONS_YAML_FILE,
|
||||||
DOC_CACHE_FILE,
|
DOC_CACHE_FILE,
|
||||||
} from './constants'
|
} from './constants'
|
||||||
|
@ -77,6 +79,30 @@ function extractDescription($: CheerioInit) {
|
||||||
// from https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json
|
// from https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json
|
||||||
const PROGRESS_CHARS = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
|
const PROGRESS_CHARS = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
|
||||||
|
|
||||||
|
async function chooseDomainForDocs(
|
||||||
|
headers: Record<string, string>
|
||||||
|
): Promise<[number, string]> {
|
||||||
|
let maxLayer = 0
|
||||||
|
let maxDomain = ''
|
||||||
|
|
||||||
|
for (const domain of [CORE_DOMAIN, COREFORK_DOMAIN, BLOGFORK_DOMAIN]) {
|
||||||
|
const index = await fetchRetry(`${domain}/schema`, { headers })
|
||||||
|
const actualLayer = parseInt(
|
||||||
|
cheerio
|
||||||
|
.load(index)('.dev_layer_select .dropdown-toggle')
|
||||||
|
.text()
|
||||||
|
.match(/layer (\d+)/i)![1]
|
||||||
|
)
|
||||||
|
|
||||||
|
if (actualLayer > maxLayer) {
|
||||||
|
maxLayer = actualLayer
|
||||||
|
maxDomain = domain
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [maxLayer, maxDomain]
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchDocumentation(
|
export async function fetchDocumentation(
|
||||||
schema: TlFullSchema,
|
schema: TlFullSchema,
|
||||||
layer: number,
|
layer: number,
|
||||||
|
@ -89,14 +115,14 @@ export async function fetchDocumentation(
|
||||||
'Chrome/87.0.4280.88 Safari/537.36',
|
'Chrome/87.0.4280.88 Safari/537.36',
|
||||||
}
|
}
|
||||||
|
|
||||||
const index = await fetchRetry(`${CORE_DOMAIN}/schema`, { headers })
|
const [actualLayer, domain] = await chooseDomainForDocs(headers)
|
||||||
const actualLayer = cheerio
|
|
||||||
.load(index)('.dev_layer_select .dropdown-toggle')
|
console.log('Using domain %s (has layer %s)', domain, actualLayer)
|
||||||
.text()
|
|
||||||
.match(/layer (\d+)/i)![1]
|
|
||||||
|
|
||||||
const ret: CachedDocumentation = {
|
const ret: CachedDocumentation = {
|
||||||
updated: `${new Date().toLocaleString('ru-RU')} (layer ${actualLayer})`,
|
updated: `${new Date().toLocaleString(
|
||||||
|
'ru-RU'
|
||||||
|
)} (layer ${actualLayer}) - from ${domain}`,
|
||||||
classes: {},
|
classes: {},
|
||||||
methods: {},
|
methods: {},
|
||||||
unions: {},
|
unions: {},
|
||||||
|
@ -118,7 +144,7 @@ export async function fetchDocumentation(
|
||||||
for (const entry of schema.entries) {
|
for (const entry of schema.entries) {
|
||||||
log(`📥 ${entry.kind} ${entry.name}`)
|
log(`📥 ${entry.kind} ${entry.name}`)
|
||||||
|
|
||||||
const url = `${CORE_DOMAIN}/${
|
const url = `${domain}/${
|
||||||
entry.kind === 'class' ? 'constructor' : 'method'
|
entry.kind === 'class' ? 'constructor' : 'method'
|
||||||
}/${entry.name}`
|
}/${entry.name}`
|
||||||
|
|
||||||
|
@ -197,7 +223,7 @@ export async function fetchDocumentation(
|
||||||
|
|
||||||
log(`📥 union ${name}`)
|
log(`📥 union ${name}`)
|
||||||
|
|
||||||
const url = `${CORE_DOMAIN}/type/${name}`
|
const url = `${domain}/type/${name}`
|
||||||
|
|
||||||
const html = await fetchRetry(url, {
|
const html = await fetchRetry(url, {
|
||||||
headers,
|
headers,
|
||||||
|
|
|
@ -19,8 +19,8 @@ import {
|
||||||
API_SCHEMA_JSON_FILE,
|
API_SCHEMA_JSON_FILE,
|
||||||
TDESKTOP_SCHEMA,
|
TDESKTOP_SCHEMA,
|
||||||
TDLIB_SCHEMA,
|
TDLIB_SCHEMA,
|
||||||
COREFORK_DOMAIN,
|
COREFORK_DOMAIN, BLOGFORK_DOMAIN
|
||||||
} from './constants'
|
} from "./constants";
|
||||||
import { fetchRetry } from './utils'
|
import { fetchRetry } from './utils'
|
||||||
import {
|
import {
|
||||||
applyDocumentation,
|
applyDocumentation,
|
||||||
|
@ -189,6 +189,7 @@ async function main() {
|
||||||
await fetchTdesktopSchema(),
|
await fetchTdesktopSchema(),
|
||||||
await fetchCoreSchema(),
|
await fetchCoreSchema(),
|
||||||
await fetchCoreSchema(COREFORK_DOMAIN, 'Corefork'),
|
await fetchCoreSchema(COREFORK_DOMAIN, 'Corefork'),
|
||||||
|
await fetchCoreSchema(BLOGFORK_DOMAIN, 'Blogfork'),
|
||||||
{
|
{
|
||||||
name: 'Custom',
|
name: 'Custom',
|
||||||
layer: 0, // handled manually
|
layer: 0, // handled manually
|
||||||
|
|
Loading…
Reference in a new issue