From d9f8966ad8b35bf81ca4564fe0609f3987b77495 Mon Sep 17 00:00:00 2001 From: Vargoshi Date: Fri, 13 Oct 2023 21:18:19 +0200 Subject: [PATCH] fix: login bot url --- api/serveApi.ts | 15 ++++++++++++++- ui/AppHeader.tsx | 8 ++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/api/serveApi.ts b/api/serveApi.ts index 9781194..6d72732 100644 --- a/api/serveApi.ts +++ b/api/serveApi.ts @@ -1,10 +1,16 @@ -import { createLoggerMiddleware, createPathFilter } from "t_rest/server"; +import { + createEndpoint, + createLoggerMiddleware, + createMethodFilter, + createPathFilter, +} from "t_rest/server"; import { jobsRoute } from "./jobsRoute.ts"; import { paramsRoute } from "./paramsRoute.ts"; import { sessionsRoute } from "./sessionsRoute.ts"; import { statsRoute } from "./statsRoute.ts"; import { usersRoute } from "./usersRoute.ts"; import { workersRoute } from "./workersRoute.ts"; +import { bot } from "../bot/mod.ts"; export const serveApi = createLoggerMiddleware( createPathFilter({ @@ -14,6 +20,13 @@ export const serveApi = createLoggerMiddleware( "settings/params": paramsRoute, "stats": statsRoute, "workers": workersRoute, + "bot": createMethodFilter({ + // deno-lint-ignore require-await + GET: createEndpoint({ query: null, body: null }, async () => { + const username = bot.botInfo.username; + return { status: 200, body: { type: "application/json", data: { username } } }; + }), + }), }), { filterStatus: (status) => status >= 400 }, ); diff --git a/ui/AppHeader.tsx b/ui/AppHeader.tsx index 486de7b..fa22c51 100644 --- a/ui/AppHeader.tsx +++ b/ui/AppHeader.tsx @@ -33,6 +33,10 @@ export function AppHeader( (args) => fetchApi(...args).then(handleResponse), ); + const bot = useSWR( + ['bot',"GET",{}] as const, (args) => fetchApi(...args).then(handleResponse), + ); + const userPhoto = useSWR( session.data?.userId ? ["users/{userId}/photo", "GET", { @@ -89,7 +93,7 @@ export function AppHeader( : null} {/* login/logout button */} - {!session.isLoading && !user.isLoading && sessionId + {!session.isLoading && !user.isLoading && bot.data && sessionId ? ( user.data ? ( @@ -100,7 +104,7 @@ export function AppHeader( : ( Login