записывается сессия

This commit is contained in:
Nastya 2024-01-23 21:00:06 +03:00
parent e8eb1f6ff4
commit f0bd1091f0
6 changed files with 72 additions and 20 deletions

@ -1,22 +1,64 @@
import { makeRequest } from "@frontend/kitui";
import axios from "axios";
export function getData(quizId: string) {
return makeRequest<any>({
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",
});
method: "POST"
})
}
export async function getData(quizId: string) {
const QID =
process.env.NODE_ENV === "production" ?
window.location.pathname.replace(/\//g, '')
:
"ef836ff8-35b1-4031-9acf-af5766bac2b2"
try {
const data = await axios(`https://s.hbpn.link/answer/settings`, {
method: "POST",
// headers,
data: JSON.stringify({
quiz_id: quizId,
limit: 100,
page: 0,
need_config: true,
}),
})
const sessions: any = JSON.parse(localStorage.getItem("sessions") || "{}")
if (typeof sessions[data.data.settings[QID]] === "number") {
//unix время. Если меньше суток прошло - выводить ошибку, иначе пустить дальше
throw new Error("Вы уже прошли этот опрос")
}
SESSIONS = data.headers["x-sessionkey"]
sessions[QID] = data.headers["x-sessionkey"]
localStorage.setItem("sessions", JSON.stringify(sessions))
return data.data
} catch (e) {
console.log(e)
}
}
export function sendAnswer({ questionId, body, qid }: any) {
const formData = new FormData();
console.log(qid)
console.log(qid)
const answers = [{
question_id: questionId,
content: body, //тут массив с ответом
@ -24,7 +66,7 @@ console.log(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`,
body: formData,
method: "POST",
@ -45,7 +87,7 @@ export function sendFile({ questionId, body, qid }: any) {
formData.append(body.name, body.file);
formData.append("qid", qid);
return makeRequest<FormData, { [key: string]: string; }>({
return publicationMakeRequest({
url: `https://s.hbpn.link/answer/answer`,
body: formData,
method: "POST",
@ -89,7 +131,7 @@ export function sendFC({ questionId, body, qid }: any) {
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`,
body: formData,
method: "POST",

@ -90,6 +90,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
const showResult = (nextQuestion: QuizQuestionResult) => {
const isEmpty = checkEmptyData({ resultData: nextQuestion })
console.log("isEmpty", isEmpty)
console.log("settings?.cfg.resultInfo.showResultForm", settings?.cfg.resultInfo.showResultForm)
if (nextQuestion) {
if (nextQuestion && settings?.cfg.resultInfo.showResultForm === "before") {

@ -18,7 +18,7 @@ const QID =
process.env.NODE_ENV === "production" ?
window.location.pathname.replace(/\//g, '')
:
"4c15249d-d2e3-4d30-b6cb-63300c99faad"
"ef836ff8-35b1-4031-9acf-af5766bac2b2"
export const ViewPage = () => {

@ -16,7 +16,7 @@ import type { QuizQuestionFile } from "../../../model/questionTypes/file";
import type { DragEvent } from "react";
import type { UploadFileType } from "@model/questionTypes/file";
import { enqueueSnackbar } from "notistack";
import { sendFile } from "@api/quizRelase";
import { sendAnswer, sendFile } from "@api/quizRelase";
import { useQuestionsStore } from "@stores/quizData/store"
type FileProps = {
@ -54,7 +54,7 @@ export const File = ({ currentQuestion }: FileProps) => {
console.log(file)
try {
await sendFile({
const data = await sendFile({
questionId: currentQuestion.id,
body: {
file: file,
@ -63,6 +63,14 @@ console.log(file)
//@ts-ignore
qid: settings.qid
})
console.log(data)
await sendAnswer({
questionId: currentQuestion.id,
body: `https://storage.yandexcloud.net/squizanswer/${settings.qid}/${currentQuestion.id}/${data.data.fileIDMap[currentQuestion.id]}`,
//@ts-ignore
qid: settings.qid
})
updateAnswer(
currentQuestion.id,
@ -70,6 +78,7 @@ console.log(file)
);
} catch (e) {
console.log(e)
enqueueSnackbar("ответ не был засчитан")
}

@ -76,7 +76,7 @@ export const Images = ({ currentQuestion }: ImagesProps) => {
await sendAnswer({
questionId: currentQuestion.id,
body: currentQuestion.content.variants[index].answer,
body: `${currentQuestion.content.variants[index].answer} ${currentQuestion.content.variants[index].extendedText}`,
//@ts-ignore
qid: settings.qid
})

@ -89,7 +89,7 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
await sendAnswer({
questionId: currentQuestion.id,
body: currentQuestion.content.variants[index].answer,
body: `${currentQuestion.content.variants[index].answer} ${currentQuestion.content.variants[index].extendedText}`,
//@ts-ignore
qid: settings.qid
})