2024-02-14 11:03:35 +00:00
|
|
|
|
import { GetQuizDataResponse, parseQuizData } from "@model/api/getQuizData";
|
2024-01-29 11:16:21 +00:00
|
|
|
|
import axios from "axios";
|
2024-05-31 16:41:18 +00:00
|
|
|
|
import MobileDetect from "mobile-detect";
|
2024-03-16 23:40:13 +00:00
|
|
|
|
import device from "current-device";
|
2024-01-29 11:16:21 +00:00
|
|
|
|
|
|
|
|
|
import type { AxiosError } from "axios";
|
2024-02-14 11:03:35 +00:00
|
|
|
|
import { replaceSpacesToEmptyLines } from "../components/ViewPublicationPage/tools/replaceSpacesToEmptyLines";
|
|
|
|
|
import { QuizSettings } from "@model/settingsData";
|
2024-04-01 00:45:31 +00:00
|
|
|
|
import * as Bowser from "bowser";
|
2024-04-18 14:13:52 +00:00
|
|
|
|
import { domain } from "../utils/defineDomain";
|
2024-01-29 11:16:21 +00:00
|
|
|
|
let SESSIONS = "";
|
|
|
|
|
|
2024-03-16 23:40:13 +00:00
|
|
|
|
const md = new MobileDetect(window.navigator.userAgent);
|
2024-04-02 13:09:13 +00:00
|
|
|
|
const userAgent = navigator.userAgent;
|
2024-04-01 00:45:31 +00:00
|
|
|
|
//операционная система
|
2024-04-02 13:09:13 +00:00
|
|
|
|
let OSDevice: string | undefined;
|
2024-05-31 16:41:18 +00:00
|
|
|
|
if (userAgent.toLowerCase().includes("linux")) {
|
|
|
|
|
OSDevice = "Linux";
|
|
|
|
|
}
|
|
|
|
|
if (userAgent.toLowerCase().includes("windows")) {
|
|
|
|
|
OSDevice = "Windows";
|
|
|
|
|
}
|
|
|
|
|
if (/iPad|iPhone|iPod/.test(userAgent)) {
|
|
|
|
|
OSDevice = "IOS";
|
|
|
|
|
}
|
|
|
|
|
if (userAgent.toLowerCase().includes("macintosh")) {
|
|
|
|
|
OSDevice = "Mac OS";
|
|
|
|
|
}
|
|
|
|
|
if (OSDevice === undefined) {
|
|
|
|
|
OSDevice = userAgent;
|
|
|
|
|
}
|
2024-04-01 00:45:31 +00:00
|
|
|
|
|
|
|
|
|
//браузер
|
2024-04-02 13:09:13 +00:00
|
|
|
|
let browserUser: string;
|
|
|
|
|
if (Bowser.name === "Chrome") {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
browserUser = "Chrome";
|
2024-04-02 13:09:13 +00:00
|
|
|
|
} else if (Bowser.name === "Firefox") {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
browserUser = "Firefox";
|
2024-04-02 13:09:13 +00:00
|
|
|
|
} else if (Bowser.name === "Safari") {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
browserUser = "Safari";
|
2024-04-11 12:49:55 +00:00
|
|
|
|
} else if (Bowser.name === "Yandex Browser") {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
browserUser = "Yandex Browser";
|
|
|
|
|
} else {
|
|
|
|
|
browserUser = userAgent;
|
|
|
|
|
}
|
2024-03-16 23:40:13 +00:00
|
|
|
|
|
2024-04-02 13:09:13 +00:00
|
|
|
|
const DeviceType = device.type;
|
2024-04-01 00:45:31 +00:00
|
|
|
|
|
2024-04-02 13:09:13 +00:00
|
|
|
|
let Device = md.mobile();
|
2024-05-31 16:41:18 +00:00
|
|
|
|
if (Device === null) {
|
|
|
|
|
Device = userAgent;
|
|
|
|
|
}
|
2024-03-16 23:40:13 +00:00
|
|
|
|
|
2024-04-17 16:08:40 +00:00
|
|
|
|
type PublicationMakeRequestParams = {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
url: string;
|
|
|
|
|
body: FormData;
|
|
|
|
|
method: "POST";
|
2024-05-01 08:12:06 +00:00
|
|
|
|
};
|
2024-04-17 16:08:40 +00:00
|
|
|
|
|
|
|
|
|
export const publicationMakeRequest = ({ url, body }: PublicationMakeRequestParams) => {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
return axios(url, {
|
|
|
|
|
data: body,
|
|
|
|
|
headers: {
|
|
|
|
|
"X-Sessionkey": SESSIONS,
|
|
|
|
|
"Content-Type": "multipart/form-data",
|
|
|
|
|
DeviceType: DeviceType,
|
|
|
|
|
Device: Device,
|
|
|
|
|
OS: OSDevice,
|
|
|
|
|
Browser: browserUser,
|
|
|
|
|
},
|
|
|
|
|
method: "POST",
|
|
|
|
|
});
|
2024-01-29 11:16:21 +00:00
|
|
|
|
};
|
|
|
|
|
|
2025-05-01 13:23:10 +00:00
|
|
|
|
// Глобальные переменные для хранения состояния между вызовами
|
|
|
|
|
let globalStatus: string | null = null;
|
|
|
|
|
let isFirstRequest = true;
|
|
|
|
|
|
2025-06-01 11:14:27 +00:00
|
|
|
|
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<{
|
2024-05-31 16:41:18 +00:00
|
|
|
|
data: GetQuizDataResponse | null;
|
|
|
|
|
isRecentlyCompleted: boolean;
|
|
|
|
|
error?: AxiosError;
|
2024-01-29 11:16:21 +00:00
|
|
|
|
}> {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
try {
|
2025-05-01 13:23:10 +00:00
|
|
|
|
// Первый запрос: 1 вопрос + конфиг
|
|
|
|
|
if (isFirstRequest) {
|
|
|
|
|
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: 1,
|
|
|
|
|
page: 0,
|
|
|
|
|
need_config: true,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
globalStatus = data.settings.status;
|
|
|
|
|
isFirstRequest = false;
|
|
|
|
|
SESSIONS = headers["x-sessionkey"] || SESSIONS;
|
|
|
|
|
|
|
|
|
|
// Проверка антифрода
|
|
|
|
|
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
|
|
|
|
if (typeof sessions[quizId] === "number" && data.settings.cfg.includes('antifraud":true')) {
|
|
|
|
|
if (Date.now() - sessions[quizId] < 86400000) {
|
|
|
|
|
return { data, isRecentlyCompleted: true };
|
|
|
|
|
}
|
2024-06-29 09:32:16 +00:00
|
|
|
|
}
|
2024-05-01 08:12:06 +00:00
|
|
|
|
|
2025-05-01 13:23:10 +00:00
|
|
|
|
// Если статус не AI - сразу делаем запрос за всеми вопросами
|
|
|
|
|
if (globalStatus !== "ai") {
|
|
|
|
|
const secondResponse = 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: false,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
return {
|
|
|
|
|
data: { ...data, items: secondResponse.data.items },
|
|
|
|
|
isRecentlyCompleted: false,
|
|
|
|
|
};
|
2024-05-31 16:41:18 +00:00
|
|
|
|
}
|
2024-05-01 08:12:06 +00:00
|
|
|
|
|
2025-05-01 13:23:10 +00:00
|
|
|
|
return { data, isRecentlyCompleted: false };
|
|
|
|
|
}
|
2024-02-14 11:03:35 +00:00
|
|
|
|
|
2025-05-01 13:23:10 +00:00
|
|
|
|
// Последующие запросы
|
|
|
|
|
const response = 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: 1,
|
|
|
|
|
page: page,
|
|
|
|
|
need_config: false,
|
|
|
|
|
},
|
|
|
|
|
});
|
2024-02-14 11:03:35 +00:00
|
|
|
|
|
2025-05-01 13:23:10 +00:00
|
|
|
|
return {
|
|
|
|
|
data: response.data,
|
|
|
|
|
isRecentlyCompleted: false,
|
|
|
|
|
};
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return {
|
|
|
|
|
data: null,
|
|
|
|
|
isRecentlyCompleted: false,
|
|
|
|
|
error: error as AxiosError,
|
|
|
|
|
};
|
2024-05-31 16:41:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-01 13:23:10 +00:00
|
|
|
|
export async function getQuizData({ quizId, status = "" }: { quizId: string; status?: string }) {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
if (!quizId) throw new Error("No quiz id");
|
|
|
|
|
|
2025-05-01 13:15:54 +00:00
|
|
|
|
const response = await getData({ quizId });
|
2024-05-31 16:41:18 +00:00
|
|
|
|
const quizDataResponse = response.data;
|
|
|
|
|
|
|
|
|
|
if (response.error) {
|
2025-05-20 10:56:34 +00:00
|
|
|
|
const axiosError = response.error as AxiosError;
|
|
|
|
|
if (axiosError.response?.data) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
typeof axiosError.response.data === "string"
|
|
|
|
|
? axiosError.response.data
|
|
|
|
|
: JSON.stringify(axiosError.response.data)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
throw axiosError;
|
2024-05-31 16:41:18 +00:00
|
|
|
|
}
|
|
|
|
|
if (!quizDataResponse) {
|
|
|
|
|
throw new Error("Quiz not found");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const quizSettings = replaceSpacesToEmptyLines(parseQuizData(quizDataResponse));
|
|
|
|
|
|
|
|
|
|
const res = JSON.parse(
|
|
|
|
|
JSON.stringify({ data: quizSettings })
|
|
|
|
|
.replaceAll(/\\" \\"/g, '""')
|
|
|
|
|
.replaceAll(/" "/g, '""')
|
|
|
|
|
).data as QuizSettings;
|
|
|
|
|
res.recentlyCompleted = response.isRecentlyCompleted;
|
|
|
|
|
return res;
|
2024-02-14 11:03:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-05-01 13:15:54 +00:00
|
|
|
|
let page = 1;
|
2025-05-01 13:23:10 +00:00
|
|
|
|
|
2025-05-01 13:15:54 +00:00
|
|
|
|
export async function getQuizDataAI(quizId: string) {
|
2025-05-01 13:23:10 +00:00
|
|
|
|
console.log("[getQuizDataAI] Starting with quizId:", quizId); // Добавлено
|
2025-04-22 19:29:34 +00:00
|
|
|
|
let maxRetries = 50;
|
2025-05-01 13:23:10 +00:00
|
|
|
|
|
|
|
|
|
if (!quizId) {
|
|
|
|
|
console.error("[getQuizDataAI] Error: No quiz id provided");
|
|
|
|
|
throw new Error("No quiz id");
|
|
|
|
|
}
|
2024-05-31 16:41:18 +00:00
|
|
|
|
|
2025-04-22 19:29:34 +00:00
|
|
|
|
let lastError: Error | null = null;
|
|
|
|
|
let responseData: any = null;
|
|
|
|
|
|
2025-05-01 13:23:10 +00:00
|
|
|
|
// Первый цикл - обработка result вопросов
|
|
|
|
|
console.log("[getQuizDataAI] Starting result retries loop"); // Добавлено
|
2025-04-22 19:29:34 +00:00
|
|
|
|
let resultRetryCount = 0;
|
|
|
|
|
while (resultRetryCount < maxRetries) {
|
|
|
|
|
try {
|
2025-05-01 13:23:10 +00:00
|
|
|
|
console.log(`[getQuizDataAI] Attempt ${resultRetryCount + 1} for result questions, page: ${page}`);
|
2025-06-01 11:14:27 +00:00
|
|
|
|
const response = await getData({ quizId });
|
2025-05-01 13:23:10 +00:00
|
|
|
|
console.log("[getQuizDataAI] Response from getData:", response);
|
2025-04-22 19:29:34 +00:00
|
|
|
|
|
2025-05-01 13:23:10 +00:00
|
|
|
|
if (response.error) {
|
|
|
|
|
console.error("[getQuizDataAI] Error in response:", response.error);
|
|
|
|
|
throw response.error;
|
|
|
|
|
}
|
|
|
|
|
if (!response.data) {
|
|
|
|
|
console.error("[getQuizDataAI] Error: Quiz not found");
|
|
|
|
|
throw new Error("Quiz not found");
|
|
|
|
|
}
|
2025-04-22 19:29:34 +00:00
|
|
|
|
|
2025-05-01 13:15:54 +00:00
|
|
|
|
const hasAiResult = response.data.items.some((item) => item.typ === "result");
|
2025-05-01 13:23:10 +00:00
|
|
|
|
console.log("[getQuizDataAI] Has AI result:", hasAiResult);
|
2025-04-22 19:29:34 +00:00
|
|
|
|
|
|
|
|
|
if (hasAiResult) {
|
2025-05-01 13:23:10 +00:00
|
|
|
|
page++;
|
2025-04-22 19:29:34 +00:00
|
|
|
|
resultRetryCount++;
|
2025-05-01 13:23:10 +00:00
|
|
|
|
console.log(`[getQuizDataAI] Found result question, incrementing page to ${page}`);
|
2025-04-22 19:29:34 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
responseData = response;
|
2025-05-01 13:23:10 +00:00
|
|
|
|
console.log("[getQuizDataAI] Found non-result questions, breaking loop");
|
2025-04-22 19:29:34 +00:00
|
|
|
|
break;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
lastError = error as Error;
|
|
|
|
|
resultRetryCount++;
|
2025-05-01 13:23:10 +00:00
|
|
|
|
console.error(`[getQuizDataAI] Error in attempt ${resultRetryCount}:`, error);
|
|
|
|
|
|
|
|
|
|
if (resultRetryCount >= maxRetries) {
|
|
|
|
|
console.error("[getQuizDataAI] Max retries reached for result questions");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const delay = 1500 * resultRetryCount;
|
|
|
|
|
console.log(`[getQuizDataAI] Waiting ${delay}ms before next retry`);
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
2025-04-22 19:29:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!responseData) {
|
2025-05-01 13:23:10 +00:00
|
|
|
|
console.error("[getQuizDataAI] Failed after result retries, throwing error");
|
2025-04-22 19:29:34 +00:00
|
|
|
|
throw lastError || new Error("Failed to get quiz data after result retries");
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-01 13:23:10 +00:00
|
|
|
|
// Второй цикл - обработка пустого массива
|
|
|
|
|
console.log("[getQuizDataAI] Starting empty items retry loop"); // Добавлено
|
2025-04-22 19:29:34 +00:00
|
|
|
|
let isEmpty = !responseData.data?.items.length;
|
|
|
|
|
let emptyRetryCount = 0;
|
2025-05-01 13:23:10 +00:00
|
|
|
|
|
2025-04-22 19:29:34 +00:00
|
|
|
|
while (isEmpty && emptyRetryCount < maxRetries) {
|
|
|
|
|
try {
|
2025-05-01 13:23:10 +00:00
|
|
|
|
console.log(`[getQuizDataAI] Empty items retry ${emptyRetryCount + 1}`);
|
2025-04-22 19:29:34 +00:00
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
2025-06-01 11:14:27 +00:00
|
|
|
|
const response = await getData({ quizId });
|
2024-05-31 16:41:18 +00:00
|
|
|
|
|
2025-05-01 13:23:10 +00:00
|
|
|
|
if (response.error) {
|
|
|
|
|
console.error("[getQuizDataAI] Error in empty items check:", response.error);
|
|
|
|
|
throw response.error;
|
|
|
|
|
}
|
|
|
|
|
if (!response.data) {
|
|
|
|
|
console.error("[getQuizDataAI] Error: Quiz not found in empty check");
|
|
|
|
|
throw new Error("Quiz not found");
|
|
|
|
|
}
|
2025-04-22 19:29:34 +00:00
|
|
|
|
|
|
|
|
|
isEmpty = !response.data.items.length;
|
2025-05-01 13:23:10 +00:00
|
|
|
|
console.log("[getQuizDataAI] Is items empty:", isEmpty);
|
|
|
|
|
|
2025-04-22 19:29:34 +00:00
|
|
|
|
if (!isEmpty) {
|
2025-05-01 13:23:10 +00:00
|
|
|
|
responseData = response;
|
|
|
|
|
console.log("[getQuizDataAI] Found non-empty items, updating responseData");
|
2025-04-22 19:29:34 +00:00
|
|
|
|
}
|
|
|
|
|
emptyRetryCount++;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
lastError = error as Error;
|
|
|
|
|
emptyRetryCount++;
|
2025-05-01 13:23:10 +00:00
|
|
|
|
console.error(`[getQuizDataAI] Error in empty check attempt ${emptyRetryCount}:`, error);
|
|
|
|
|
|
|
|
|
|
if (emptyRetryCount >= maxRetries) {
|
|
|
|
|
console.error("[getQuizDataAI] Max empty retries reached");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-04-22 19:29:34 +00:00
|
|
|
|
}
|
2024-05-31 16:41:18 +00:00
|
|
|
|
}
|
2025-04-22 19:29:34 +00:00
|
|
|
|
|
|
|
|
|
if (isEmpty) {
|
2025-05-01 13:23:10 +00:00
|
|
|
|
console.error("[getQuizDataAI] Items still empty after retries");
|
2025-04-22 19:29:34 +00:00
|
|
|
|
throw new Error("Items array is empty after maximum retries");
|
2024-05-31 16:41:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-05-01 13:23:10 +00:00
|
|
|
|
// Финальная обработка
|
|
|
|
|
console.log("[getQuizDataAI] Processing final response data");
|
2025-05-01 13:15:54 +00:00
|
|
|
|
|
2025-05-01 13:23:10 +00:00
|
|
|
|
console.log("[getQuizDataAI] Final response before return:", responseData);
|
|
|
|
|
return responseData.data.items;
|
2024-02-14 11:03:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 16:08:40 +00:00
|
|
|
|
type SendAnswerProps = {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
questionId: string;
|
|
|
|
|
body: string | string[];
|
|
|
|
|
qid: string;
|
2024-06-29 09:32:16 +00:00
|
|
|
|
preview?: boolean;
|
2024-05-01 08:12:06 +00:00
|
|
|
|
};
|
2024-04-17 16:08:40 +00:00
|
|
|
|
|
2024-06-29 09:32:16 +00:00
|
|
|
|
export function sendAnswer({ questionId, body, qid, preview = false }: SendAnswerProps) {
|
2025-05-01 13:15:54 +00:00
|
|
|
|
console.log("qid");
|
|
|
|
|
console.log(qid);
|
2024-05-31 16:41:18 +00:00
|
|
|
|
if (preview) return;
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
|
|
|
|
|
const answers = [
|
|
|
|
|
{
|
|
|
|
|
question_id: questionId,
|
|
|
|
|
content: body, //тут массив с ответом
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
formData.append("answers", JSON.stringify(answers));
|
|
|
|
|
formData.append("qid", qid);
|
|
|
|
|
|
|
|
|
|
return publicationMakeRequest({
|
2024-06-02 09:55:23 +00:00
|
|
|
|
url: domain + `/answer/v1.0.0/answer`,
|
2024-05-31 16:41:18 +00:00
|
|
|
|
body: formData,
|
|
|
|
|
method: "POST",
|
|
|
|
|
});
|
2023-12-17 21:28:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//body ={file, filename}
|
2024-04-17 16:08:40 +00:00
|
|
|
|
type SendFileParams = {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
questionId: string;
|
|
|
|
|
body: {
|
|
|
|
|
name: string;
|
|
|
|
|
file: File;
|
|
|
|
|
preview: boolean;
|
|
|
|
|
};
|
|
|
|
|
qid: string;
|
2024-05-01 08:12:06 +00:00
|
|
|
|
};
|
2024-04-17 16:08:40 +00:00
|
|
|
|
|
|
|
|
|
type Answer = {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
question_id: string;
|
|
|
|
|
content: string;
|
2024-04-17 16:08:40 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function sendFile({ questionId, body, qid }: SendFileParams) {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
if (body.preview) return;
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
|
2024-08-28 00:18:19 +00:00
|
|
|
|
const file = new File([body.file], body.file.name.replace(/\s/g, "_"));
|
|
|
|
|
const nameImage = body.name.replace(/\s/g, "_");
|
|
|
|
|
|
2024-05-31 16:41:18 +00:00
|
|
|
|
const answers: Answer[] = [
|
|
|
|
|
{
|
|
|
|
|
question_id: questionId,
|
2024-08-28 00:18:19 +00:00
|
|
|
|
content: "file:" + nameImage,
|
2024-05-31 16:41:18 +00:00
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
formData.append("answers", JSON.stringify(answers));
|
2024-08-28 00:18:19 +00:00
|
|
|
|
formData.append(nameImage, file);
|
2024-05-31 16:41:18 +00:00
|
|
|
|
formData.append("qid", qid);
|
|
|
|
|
|
|
|
|
|
return publicationMakeRequest({
|
2024-06-02 09:55:23 +00:00
|
|
|
|
url: domain + `/answer/v1.0.0/answer`,
|
2024-05-31 16:41:18 +00:00
|
|
|
|
body: formData,
|
|
|
|
|
method: "POST",
|
|
|
|
|
});
|
2023-12-17 21:28:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//форма контактов
|
2024-04-17 16:08:40 +00:00
|
|
|
|
export type SendFCParams = {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
questionId: string;
|
|
|
|
|
body: {
|
|
|
|
|
name?: string;
|
|
|
|
|
email?: string;
|
|
|
|
|
phone?: string;
|
|
|
|
|
address?: string;
|
|
|
|
|
customs?: Record<string, string>;
|
|
|
|
|
};
|
|
|
|
|
qid: string;
|
|
|
|
|
preview: boolean;
|
2024-05-01 08:12:06 +00:00
|
|
|
|
};
|
2024-04-17 16:08:40 +00:00
|
|
|
|
|
|
|
|
|
export function sendFC({ questionId, body, qid, preview }: SendFCParams) {
|
2024-05-31 16:41:18 +00:00
|
|
|
|
if (preview) return;
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
|
|
|
|
|
// const keysBody = Object.keys(body)
|
|
|
|
|
// const content:any = {}
|
|
|
|
|
// fields.forEach((key) => {
|
|
|
|
|
// if (keysBody.includes(key)) content[key] = body.key
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
const answers = [
|
|
|
|
|
{
|
|
|
|
|
question_id: questionId,
|
|
|
|
|
content: JSON.stringify(body),
|
|
|
|
|
result: true,
|
|
|
|
|
qid,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
formData.append("answers", JSON.stringify(answers));
|
|
|
|
|
formData.append("qid", qid);
|
|
|
|
|
|
|
|
|
|
return publicationMakeRequest({
|
2024-06-02 09:55:23 +00:00
|
|
|
|
url: domain + `/answer/v1.0.0/answer`,
|
2024-05-31 16:41:18 +00:00
|
|
|
|
body: formData,
|
|
|
|
|
method: "POST",
|
|
|
|
|
});
|
2024-01-29 11:16:21 +00:00
|
|
|
|
}
|
2024-10-23 19:48:26 +00:00
|
|
|
|
|
|
|
|
|
//форма контактов
|
|
|
|
|
export type SendResultParams = {
|
|
|
|
|
questionId: string;
|
|
|
|
|
pointsSum: number;
|
|
|
|
|
qid: string;
|
|
|
|
|
preview: boolean;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function sendResult({ questionId, pointsSum, qid, preview }: SendResultParams) {
|
|
|
|
|
if (preview) return;
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
|
|
|
|
|
// const keysBody = Object.keys(body)
|
|
|
|
|
// const content:any = {}
|
|
|
|
|
// fields.forEach((key) => {
|
|
|
|
|
// if (keysBody.includes(key)) content[key] = body.key
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
const answers = [
|
|
|
|
|
{
|
|
|
|
|
question_id: questionId,
|
|
|
|
|
content: pointsSum.toString(),
|
|
|
|
|
result: false,
|
|
|
|
|
qid,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
formData.append("answers", JSON.stringify(answers));
|
|
|
|
|
formData.append("qid", qid);
|
|
|
|
|
|
|
|
|
|
return publicationMakeRequest({
|
|
|
|
|
url: domain + `/answer/v1.0.0/answer`,
|
|
|
|
|
body: formData,
|
|
|
|
|
method: "POST",
|
|
|
|
|
});
|
|
|
|
|
}
|