feat: fronted change
This commit is contained in:
parent
200d7749b7
commit
864781a511
@ -13,13 +13,16 @@ for v in backend_status["clients"]:
|
||||
|
||||
if need_login:
|
||||
import login
|
||||
|
||||
login.loop()
|
||||
st.stop()
|
||||
|
||||
search_tab, link_convert_tab = st.tabs(["Search", "Link Convert"])
|
||||
with search_tab:
|
||||
import search
|
||||
|
||||
search.loop()
|
||||
with link_convert_tab:
|
||||
st.header("施工中<( ̄︶ ̄)↗[GO!]")
|
||||
st.markdown("# 404 Not Found")
|
||||
import link_convert
|
||||
|
||||
link_convert.loop()
|
||||
|
12
frontend/link_convert.py
Normal file
12
frontend/link_convert.py
Normal file
@ -0,0 +1,12 @@
|
||||
import streamlit as st
|
||||
|
||||
import remote_api as api
|
||||
|
||||
|
||||
def loop():
|
||||
input_link = st.text_input("Telegram share link:", placeholder="https://t.me/c/xxx/xxx/ or https://t.me/xxx/xxx")
|
||||
button_clicked = st.button("Convert", type="primary", use_container_width=True)
|
||||
res = ""
|
||||
if button_clicked and input_link != "":
|
||||
res = api.convert_tg_link_to_proxy_link(input_link)
|
||||
st.text_area("Convert res text area", value=res, label_visibility="hidden")
|
@ -2,6 +2,7 @@ import sys
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
from urllib.parse import quote
|
||||
|
||||
import requests
|
||||
|
||||
@ -13,8 +14,8 @@ logger = logging.getLogger(__file__.split("/")[-1])
|
||||
param = configParse.get_TgToFileSystemParameter()
|
||||
|
||||
background_server_url = f"{param.base.exposed_url}"
|
||||
search_api_route = "/tg/api/v1/file/search"
|
||||
status_api_route = "/tg/api/v1/client/status"
|
||||
|
||||
|
||||
login_api_route = "/tg/api/v1/client/login"
|
||||
|
||||
|
||||
@ -28,6 +29,9 @@ def login_client_by_qr_code_url() -> str:
|
||||
return url_info.get("url")
|
||||
|
||||
|
||||
status_api_route = "/tg/api/v1/client/status"
|
||||
|
||||
|
||||
def get_backend_client_status() -> dict[str, any]:
|
||||
request_url = background_server_url + status_api_route
|
||||
response = requests.get(request_url)
|
||||
@ -37,6 +41,9 @@ def get_backend_client_status() -> dict[str, any]:
|
||||
return json.loads(response.content.decode("utf-8"))
|
||||
|
||||
|
||||
search_api_route = "/tg/api/v1/file/search"
|
||||
|
||||
|
||||
def search_database_by_keyword(keyword: str, offset: int, limit: int, is_order: bool) -> list[any] | None:
|
||||
request_url = background_server_url + search_api_route
|
||||
req_body = {
|
||||
@ -56,3 +63,17 @@ def search_database_by_keyword(keyword: str, offset: int, limit: int, is_order:
|
||||
return None
|
||||
search_res = json.loads(response.content.decode("utf-8"))
|
||||
return search_res
|
||||
|
||||
|
||||
link_convert_api_route = "/tg/api/v1/client/link_convert"
|
||||
|
||||
|
||||
def convert_tg_link_to_proxy_link(link: str) -> str:
|
||||
link = quote(link, safe="")
|
||||
request_url = background_server_url + link_convert_api_route + f"?link={link}"
|
||||
response = requests.get(request_url)
|
||||
if response.status_code != 200:
|
||||
logger.warning(f"link convert fail: {response.status_code}, {response.content.decode('utf-8')}")
|
||||
return ""
|
||||
response_js = json.loads(response.content.decode("utf-8"))
|
||||
return response_js["url"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user