mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
feat: local and preview detection
This commit is contained in:
30
apps/website/src/util/fetchNode.ts
Normal file
30
apps/website/src/util/fetchNode.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { ENV } from './env';
|
||||
|
||||
export async function fetchNode({
|
||||
item,
|
||||
packageName,
|
||||
version,
|
||||
}: {
|
||||
readonly item: any;
|
||||
readonly packageName: string;
|
||||
readonly version: string;
|
||||
}) {
|
||||
const normalizeItem = item.split(encodeURIComponent(':')).join('.').toLowerCase();
|
||||
|
||||
if (ENV.IS_LOCAL_DEV) {
|
||||
const fileContent = await readFile(
|
||||
join(process.cwd(), `../../packages/${packageName}/docs/split/${version}.${normalizeItem}.api.json`),
|
||||
'utf8',
|
||||
);
|
||||
return JSON.parse(fileContent);
|
||||
}
|
||||
|
||||
const isMainVersion = version === 'main';
|
||||
const fileContent = await fetch(
|
||||
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizeItem}.api.json`,
|
||||
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
|
||||
);
|
||||
return fileContent.json();
|
||||
}
|
||||
Reference in New Issue
Block a user