From c186a04fa570a8fb8cc19ca653095f060b8cbadf Mon Sep 17 00:00:00 2001 From: Nastya Date: Wed, 4 Jun 2025 18:07:55 +0300 Subject: [PATCH] auditory --- lib/api/quizRelase.ts | 119 ++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 61 deletions(-) diff --git a/lib/api/quizRelase.ts b/lib/api/quizRelase.ts index 9c1caf8..59dc445 100644 --- a/lib/api/quizRelase.ts +++ b/lib/api/quizRelase.ts @@ -57,6 +57,9 @@ type PublicationMakeRequestParams = { method: "POST"; }; +const urlParams = new URLSearchParams(window.location.search); +const paudParam = urlParams.get("_paud"); + export const publicationMakeRequest = ({ url, body }: PublicationMakeRequestParams) => { return axios(url, { data: body, @@ -81,27 +84,27 @@ export async function getData({ quizId }: { quizId: string }): Promise<{ isRecentlyCompleted: boolean; error?: AxiosError; }> { + const body = { + quiz_id: quizId, + limit: 100, + page: 0, + need_config: true, + } as any; + if (paudParam) body.auditory = Number(paudParam); + try { - const { data, headers } = await axios( - domain + `/answer/v1.0.0/settings${window.location.search}`, - { - method: "POST", - headers: { - "X-Sessionkey": SESSIONS, - "Content-Type": "application/json", - DeviceType: DeviceType, - Device: Device, - OS: OSDevice, - Browser: userAgent, - }, - data: { - quiz_id: quizId, - limit: 100, - page: 0, - need_config: true, - }, - } - ); + const { data, headers } = await axios(domain + `/answer/v1.0.0/settings`, { + method: "POST", + headers: { + "X-Sessionkey": SESSIONS, + "Content-Type": "application/json", + DeviceType: DeviceType, + Device: Device, + OS: OSDevice, + Browser: userAgent, + }, + data: body, + }); const sessions = JSON.parse(localStorage.getItem("sessions") || "{}"); //Тут ещё проверка на антифрод без парса конфига. Нам не интересно время если не нужно запрещать проходить чаще чем в сутки @@ -130,26 +133,23 @@ export async function getDataSingle({ quizId, page }: { quizId: string; page?: n try { // Первый запрос: 1 вопрос + конфиг if (isFirstRequest) { - const { data, headers } = await axios( - domain + `/answer/v1.0.0/settings${window.location.search}`, - { - method: "POST", - headers: { - "X-Sessionkey": SESSIONS, - "Content-Type": "application/json", - DeviceType: DeviceType, - Device: Device, - OS: OSDevice, - Browser: userAgent, - }, - data: { - quiz_id: quizId, - limit: 1, - page: 0, - need_config: true, - }, - } - ); + const { data, headers } = await axios(domain + `/answer/v1.0.0/settings`, { + method: "POST", + headers: { + "X-Sessionkey": SESSIONS, + "Content-Type": "application/json", + DeviceType: DeviceType, + Device: Device, + OS: OSDevice, + Browser: userAgent, + }, + data: { + quiz_id: quizId, + limit: 1, + page: 0, + need_config: true, + }, + }); globalStatus = data.settings.status; isFirstRequest = false; @@ -165,26 +165,23 @@ export async function getDataSingle({ quizId, page }: { quizId: string; page?: n // Если статус не AI - сразу делаем запрос за всеми вопросами if (globalStatus !== "ai") { - const secondResponse = await axios( - domain + `/answer/v1.0.0/settings${window.location.search}`, - { - method: "POST", - headers: { - "X-Sessionkey": SESSIONS, - "Content-Type": "application/json", - DeviceType: DeviceType, - Device: Device, - OS: OSDevice, - Browser: userAgent, - }, - data: { - quiz_id: quizId, - limit: 100, - page: 0, - need_config: false, - }, - } - ); + const secondResponse = await axios(domain + `/answer/v1.0.0/settings`, { + method: "POST", + headers: { + "X-Sessionkey": SESSIONS, + "Content-Type": "application/json", + DeviceType: DeviceType, + Device: Device, + OS: OSDevice, + Browser: userAgent, + }, + data: { + quiz_id: quizId, + limit: 100, + page: 0, + need_config: false, + }, + }); return { data: { ...data, items: secondResponse.data.items }, isRecentlyCompleted: false, @@ -195,7 +192,7 @@ export async function getDataSingle({ quizId, page }: { quizId: string; page?: n } // Последующие запросы - const response = await axios(domain + `/answer/v1.0.0/settings${window.location.search}`, { + const response = await axios(domain + `/answer/v1.0.0/settings`, { method: "POST", headers: { "X-Sessionkey": SESSIONS,