вернула запрос 100 вопросов
This commit is contained in:
parent
3a8865713a
commit
d675530480
@ -76,7 +76,53 @@ export const publicationMakeRequest = ({ url, body }: PublicationMakeRequestPara
|
||||
let globalStatus: string | null = null;
|
||||
let isFirstRequest = true;
|
||||
|
||||
export async function getData({ quizId, page }: { quizId: string; page?: number }): Promise<{
|
||||
export async function getData({ quizId }: { quizId: string }): Promise<{
|
||||
data: GetQuizDataResponse | null;
|
||||
isRecentlyCompleted: boolean;
|
||||
error?: AxiosError;
|
||||
}> {
|
||||
try {
|
||||
const { data, headers } = await axios<GetQuizDataResponse>(
|
||||
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 sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
||||
|
||||
//Тут ещё проверка на антифрод без парса конфига. Нам не интересно время если не нужно запрещать проходить чаще чем в сутки
|
||||
if (typeof sessions[quizId] === "number" && data.settings.cfg.includes('antifraud":true')) {
|
||||
// unix время. Если меньше суток прошло - выводить ошибку, иначе пустить дальше
|
||||
if (Date.now() - sessions[quizId] < 86400000) {
|
||||
return { data, isRecentlyCompleted: true };
|
||||
}
|
||||
}
|
||||
|
||||
SESSIONS = headers["x-sessionkey"] ? headers["x-sessionkey"] : SESSIONS;
|
||||
|
||||
return { data, isRecentlyCompleted: false };
|
||||
} catch (nativeError) {
|
||||
const error = nativeError as AxiosError;
|
||||
|
||||
return { data: null, isRecentlyCompleted: false, error: error };
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDataSingle({ quizId, page }: { quizId: string; page?: number }): Promise<{
|
||||
data: GetQuizDataResponse | null;
|
||||
isRecentlyCompleted: boolean;
|
||||
error?: AxiosError;
|
||||
@ -231,7 +277,7 @@ export async function getQuizDataAI(quizId: string) {
|
||||
while (resultRetryCount < maxRetries) {
|
||||
try {
|
||||
console.log(`[getQuizDataAI] Attempt ${resultRetryCount + 1} for result questions, page: ${page}`);
|
||||
const response = await getData({ quizId, page });
|
||||
const response = await getData({ quizId });
|
||||
console.log("[getQuizDataAI] Response from getData:", response);
|
||||
|
||||
if (response.error) {
|
||||
@ -286,7 +332,7 @@ export async function getQuizDataAI(quizId: string) {
|
||||
try {
|
||||
console.log(`[getQuizDataAI] Empty items retry ${emptyRetryCount + 1}`);
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
const response = await getData({ quizId, page });
|
||||
const response = await getData({ quizId });
|
||||
|
||||
if (response.error) {
|
||||
console.error("[getQuizDataAI] Error in empty items check:", response.error);
|
||||
|
Loading…
Reference in New Issue
Block a user