added link video parse
All checks were successful
publish-main / release-image (push) Successful in 3m59s
All checks were successful
publish-main / release-image (push) Successful in 3m59s
This commit is contained in:
parent
006c9bc4ea
commit
1e1bdceb2c
@ -9,14 +9,6 @@
|
||||
font-size: 15px;
|
||||
font-family: "Montserrat", sans-serif;
|
||||
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 {
|
||||
font-size: 11px;
|
||||
@ -24,19 +16,15 @@
|
||||
font-style: italic;
|
||||
color: rgb(200, 200, 200);
|
||||
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 {
|
||||
iframe {
|
||||
|
||||
}
|
||||
&__error {
|
||||
font-size: 12px;
|
||||
color: rgb(220, 105, 105);
|
||||
}
|
||||
}
|
||||
&::-webkit-scrollbar {
|
||||
height: 7px;
|
||||
|
@ -29,7 +29,7 @@ const AnswerModal = ({
|
||||
}) => {
|
||||
|
||||
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-content" className={classes.myModal__dialog__content}>
|
||||
<div class="modal-header" className={classes.myModal__dialog__content__header}>
|
||||
|
@ -1,6 +1,7 @@
|
||||
import React, { useState } from "react";
|
||||
import classes from "../assets/styles/generatingFormFields.module.scss";
|
||||
import MarkdownEditor from "@uiw/react-markdown-editor";
|
||||
import { parseTotalLinkVideo } from "../hooks/sundry/parseLinkVideo";
|
||||
|
||||
const GeneratingFormFields = ({listBlock, listTypeAnswer, answers, updateAnswersForm}) => {
|
||||
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__comment}>{item.comment}</p>
|
||||
<div className={classes.item__question__video}>
|
||||
{item.video ? <iframe
|
||||
width="300"
|
||||
height="150"
|
||||
src={item.video}
|
||||
frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
referrerpolicy="strict-origin-when-cross-origin"
|
||||
allowfullscreen
|
||||
></iframe> : <span></span>}
|
||||
{item.video ?
|
||||
parseTotalLinkVideo(item.video).check ?
|
||||
<iframe
|
||||
width="300"
|
||||
height="150"
|
||||
src={parseTotalLinkVideo(item.video).parseLink}
|
||||
frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
referrerpolicy="strict-origin-when-cross-origin"
|
||||
allowfullscreen
|
||||
></iframe> :
|
||||
<span className={classes.item__question__video__error}>
|
||||
Данный сервис неподдерживает использование их видео.
|
||||
</span> :
|
||||
<span></span>}
|
||||
</div>
|
||||
</div>
|
||||
<div className={classes.item__answer}>
|
||||
|
@ -9,6 +9,7 @@ const MarkDown = ({mkValue, setMkValue}) => {
|
||||
value={mkValue}
|
||||
onChange={(value, viewUpdate) => setMkValue(value)}
|
||||
enablePreview={false}
|
||||
visibleDragbar={false}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
75
src/hooks/sundry/parseLinkVideo.js
Normal file
75
src/hooks/sundry/parseLinkVideo.js
Normal 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 }
|
@ -9,7 +9,7 @@ import { FormsData, TypeAnswerData } from "../context";
|
||||
import { listFormsApi, updateTitleFormApi } from "../hooks/api/listFormsApi.js";
|
||||
import { saveFormApi, addFormBlockApi, listFormBlockApi, updateBlockApi, updateOrderBlockApi } from "../hooks/api/formApi.js";
|
||||
import { responseDataToListBlock } from "../hooks/sundry/parseListBlock.js";
|
||||
import MarkDown from "../components/MarkDown.jsx";
|
||||
import { parseVKlinkVideo } from "../hooks/sundry/parseLinkVideo.js";
|
||||
|
||||
const NewForm = () => {
|
||||
const navigate = useNavigate();
|
||||
@ -136,6 +136,8 @@ const NewForm = () => {
|
||||
video: video
|
||||
}
|
||||
|
||||
console.log(parseVKlinkVideo(video))
|
||||
|
||||
const response = await addFormBlockApi(cookies.token, formId, newBlock)
|
||||
|
||||
if (response.status === 200) {
|
||||
|
Loading…
Reference in New Issue
Block a user