fix: login bot url
This commit is contained in:
parent
5bb2a13f35
commit
d9f8966ad8
|
@ -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 },
|
||||
);
|
||||
|
|
|
@ -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(
|
|||
: (
|
||||
<a
|
||||
className="button-filled"
|
||||
href={`https://t.me/ErisTheBot?start=${sessionId}`}
|
||||
href={`https://t.me/${bot.data.username}?start=${sessionId}`}
|
||||
target="_blank"
|
||||
>
|
||||
Login
|
||||
|
|
Loading…
Reference in New Issue