forked from pinks/eris
1
0
Fork 0

fix: login bot url

This commit is contained in:
Vargoshi 2023-10-13 21:18:19 +02:00
parent 5bb2a13f35
commit d9f8966ad8
2 changed files with 20 additions and 3 deletions

View File

@ -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 { jobsRoute } from "./jobsRoute.ts";
import { paramsRoute } from "./paramsRoute.ts"; import { paramsRoute } from "./paramsRoute.ts";
import { sessionsRoute } from "./sessionsRoute.ts"; import { sessionsRoute } from "./sessionsRoute.ts";
import { statsRoute } from "./statsRoute.ts"; import { statsRoute } from "./statsRoute.ts";
import { usersRoute } from "./usersRoute.ts"; import { usersRoute } from "./usersRoute.ts";
import { workersRoute } from "./workersRoute.ts"; import { workersRoute } from "./workersRoute.ts";
import { bot } from "../bot/mod.ts";
export const serveApi = createLoggerMiddleware( export const serveApi = createLoggerMiddleware(
createPathFilter({ createPathFilter({
@ -14,6 +20,13 @@ export const serveApi = createLoggerMiddleware(
"settings/params": paramsRoute, "settings/params": paramsRoute,
"stats": statsRoute, "stats": statsRoute,
"workers": workersRoute, "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 }, { filterStatus: (status) => status >= 400 },
); );

View File

@ -33,6 +33,10 @@ export function AppHeader(
(args) => fetchApi(...args).then(handleResponse), (args) => fetchApi(...args).then(handleResponse),
); );
const bot = useSWR(
['bot',"GET",{}] as const, (args) => fetchApi(...args).then(handleResponse),
);
const userPhoto = useSWR( const userPhoto = useSWR(
session.data?.userId session.data?.userId
? ["users/{userId}/photo", "GET", { ? ["users/{userId}/photo", "GET", {
@ -89,7 +93,7 @@ export function AppHeader(
: null} : null}
{/* login/logout button */} {/* login/logout button */}
{!session.isLoading && !user.isLoading && sessionId {!session.isLoading && !user.isLoading && bot.data && sessionId
? ( ? (
user.data user.data
? ( ? (
@ -100,7 +104,7 @@ export function AppHeader(
: ( : (
<a <a
className="button-filled" className="button-filled"
href={`https://t.me/ErisTheBot?start=${sessionId}`} href={`https://t.me/${bot.data.username}?start=${sessionId}`}
target="_blank" target="_blank"
> >
Login Login