added link video parse
All checks were successful
publish-main / release-image (push) Successful in 3m59s

This commit is contained in:
kuwsh1n 2024-04-21 10:37:18 +03:00
parent 006c9bc4ea
commit 1e1bdceb2c
6 changed files with 100 additions and 27 deletions

View File

@ -9,14 +9,6 @@
font-size: 15px; font-size: 15px;
font-family: "Montserrat", sans-serif; font-family: "Montserrat", sans-serif;
width: 100%; width: 100%;
// overflow-x: auto;
// &::-webkit-scrollbar {
// height: 7px;
// border: 1px solid rgb(200, 200, 200);
// }
// &::-webkit-scrollbar-thumb {
// background-color: rgb(200, 200, 200);
// }
} }
&__comment { &__comment {
font-size: 11px; font-size: 11px;
@ -24,19 +16,15 @@
font-style: italic; font-style: italic;
color: rgb(200, 200, 200); color: rgb(200, 200, 200);
width: 100%; width: 100%;
// overflow-x: auto;
// &::-webkit-scrollbar {
// height: 7px;
// border: 1px solid rgb(200, 200, 200);
// }
// &::-webkit-scrollbar-thumb {
// background-color: rgb(200, 200, 200);
// }
} }
&__video { &__video {
iframe { iframe {
} }
&__error {
font-size: 12px;
color: rgb(220, 105, 105);
}
} }
&::-webkit-scrollbar { &::-webkit-scrollbar {
height: 7px; height: 7px;

View File

@ -29,7 +29,7 @@ const AnswerModal = ({
}) => { }) => {
return ( return (
<div class="modal fade myModal" className={classes.myModal} id="answerModal" tabIndex="-1" aria-labelledby="exampleModalLabel" data-bs-backdrop="static" aria-hidden="true"> <div class="modal fade modal-lg myModal" className={classes.myModal} id="answerModal" tabIndex="-1" aria-labelledby="exampleModalLabel" data-bs-backdrop="static" aria-hidden="true">
<div class="modal-dialog myModal__dialog" className={classes.myModal__dialog}> <div class="modal-dialog myModal__dialog" className={classes.myModal__dialog}>
<div class="modal-content" className={classes.myModal__dialog__content}> <div class="modal-content" className={classes.myModal__dialog__content}>
<div class="modal-header" className={classes.myModal__dialog__content__header}> <div class="modal-header" className={classes.myModal__dialog__content__header}>

View File

@ -1,6 +1,7 @@
import React, { useState } from "react"; import React, { useState } from "react";
import classes from "../assets/styles/generatingFormFields.module.scss"; import classes from "../assets/styles/generatingFormFields.module.scss";
import MarkdownEditor from "@uiw/react-markdown-editor"; import MarkdownEditor from "@uiw/react-markdown-editor";
import { parseTotalLinkVideo } from "../hooks/sundry/parseLinkVideo";
const GeneratingFormFields = ({listBlock, listTypeAnswer, answers, updateAnswersForm}) => { const GeneratingFormFields = ({listBlock, listTypeAnswer, answers, updateAnswersForm}) => {
return ( return (
@ -10,15 +11,21 @@ const GeneratingFormFields = ({listBlock, listTypeAnswer, answers, updateAnswers
<p className={classes.item__question__text}>{i + 1}) <MarkdownEditor.Markdown source={item.question}/></p> <p className={classes.item__question__text}>{i + 1}) <MarkdownEditor.Markdown source={item.question}/></p>
<p className={classes.item__question__comment}>{item.comment}</p> <p className={classes.item__question__comment}>{item.comment}</p>
<div className={classes.item__question__video}> <div className={classes.item__question__video}>
{item.video ? <iframe {item.video ?
parseTotalLinkVideo(item.video).check ?
<iframe
width="300" width="300"
height="150" height="150"
src={item.video} src={parseTotalLinkVideo(item.video).parseLink}
frameborder="0" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerpolicy="strict-origin-when-cross-origin" referrerpolicy="strict-origin-when-cross-origin"
allowfullscreen allowfullscreen
></iframe> : <span></span>} ></iframe> :
<span className={classes.item__question__video__error}>
Данный сервис неподдерживает использование их видео.
</span> :
<span></span>}
</div> </div>
</div> </div>
<div className={classes.item__answer}> <div className={classes.item__answer}>

View File

@ -9,6 +9,7 @@ const MarkDown = ({mkValue, setMkValue}) => {
value={mkValue} value={mkValue}
onChange={(value, viewUpdate) => setMkValue(value)} onChange={(value, viewUpdate) => setMkValue(value)}
enablePreview={false} enablePreview={false}
visibleDragbar={false}
/> />
</div> </div>

View File

@ -0,0 +1,75 @@
const serviceVideo = {
"www.youtube.com": parseYTlinkVideo,
"youtu.be": parseMobileYTlinkVideo,
"vk.com": parseVKlinkVideo,
"rutube.ru": parseRTlinkVideo
}
function parseYTlinkVideo(link) {
const startIndexIdVideo = link.indexOf("watch?v=") + 8;
const endIndexIdVideo = link.indexOf("&");
const idVideo = endIndexIdVideo === -1 ?
link.slice(startIndexIdVideo) :
link.slice(startIndexIdVideo, endIndexIdVideo);
return `https://www.youtube.com/embed/${idVideo}`
};
function parseMobileYTlinkVideo(link) {
const startIndexIdVideo = 17;
const endIndexIdVideo = link.indexOf("?");
const idVideo = endIndexIdVideo === -1 ?
link.slice(startIndexIdVideo) :
link.slice(startIndexIdVideo, endIndexIdVideo);
return `https://www.youtube.com/embed/${idVideo}`
};
function parseVKlinkVideo(link) {
let idVideo = "";
if (link.indexOf("video?z=video") !== -1) {
const startIndexIdVideo = link.indexOf("video?z=video") + 13;
const endIndexIdVideo = link.lastIndexOf("%");
idVideo = link.slice(startIndexIdVideo, endIndexIdVideo);
}
else if (link.indexOf("video") !== -1) {
const startIndexIdVideo = link.indexOf("video") + 5;
idVideo = link.slice(startIndexIdVideo)
}
const oid = idVideo.slice(0, idVideo.indexOf("_"));
const id = idVideo.slice(idVideo.indexOf("_") + 1);
return `https://vk.com/video_ext.php?oid=${oid}&id=${id}&hd=2`
};
function parseRTlinkVideo(link) {
const startIndexIdVideo = link.indexOf("video/") + 6;
const endIndexIdVideo = link.lastIndexOf("?r=a");
const idVideo = endIndexIdVideo === -1 ?
link.slice(startIndexIdVideo) :
link.slice(startIndexIdVideo, endIndexIdVideo);
return `https://rutube.ru/play/embed/${idVideo}`
};
function parseTotalLinkVideo(link) {
const serviceLink = {
check: false,
parseLink: ""
};
if (link) {
for (let key of Object.keys(serviceVideo)) {
if (link.indexOf(key) !== -1) {
serviceLink.parseLink = serviceVideo[key](link);
serviceLink.check = true;
}
}
}
return serviceLink
};
export { parseYTlinkVideo, parseVKlinkVideo, parseTotalLinkVideo }

View File

@ -9,7 +9,7 @@ import { FormsData, TypeAnswerData } from "../context";
import { listFormsApi, updateTitleFormApi } from "../hooks/api/listFormsApi.js"; import { listFormsApi, updateTitleFormApi } from "../hooks/api/listFormsApi.js";
import { saveFormApi, addFormBlockApi, listFormBlockApi, updateBlockApi, updateOrderBlockApi } from "../hooks/api/formApi.js"; import { saveFormApi, addFormBlockApi, listFormBlockApi, updateBlockApi, updateOrderBlockApi } from "../hooks/api/formApi.js";
import { responseDataToListBlock } from "../hooks/sundry/parseListBlock.js"; import { responseDataToListBlock } from "../hooks/sundry/parseListBlock.js";
import MarkDown from "../components/MarkDown.jsx"; import { parseVKlinkVideo } from "../hooks/sundry/parseLinkVideo.js";
const NewForm = () => { const NewForm = () => {
const navigate = useNavigate(); const navigate = useNavigate();
@ -136,6 +136,8 @@ const NewForm = () => {
video: video video: video
} }
console.log(parseVKlinkVideo(video))
const response = await addFormBlockApi(cookies.token, formId, newBlock) const response = await addFormBlockApi(cookies.token, formId, newBlock)
if (response.status === 200) { if (response.status === 200) {