refactor: switch to vercel blob for docs

This commit is contained in:
iCrawl
2023-11-13 23:15:16 +01:00
parent ffc3ea5c3f
commit 01c63d2e0f
9 changed files with 278 additions and 69 deletions

View File

@@ -43,6 +43,7 @@
"@actions/core": "^1.10.1",
"@actions/glob": "^0.4.0",
"@discordjs/scripts": "workspace:^",
"@vercel/blob": "^0.15.0",
"@vercel/postgres": "^0.5.1",
"meilisearch": "^0.35.0",
"tslib": "^2.6.2",

View File

@@ -2,6 +2,7 @@ import { readFile } from 'node:fs/promises';
import process from 'node:process';
import { getInput, setFailed } from '@actions/core';
import { create } from '@actions/glob';
import { put } from '@vercel/blob';
import { createPool } from '@vercel/postgres';
if (!process.env.DATABASE_URL) {
@@ -20,7 +21,15 @@ for await (const file of globber.globGenerator()) {
const data = await readFile(file, 'utf8');
try {
console.log(`Uploading ${file} with ${version}...`);
await pool.sql`insert into documentation (version, data) values (${version}, ${data}) on conflict (name, version) do update set data = EXCLUDED.data`;
const { name } = JSON.parse(data);
const { url } = await put(`${name.replace('@discordjs/', '')}/${version}.json`, data, {
access: 'public',
addRandomSuffix: false,
});
await pool.sql`insert into documentation (name, version, url) values (${name.replace(
'@discordjs/',
'',
)}, ${version}, ${url}) on conflict (name, version, url) do update set url = EXCLUDED.url`;
} catch (error) {
const err = error as Error;
console.log(err.message);

View File

@@ -3,6 +3,7 @@ import { setFailed } from '@actions/core';
import { generateAllIndices } from '@discordjs/scripts';
import { createPool } from '@vercel/postgres';
import { MeiliSearch } from 'meilisearch';
import { fetch } from 'undici';
if (!process.env.DATABASE_URL) {
setFailed('DATABASE_URL is not set');
@@ -36,9 +37,10 @@ try {
},
fetchPackageVersionDocs: async (pkg, version) => {
console.log(`Fetching data for ${pkg} ${version}...`);
const { rows } = await pool.sql`select data from documentation where name = ${pkg} and version = ${version}`;
const { rows } = await pool.sql`select url from documentation where name = ${pkg} and version = ${version}`;
const res = await fetch(rows[0]?.url ?? '');
return rows[0]?.data ?? null;
return res.json();
},
writeToFile: false,
});