From 6955d83b0c6bc8c6bb585f37c8eb6407b879438e Mon Sep 17 00:00:00 2001 From: diced Date: Mon, 20 Feb 2023 23:17:04 -0800 Subject: [PATCH] feat: better version checking --- src/components/Layout.tsx | 12 +++++++----- src/lib/queries/version.ts | 13 ++++++++++++- src/pages/api/version.ts | 25 +++++++++++++++++++++---- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index 282dd13..38800c9 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -289,9 +289,11 @@ export default function Layout({ children, props }) { - {version.data.local} + {version.data.versions.current} diff --git a/src/lib/queries/version.ts b/src/lib/queries/version.ts index dbf5fc3..c9ec854 100644 --- a/src/lib/queries/version.ts +++ b/src/lib/queries/version.ts @@ -1,7 +1,18 @@ import { useQuery } from '@tanstack/react-query'; +export type VersionResponse = { + isUpstream: boolean; + update?: boolean; + updateToType?: keyof VersionResponse['versions']; + versions: { + stable: string; + upstream: string; + current: string; + }; +}; + export const useVersion = () => { - return useQuery<{ local: string; upstream: string }>( + return useQuery( ['version'], async () => { return fetch('/api/version').then((res) => res.json()); diff --git a/src/pages/api/version.ts b/src/pages/api/version.ts index d933e6a..93e9cae 100644 --- a/src/pages/api/version.ts +++ b/src/pages/api/version.ts @@ -7,12 +7,29 @@ async function handler(_: NextApiReq, res: NextApiRes) { const pkg = JSON.parse(await readFile('package.json', 'utf8')); - const re = await fetch('https://raw.githubusercontent.com/diced/zipline/trunk/package.json'); - const upstreamPkg = await re.json(); + // TODO: this needs to change to zipline.diced.tech once 3.7.0 is released + const re = await fetch('https://trunk.zipline.diced.tech/api/version?c=' + pkg.version); + const json = await re.json(); + + let updateToType = 'stable'; + + if (json.isUpstream) { + updateToType = 'upstream'; + + if (json.update?.stable) { + updateToType = 'stable'; + } + } return res.json({ - local: pkg.version, - upstream: upstreamPkg.version, + isUpstream: true, + update: json.update?.stable || json.update?.upstream, + updateToType, + versions: { + stable: json.git.stable, + upstream: json.git.upstream, + current: json.current, + }, }); }