feat: discord-api-types on docs

This commit is contained in:
iCrawl
2025-05-13 01:33:48 +02:00
parent b3db92edfb
commit aa533efe26
15 changed files with 93 additions and 109 deletions

View File

@@ -1,34 +1,36 @@
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
// import { sql } from '@vercel/postgres';
import { PACKAGES_WITH_ENTRY_POINTS } from './constants';
import { ENV } from './env';
export async function fetchEntryPoints(packageName: string, version: string) {
const hasEntryPoint = PACKAGES_WITH_ENTRY_POINTS.includes(packageName);
if (!hasEntryPoint) {
return [];
}
if (ENV.IS_LOCAL_DEV) {
const fileContent = await readFile(
join(process.cwd(), `../../packages/${packageName}/docs/${packageName}/split/${version}.entrypoints.api.json`),
join(
process.cwd(),
`${hasEntryPoint ? `../../../discord-api-types` : `../../packages/${packageName}`}/docs/${packageName}/split/${version}.entrypoints.api.json`,
),
'utf8',
);
return JSON.parse(fileContent);
}
// try {
// const { rows } = await sql<{
// entryPoint: string;
// }>`select entryPoint from documentation where name = ${packageName} and version = ${version} order by
// case
// when version = 'main' then 0
// else 1
// end,
// case
// when version = 'main' then null
// else string_to_array(version, '.')::int[]
// end desc;
// `;
const isMain = version === 'main';
const fileContent = await fetch(
`${process.env.CF_R2_DOCS_BUCKET_URL}/${packageName}/${version}.entrypoints.api.json`,
{ next: { revalidate: isMain ? 0 : 604_800 } },
);
// return rows;
// } catch {
return [];
// }
if (!fileContent.ok) {
return null;
}
return fileContent.json();
}