From 5e3e6b3edda495d80bb1e86ed3ccae949c07a469 Mon Sep 17 00:00:00 2001 From: Yash Date: Thu, 25 Dec 2025 09:48:09 +0530 Subject: [PATCH] refactor: Simplify version display by removing API endpoint and using constant --- .../settings/preferences/VersionSetting.tsx | 27 ++------------ src/app/api/version/route.ts | 35 ------------------- 2 files changed, 2 insertions(+), 60 deletions(-) delete mode 100644 src/app/api/version/route.ts diff --git a/src/app/(main)/settings/preferences/VersionSetting.tsx b/src/app/(main)/settings/preferences/VersionSetting.tsx index 2cfdbeb7..afca1de6 100644 --- a/src/app/(main)/settings/preferences/VersionSetting.tsx +++ b/src/app/(main)/settings/preferences/VersionSetting.tsx @@ -1,31 +1,8 @@ 'use client'; import { Text } from '@umami/react-zen'; -import { useEffect, useState } from 'react'; +import { CURRENT_VERSION } from '@/lib/constants'; export function VersionSetting() { - const [version, setVersion] = useState(''); - const [loading, setLoading] = useState(true); - - useEffect(() => { - const fetchVersion = async () => { - try { - const response = await fetch('/api/version'); - const data = await response.json(); - setVersion(data.version || 'unknown'); - } catch (error) { - setVersion('unknown'); - } finally { - setLoading(false); - } - }; - - fetchVersion(); - }, []); - - if (loading) { - return Loading...; - } - - return {version}; + return {CURRENT_VERSION}; } diff --git a/src/app/api/version/route.ts b/src/app/api/version/route.ts deleted file mode 100644 index af548f73..00000000 --- a/src/app/api/version/route.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { readFile } from 'fs/promises'; -import { join } from 'path'; -import { parseRequest } from '@/lib/request'; -import { json } from '@/lib/response'; - -let cachedVersion: string | null = null; - -async function getVersion(): Promise { - if (cachedVersion) { - return cachedVersion; - } - - try { - const packageJsonPath = join(process.cwd(), 'package.json'); - const data = await readFile(packageJsonPath, 'utf-8'); - const packageJson = JSON.parse(data); - cachedVersion = packageJson.version || 'unknown'; - } catch (error) { - cachedVersion = 'unknown'; - } - - return cachedVersion; -} - -export async function GET(request: Request) { - const { error } = await parseRequest(request, null, { skipAuth: true }); - - if (error) { - return error(); - } - - const version = await getVersion(); - - return json({ version }); -}