Skip to content

Commit 8a269ea

Browse files
committed
fix(admin): correct app-info endpoint and monorepo release lookup
- system.ts: switch getAppInfo from `/` to `/info` so the request resolves through the V2 ApiController route without depending on Fastify's trailing-slash handling, restoring the dashboard's system version. - github-update.ts: point both system and dashboard update checks at `mx-space/core` and discriminate by tag prefix (`v*` vs `admin-v*`), since `mx-space/mx-server` and `mx-space/mx-admin` are archived and the monorepo no longer publishes there. Filter out drafts/prereleases.
1 parent 1d7c110 commit 8a269ea

2 files changed

Lines changed: 59 additions & 11 deletions

File tree

apps/admin/src/api/github-update.ts

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ interface GitHubReleaseResponse {
1414
name: string | null
1515
published_at: string | null
1616
tag_name: string
17+
draft?: boolean
18+
prerelease?: boolean
1719
}
1820

1921
export interface GitHubUpdateVersions {
@@ -23,27 +25,64 @@ export interface GitHubUpdateVersions {
2325
systemRelease: GitHubReleaseDetails
2426
}
2527

28+
const MONOREPO = 'mx-space/core'
29+
const ADMIN_PREFIX = 'admin-v'
30+
const SYSTEM_PREFIX = 'v'
31+
2632
export async function checkUpdateFromGitHub(): Promise<GitHubUpdateVersions> {
2733
const [systemRelease, dashboardRelease] = await Promise.all([
28-
fetchRelease('mx-server', 'latest'),
29-
fetchRelease('mx-admin', 'latest'),
34+
fetchLatestRelease('mx-server'),
35+
fetchLatestRelease('mx-admin'),
3036
])
3137

3238
return {
33-
dashboard: normalizeVersion(dashboardRelease.tagName),
39+
dashboard: stripPrefix(dashboardRelease.tagName, 'mx-admin'),
3440
dashboardRelease,
35-
system: normalizeVersion(systemRelease.tagName),
41+
system: stripPrefix(systemRelease.tagName, 'mx-server'),
3642
systemRelease,
3743
}
3844
}
3945

4046
export function getReleaseDetails(repo: UpdateRepo, version: string) {
41-
return fetchRelease(repo, `tags/v${normalizeVersion(version)}`)
47+
const tag =
48+
repo === 'mx-admin'
49+
? `${ADMIN_PREFIX}${normalizeVersion(version)}`
50+
: `${SYSTEM_PREFIX}${normalizeVersion(version)}`
51+
return fetchReleaseByTag(tag)
4252
}
4353

44-
async function fetchRelease(repo: UpdateRepo, release: 'latest' | string) {
54+
async function fetchLatestRelease(
55+
repo: UpdateRepo,
56+
): Promise<GitHubReleaseDetails> {
4557
const response = await fetch(
46-
`https://api.github.com/repos/mx-space/${repo}/releases/${release}`,
58+
`https://api.github.com/repos/${MONOREPO}/releases?per_page=50`,
59+
{
60+
headers: {
61+
accept: 'application/vnd.github+json',
62+
},
63+
},
64+
)
65+
66+
if (!response.ok) {
67+
throw new Error(`GitHub release request failed: ${response.status}`)
68+
}
69+
70+
const releases = (await response.json()) as GitHubReleaseResponse[]
71+
const match = releases.find(
72+
(release) =>
73+
!release.draft &&
74+
!release.prerelease &&
75+
matchesRepo(release.tag_name, repo),
76+
)
77+
if (!match) {
78+
throw new Error(`No ${repo} release found in ${MONOREPO}`)
79+
}
80+
return mapRelease(match)
81+
}
82+
83+
async function fetchReleaseByTag(tag: string): Promise<GitHubReleaseDetails> {
84+
const response = await fetch(
85+
`https://api.github.com/repos/${MONOREPO}/releases/tags/${tag}`,
4786
{
4887
headers: {
4988
accept: 'application/vnd.github+json',
@@ -58,6 +97,16 @@ async function fetchRelease(repo: UpdateRepo, release: 'latest' | string) {
5897
return mapRelease((await response.json()) as GitHubReleaseResponse)
5998
}
6099

100+
function matchesRepo(tagName: string, repo: UpdateRepo) {
101+
if (repo === 'mx-admin') return tagName.startsWith(ADMIN_PREFIX)
102+
return tagName.startsWith(SYSTEM_PREFIX) && !tagName.startsWith(ADMIN_PREFIX)
103+
}
104+
105+
function stripPrefix(tagName: string, repo: UpdateRepo) {
106+
const prefix = repo === 'mx-admin' ? ADMIN_PREFIX : SYSTEM_PREFIX
107+
return tagName.startsWith(prefix) ? tagName.slice(prefix.length) : tagName
108+
}
109+
61110
function mapRelease(release: GitHubReleaseResponse): GitHubReleaseDetails {
62111
return {
63112
body: release.body,

apps/admin/src/api/system.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { AppInfo } from '~/models/system'
2-
31
import { API_URL } from '~/constants/env'
2+
import type { AppInfo } from '~/models/system'
43

54
import {
65
buildAdminRequestHeaders,
@@ -45,12 +44,12 @@ export async function checkInit() {
4544
return (await response.json()) as { isInit: boolean }
4645
} catch (error) {
4746
if (error instanceof Error) throw error
48-
throw new Error('Init check failed')
47+
throw new Error('Init check failed', { cause: error })
4948
}
5049
}
5150

5251
export function getAppInfo() {
53-
return getJson<AppInfo>('/')
52+
return getJson<AppInfo>('/info')
5453
}
5554

5655
export function getInitDefaultConfigs() {

0 commit comments

Comments
 (0)