diff --git a/app/main.py b/app/main.py index f1153a3..dd77954 100644 --- a/app/main.py +++ b/app/main.py @@ -157,6 +157,7 @@ async def tg_intgr_get(request: Request): logger.info(e) return {"status": "error"} + def extract_id(params): json_strings = params.get("PLACEMENT_OPTIONS", []) for json_str in json_strings: @@ -166,7 +167,8 @@ def extract_id(params): return data["ID"] except json.JSONDecodeError: print(f"Ошибка: Некорректная JSON-строка - {json_str}") - + + def get_task_by_deal(deal_id): select = [ "ID", @@ -187,9 +189,10 @@ def get_task_by_deal(deal_id): task_data = requests.get(get_task_hook + f"&start={limit}") task_data_json = task_data.json() result += task_data_json["result"]["tasks"] - + return result - + + @app.post("/deal_tab") async def deal_tab( request: Request, @@ -204,10 +207,9 @@ async def deal_tab( result = parse_qs(b_str) q = [DOMAIN, PROTOCOL, LANG, APP_SID] - deal_id = extract_id(result) if not deal_id: - raise('not deal id') + raise ("not deal id") deal_id = 49 result = get_task_by_deal(deal_id) @@ -226,6 +228,7 @@ async def deal_tab( logger.error(e) return {"status": "error"} + @app.post("/widget/deal_tab/{deal_id}") async def deal_tab(request: Request, deal_id): try: @@ -235,7 +238,11 @@ async def deal_tab(request: Request, deal_id): parts = WEBHOOK.split("/") domain = f"https://{parts[2]}" - return {"status": "success", "result": result, "format": {"domain": domain, "statuses": statuses}} + return { + "status": "success", + "result": result, + "format": {"domain": domain, "statuses": statuses}, + } except Exception as e: logger.error(e) return {"status": "error"} @@ -262,8 +269,9 @@ async def handle_widget_post(request: Request): deal_id = 49 logger.info(result) - html_file = NUXT_DIST / f"/deal/index.html?deal_id={deal_id}" + html_file = NUXT_DIST / f"/deal/index.html" if html_file.exists(): html_content = html_file.read_text() + html_content = html_content.replace("data_deal_id:0", f"data_deal_id:{deal_id}") return HTMLResponse(content=html_content, status_code=200) return {"error": "Nuxt.js page not found"}, 404 diff --git a/front/nuxt.config.ts b/front/nuxt.config.ts index c6cf7d5..657bf2b 100644 --- a/front/nuxt.config.ts +++ b/front/nuxt.config.ts @@ -10,7 +10,8 @@ export default defineNuxtConfig({ runtimeConfig: { public: { - apiBase: process.env.NODE_ENV == 'development' ? 'http://localhost:8000' : '' + apiBase: process.env.NODE_ENV == 'development' ? 'http://localhost:8000' : '', + data_deal_id: 0 } }, diff --git a/front/pages/deal.vue b/front/pages/deal.vue index e535223..b60a777 100644 --- a/front/pages/deal.vue +++ b/front/pages/deal.vue @@ -67,10 +67,10 @@ const columns = [{ onMounted(() => { - const deal_id = route.query.deal_id + const deal_id = config.public.data_deal_id if (!deal_id) return - loadData(parseInt(deal_id as string)) + loadData(deal_id) })