mirror changes from main
This commit is contained in:
parent
f56b9a967e
commit
9367a2178f
@ -1,98 +1,148 @@
|
|||||||
import { makeRequest } from "@frontend/kitui";
|
import axios from "axios";
|
||||||
|
|
||||||
export function getData(quizId: string) {
|
import type { AxiosError } from "axios";
|
||||||
return makeRequest<any>({
|
import type { GetDataResponse } from "../model/settingsData";
|
||||||
url: `https://s.hbpn.link/answer/settings`,
|
|
||||||
body: {
|
|
||||||
quiz_id: quizId,
|
|
||||||
limit: 100,
|
|
||||||
page: 0,
|
|
||||||
need_config: true,
|
|
||||||
|
|
||||||
},
|
let SESSIONS = "";
|
||||||
|
|
||||||
|
export const publicationMakeRequest = ({ url, body }: any) => {
|
||||||
|
console.log(body);
|
||||||
|
return axios(url, {
|
||||||
|
//@ts-ignore
|
||||||
|
data: body,
|
||||||
|
headers: {
|
||||||
|
"X-Sessionkey": SESSIONS,
|
||||||
|
"Content-Type": "multipart/form-data",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getData(quizId: string): Promise<{
|
||||||
|
data: GetDataResponse | null;
|
||||||
|
isRecentlyCompleted: boolean;
|
||||||
|
error?: string;
|
||||||
|
}> {
|
||||||
|
const QID =
|
||||||
|
process.env.NODE_ENV === "production"
|
||||||
|
? window.location.pathname.replace(/\//g, "")
|
||||||
|
: "ef836ff8-35b1-4031-9acf-af5766bac2b2";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { data, headers } = await axios<GetDataResponse>(
|
||||||
|
`https://s.hbpn.link/answer/settings`,
|
||||||
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
});
|
// headers,
|
||||||
|
data: JSON.stringify({
|
||||||
|
quiz_id: quizId,
|
||||||
|
limit: 100,
|
||||||
|
page: 0,
|
||||||
|
need_config: true,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
||||||
|
|
||||||
|
if (typeof sessions[QID] === "number") {
|
||||||
|
// unix время. Если меньше суток прошло - выводить ошибку, иначе пустить дальше
|
||||||
|
if (Date.now() - sessions[QID] < 86400000) {
|
||||||
|
return { data, isRecentlyCompleted: true };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SESSIONS = headers["x-sessionkey"];
|
||||||
|
|
||||||
|
return { data, isRecentlyCompleted: false };
|
||||||
|
} catch (nativeError) {
|
||||||
|
const error = nativeError as AxiosError;
|
||||||
|
|
||||||
|
return { data: null, isRecentlyCompleted: false, error: error.message };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendAnswer({ questionId, body, qid }: any) {
|
export function sendAnswer({ questionId, body, qid }: any) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
console.log(qid)
|
console.log(qid);
|
||||||
const answers = [{
|
const answers = [
|
||||||
question_id: questionId,
|
{
|
||||||
content: body, //тут массив с ответом
|
question_id: questionId,
|
||||||
}]
|
content: body, //тут массив с ответом
|
||||||
formData.append("answers", JSON.stringify(answers));
|
},
|
||||||
formData.append("qid", qid);
|
];
|
||||||
|
formData.append("answers", JSON.stringify(answers));
|
||||||
|
formData.append("qid", qid);
|
||||||
|
|
||||||
return makeRequest<FormData, { [key: string]: string; }>({
|
return publicationMakeRequest({
|
||||||
url: `https://s.hbpn.link/answer/answer`,
|
url: `https://s.hbpn.link/answer/answer`,
|
||||||
body: formData,
|
body: formData,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//body ={file, filename}
|
//body ={file, filename}
|
||||||
export function sendFile({ questionId, body, qid }: any) {
|
export function sendFile({ questionId, body, qid }: any) {
|
||||||
const formData = new FormData();
|
console.log(body);
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
const fd: any = {
|
const answers: any = [
|
||||||
question_id: questionId,
|
{
|
||||||
content: body.name,
|
question_id: questionId,
|
||||||
}
|
content: "file:" + body.name,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
fd[body.name] = body.file //target.files[0]
|
formData.append("answers", JSON.stringify(answers));
|
||||||
|
formData.append(body.name, body.file);
|
||||||
|
formData.append("qid", qid);
|
||||||
|
|
||||||
const answers = [fd]
|
return publicationMakeRequest({
|
||||||
formData.append("answers", JSON.stringify(answers));
|
url: `https://s.hbpn.link/answer/answer`,
|
||||||
formData.append("qid", qid);
|
body: formData,
|
||||||
|
method: "POST",
|
||||||
return makeRequest<FormData, { [key: string]: string; }>({
|
});
|
||||||
url: `https://s.hbpn.link/answer/answer`,
|
|
||||||
body: formData,
|
|
||||||
method: "POST",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const fields = [
|
const fields = [
|
||||||
"name",
|
"name",
|
||||||
"email",
|
"email",
|
||||||
"phone",
|
"phone",
|
||||||
"adress",
|
"adress",
|
||||||
"telegram",
|
"telegram",
|
||||||
"wechat",
|
"wechat",
|
||||||
"viber",
|
"viber",
|
||||||
"vk",
|
"vk",
|
||||||
"skype",
|
"skype",
|
||||||
"whatsup",
|
"whatsup",
|
||||||
"messenger",
|
"messenger",
|
||||||
"text"
|
"text",
|
||||||
]
|
];
|
||||||
|
|
||||||
//форма контактов
|
//форма контактов
|
||||||
export function sendFC({ questionId, body, qid }: any) {
|
export function sendFC({ questionId, body, qid }: any) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
// const keysBody = Object.keys(body)
|
// const keysBody = Object.keys(body)
|
||||||
// const content:any = {}
|
// const content:any = {}
|
||||||
// fields.forEach((key) => {
|
// fields.forEach((key) => {
|
||||||
// if (keysBody.includes(key)) content[key] = body.key
|
// if (keysBody.includes(key)) content[key] = body.key
|
||||||
// })
|
// })
|
||||||
|
|
||||||
|
const answers = [
|
||||||
|
{
|
||||||
|
question_id: questionId,
|
||||||
|
content: JSON.stringify(body),
|
||||||
|
result: true,
|
||||||
|
qid,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const answers = [{
|
formData.append("answers", JSON.stringify(answers));
|
||||||
question_id: questionId,
|
formData.append("qid", qid);
|
||||||
content: JSON.stringify(body),
|
|
||||||
result: true,
|
|
||||||
qid
|
|
||||||
}]
|
|
||||||
|
|
||||||
formData.append("answers", JSON.stringify(answers));
|
return publicationMakeRequest({
|
||||||
formData.append("qid", qid);
|
url: `https://s.hbpn.link/answer/answer`,
|
||||||
|
body: formData,
|
||||||
return makeRequest<FormData, { [key: string]: string; }>({
|
method: "POST",
|
||||||
url: `https://s.hbpn.link/answer/answer`,
|
});
|
||||||
body: formData,
|
}
|
||||||
method: "POST",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user