записывается сессия
This commit is contained in:
parent
e8eb1f6ff4
commit
f0bd1091f0
@ -1,22 +1,64 @@
|
|||||||
import { makeRequest } from "@frontend/kitui";
|
import axios from "axios";
|
||||||
|
|
||||||
export function getData(quizId: string) {
|
let SESSIONS = ""
|
||||||
return makeRequest<any>({
|
|
||||||
url: `https://s.hbpn.link/answer/settings`,
|
|
||||||
body: {
|
|
||||||
quiz_id: quizId,
|
|
||||||
limit: 100,
|
|
||||||
page: 0,
|
|
||||||
need_config: true,
|
|
||||||
|
|
||||||
|
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) {
|
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,
|
question_id: questionId,
|
||||||
content: body, //тут массив с ответом
|
content: body, //тут массив с ответом
|
||||||
@ -24,7 +66,7 @@ console.log(qid)
|
|||||||
formData.append("answers", JSON.stringify(answers));
|
formData.append("answers", JSON.stringify(answers));
|
||||||
formData.append("qid", qid);
|
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",
|
||||||
@ -45,7 +87,7 @@ export function sendFile({ questionId, body, qid }: any) {
|
|||||||
formData.append(body.name, body.file);
|
formData.append(body.name, body.file);
|
||||||
formData.append("qid", qid);
|
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",
|
||||||
@ -89,7 +131,7 @@ export function sendFC({ questionId, body, qid }: any) {
|
|||||||
formData.append("answers", JSON.stringify(answers));
|
formData.append("answers", JSON.stringify(answers));
|
||||||
formData.append("qid", qid);
|
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",
|
||||||
|
@ -90,6 +90,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
const showResult = (nextQuestion: QuizQuestionResult) => {
|
const showResult = (nextQuestion: QuizQuestionResult) => {
|
||||||
const isEmpty = checkEmptyData({ resultData: nextQuestion })
|
const isEmpty = checkEmptyData({ resultData: nextQuestion })
|
||||||
console.log("isEmpty", isEmpty)
|
console.log("isEmpty", isEmpty)
|
||||||
|
console.log("settings?.cfg.resultInfo.showResultForm", settings?.cfg.resultInfo.showResultForm)
|
||||||
|
|
||||||
if (nextQuestion) {
|
if (nextQuestion) {
|
||||||
if (nextQuestion && settings?.cfg.resultInfo.showResultForm === "before") {
|
if (nextQuestion && settings?.cfg.resultInfo.showResultForm === "before") {
|
||||||
|
@ -18,7 +18,7 @@ const QID =
|
|||||||
process.env.NODE_ENV === "production" ?
|
process.env.NODE_ENV === "production" ?
|
||||||
window.location.pathname.replace(/\//g, '')
|
window.location.pathname.replace(/\//g, '')
|
||||||
:
|
:
|
||||||
"4c15249d-d2e3-4d30-b6cb-63300c99faad"
|
"ef836ff8-35b1-4031-9acf-af5766bac2b2"
|
||||||
|
|
||||||
|
|
||||||
export const ViewPage = () => {
|
export const ViewPage = () => {
|
||||||
|
@ -16,7 +16,7 @@ import type { QuizQuestionFile } from "../../../model/questionTypes/file";
|
|||||||
import type { DragEvent } from "react";
|
import type { DragEvent } from "react";
|
||||||
import type { UploadFileType } from "@model/questionTypes/file";
|
import type { UploadFileType } from "@model/questionTypes/file";
|
||||||
import { enqueueSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { sendFile } from "@api/quizRelase";
|
import { sendAnswer, sendFile } from "@api/quizRelase";
|
||||||
import { useQuestionsStore } from "@stores/quizData/store"
|
import { useQuestionsStore } from "@stores/quizData/store"
|
||||||
|
|
||||||
type FileProps = {
|
type FileProps = {
|
||||||
@ -54,7 +54,7 @@ export const File = ({ currentQuestion }: FileProps) => {
|
|||||||
console.log(file)
|
console.log(file)
|
||||||
try {
|
try {
|
||||||
|
|
||||||
await sendFile({
|
const data = await sendFile({
|
||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: {
|
body: {
|
||||||
file: file,
|
file: file,
|
||||||
@ -63,6 +63,14 @@ console.log(file)
|
|||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
qid: settings.qid
|
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(
|
updateAnswer(
|
||||||
currentQuestion.id,
|
currentQuestion.id,
|
||||||
@ -70,6 +78,7 @@ console.log(file)
|
|||||||
);
|
);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
enqueueSnackbar("ответ не был засчитан")
|
enqueueSnackbar("ответ не был засчитан")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ export const Images = ({ currentQuestion }: ImagesProps) => {
|
|||||||
|
|
||||||
await sendAnswer({
|
await sendAnswer({
|
||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: currentQuestion.content.variants[index].answer,
|
body: `${currentQuestion.content.variants[index].answer} ${currentQuestion.content.variants[index].extendedText}`,
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
qid: settings.qid
|
qid: settings.qid
|
||||||
})
|
})
|
||||||
|
@ -89,7 +89,7 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
|||||||
|
|
||||||
await sendAnswer({
|
await sendAnswer({
|
||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: currentQuestion.content.variants[index].answer,
|
body: `${currentQuestion.content.variants[index].answer} ${currentQuestion.content.variants[index].extendedText}`,
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
qid: settings.qid
|
qid: settings.qid
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user