misskey2telegram_web/main.py

33 lines
652 B
Python
Raw Normal View History

2023-01-27 12:02:46 +00:00
import uuid
from fastapi import FastAPI
from starlette.responses import RedirectResponse
from utils import gen_url, get_auth
app = FastAPI()
@app.get('/gen')
async def gen(
*,
username: str,
host: str,
back_host: str,
):
session = str(uuid.uuid4())
return RedirectResponse(gen_url(username, host, back_host, session))
@app.get("/{username}/{host}")
async def back_to_telegram(
*,
username: str,
host: str,
session: str,
):
data = await get_auth(host, session)
if data.get("ok", False):
return RedirectResponse(f"https://t.me/{username}?start={data['token']}")
else:
return data