mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
fix(fetchVersions): Sort package versions (#10695)
* fix(fetchVersions): sort package versions * fix(middleware): fix stable redirect
This commit is contained in:
@@ -9,9 +9,12 @@ async function fetchLatestVersion(packageName: string): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { rows } = await sql`select version from documentation where name = ${packageName} order by version desc`;
|
const { rows } = await sql<{ version: string }>`with ordered_versions as (
|
||||||
|
select version from documentation where name = ${packageName} and version != 'main' order by string_to_array(version, '.')::int[] desc
|
||||||
|
)
|
||||||
|
select version from ordered_versions limit 1`;
|
||||||
|
|
||||||
return rows.map((row) => row.version).at(1) ?? 'main';
|
return rows[0]?.version ?? 'main';
|
||||||
} catch {
|
} catch {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import { sql } from '@vercel/postgres';
|
|
||||||
import { ENV } from './env';
|
|
||||||
|
|
||||||
export async function fetchLatestVersion(packageName: string): Promise<string> {
|
|
||||||
if (ENV.IS_LOCAL_DEV) {
|
|
||||||
return 'main';
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const { rows } = await sql`select version from documentation where name = ${packageName} order by version desc`;
|
|
||||||
|
|
||||||
return rows.map((row) => row.version).at(1) ?? 'main';
|
|
||||||
} catch {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,16 @@ export async function fetchVersions(packageName: string) {
|
|||||||
try {
|
try {
|
||||||
const { rows } = await sql<{
|
const { rows } = await sql<{
|
||||||
version: string;
|
version: string;
|
||||||
}>`select version from documentation where name = ${packageName} order by version desc`;
|
}>`select version from documentation where name = ${packageName} 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;
|
||||||
|
`;
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user