diff options
| author | MohamedBassem <me@mbassem.com> | 2024-04-02 16:42:53 +0100 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-04-02 16:42:53 +0100 |
| commit | c206aa254c39175812c0e1d0e012a6a841ea5d50 (patch) | |
| tree | 26fd1b2b33528b33b735fdcd0d2a3e93ed39c887 /apps | |
| parent | d02fa5056a07dee699cd4b3868c2ffb673c133c2 (diff) | |
| download | karakeep-c206aa254c39175812c0e1d0e012a6a841ea5d50.tar.zst | |
feature: Include server version in the admin UI. Fixes #66
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/cli/index.ts | 2 | ||||
| -rw-r--r-- | apps/web/app/dashboard/admin/page.tsx | 55 | ||||
| -rw-r--r-- | apps/web/lib/clientConfig.tsx | 2 | ||||
| -rw-r--r-- | apps/workers/index.ts | 4 |
4 files changed, 61 insertions, 2 deletions
diff --git a/apps/cli/index.ts b/apps/cli/index.ts index 03699e55..4d0adafb 100644 --- a/apps/cli/index.ts +++ b/apps/cli/index.ts @@ -19,7 +19,7 @@ const program = new Command() .makeOptionMandatory(true) .env("HOARDER_SERVER_ADDR"), ) - .version("0.1.0"); + .version(process.env.SERVER_VERSION ?? "nightly"); program.addCommand(bookmarkCmd); program.addCommand(whoamiCmd); diff --git a/apps/web/app/dashboard/admin/page.tsx b/apps/web/app/dashboard/admin/page.tsx index eb80cb03..0db1130f 100644 --- a/apps/web/app/dashboard/admin/page.tsx +++ b/apps/web/app/dashboard/admin/page.tsx @@ -13,11 +13,58 @@ import { TableRow, } from "@/components/ui/table"; import { toast } from "@/components/ui/use-toast"; +import { useClientConfig } from "@/lib/clientConfig"; import { api } from "@/lib/trpc"; -import { keepPreviousData } from "@tanstack/react-query"; +import { keepPreviousData, useQuery } from "@tanstack/react-query"; import { Trash } from "lucide-react"; import { useSession } from "next-auth/react"; +const REPO_LATEST_RELEASE_API = + "https://api.github.com/repos/mohamedbassem/hoarder-app/releases/latest"; +const REPO_RELEASE_PAGE = + "https://github.com/MohamedBassem/hoarder-app/releases"; + +function useLatestRelease() { + const { data } = useQuery({ + queryKey: ["latest-release"], + queryFn: async () => { + const res = await fetch(REPO_LATEST_RELEASE_API); + if (!res.ok) { + return undefined; + } + const data = (await res.json()) as { name: string }; + return data.name; + }, + staleTime: 60 * 60 * 1000, + enabled: !useClientConfig().disableNewReleaseCheck, + }); + return data; +} + +function ReleaseInfo() { + const currentRelease = useClientConfig().serverVersion ?? "not set"; + const latestRelease = useLatestRelease(); + + let newRelease; + if (latestRelease && currentRelease != latestRelease) { + newRelease = ( + <a + href={REPO_RELEASE_PAGE} + target="_blank" + className="text-blue-500" + rel="noreferrer" + > + (New release available: {latestRelease}) + </a> + ); + } + return ( + <p className="text-nowrap"> + {currentRelease} {newRelease} + </p> + ); +} + function ActionsSection() { const { mutate: recrawlLinks, isPending: isRecrawlPending } = api.admin.recrawlAllLinks.useMutation({ @@ -95,6 +142,12 @@ function ServerStatsSection() { <TableCell>Num Bookmarks</TableCell> <TableCell>{serverStats.numBookmarks}</TableCell> </TableRow> + <TableRow> + <TableCell className="w-2/3">Server Version</TableCell> + <TableCell> + <ReleaseInfo /> + </TableCell> + </TableRow> </TableBody> </Table> <Separator /> diff --git a/apps/web/lib/clientConfig.tsx b/apps/web/lib/clientConfig.tsx index d63b169c..50e9774d 100644 --- a/apps/web/lib/clientConfig.tsx +++ b/apps/web/lib/clientConfig.tsx @@ -7,6 +7,8 @@ export const ClientConfigCtx = createContext<ClientConfig>({ auth: { disableSignups: false, }, + serverVersion: undefined, + disableNewReleaseCheck: true, }); export function useClientConfig() { diff --git a/apps/workers/index.ts b/apps/workers/index.ts index 24bdc67b..687d9ced 100644 --- a/apps/workers/index.ts +++ b/apps/workers/index.ts @@ -1,11 +1,15 @@ import "dotenv/config"; +import serverConfig from "@hoarder/shared/config"; +import logger from "@hoarder/shared/logger"; + import { CrawlerWorker } from "./crawlerWorker"; import { shutdownPromise } from "./exit"; import { OpenAiWorker } from "./openaiWorker"; import { SearchIndexingWorker } from "./searchWorker"; async function main() { + logger.info(`Workers version: ${serverConfig.serverVersion ?? "not set"}`); const [crawler, openai, search] = [ await CrawlerWorker.build(), OpenAiWorker.build(), |
