Skip to content

Commit

Permalink
fix: added condition to identify if the file URL has or not @@Download (
Browse files Browse the repository at this point in the history
  • Loading branch information
Wagner3UB authored Oct 15, 2024
1 parent a8164c8 commit a30551e
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/customizations/components/manage/Blocks/Video/Body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* @module components/manage/Blocks/Video/Body
*/

import React from "react";
import PropTypes from "prop-types";
import { FormattedMessage } from "react-intl";
import { Embed, Message } from "semantic-ui-react";
import cx from "classnames";
import { isInternalURL, flattenToAppURL } from "@plone/volto/helpers";
import { ConditionalEmbed } from "../../../../../";
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { Embed, Message } from 'semantic-ui-react';
import cx from 'classnames';
import { isInternalURL, flattenToAppURL } from '@plone/volto/helpers';
import { ConditionalEmbed } from '../../../../../';

/**
* Body video block class.
Expand All @@ -27,13 +27,13 @@ const Body = ({ data, isEditMode }) => {
let listID = null;

if (!placeholder && data.url) {
if (data.url.match("youtu")) {
if (data.url.match('youtu')) {
if (!placeholder) {
//load video preview image from youtube

if (data.url.match("list")) {
if (data.url.match('list')) {
listID = data.url.match(/^.*\?list=(.*)|^.*&list=(.*)$/)[1];
if (data.url.match("v=")) {
if (data.url.match('v=')) {
videoID = data.url.match(/^.*\?v=(.*)&(.*)$/)?.[1] || null;
}
} else {
Expand All @@ -43,11 +43,11 @@ const Body = ({ data, isEditMode }) => {
}

placeholder =
"https://img.youtube.com/vi/" + videoID + "/sddefault.jpg";
'https://img.youtube.com/vi/' + videoID + '/sddefault.jpg';
}
} else if (data.url.match("vimeo")) {
} else if (data.url.match('vimeo')) {
videoID = data.url.match(/^.*\.com\/(.*)/)[1];
placeholder = "https://vumbnail.com/" + videoID + ".jpg";
placeholder = 'https://vumbnail.com/' + videoID + '.jpg';
}
}

Expand All @@ -60,10 +60,10 @@ const Body = ({ data, isEditMode }) => {

const embedSettings = {
placeholder: placeholder,
icon: "play",
icon: 'play',
defaultActive: false,
autoplay: false,
aspectRatio: "16:9",
aspectRatio: '16:9',
tabIndex: 0,
onKeyPress: onKeyDown,
ref: ref,
Expand All @@ -73,14 +73,14 @@ const Body = ({ data, isEditMode }) => {
<>
{data.url && (
<div
className={cx("video-inner", {
"full-width": data.align === "full",
className={cx('video-inner', {
'full-width': data.align === 'full',
})}
>
<ConditionalEmbed url={data.url}>
{data.url.match("youtu") ? (
{data.url.match('youtu') ? (
<>
{data.url.match("list") ? (
{data.url.match('list') ? (
<Embed
url={`https://www.youtube.com/embed/videoseries?list=${listID}`}
{...embedSettings}
Expand All @@ -91,16 +91,18 @@ const Body = ({ data, isEditMode }) => {
</>
) : (
<>
{data.url.match("vimeo") ? (
{data.url.match('vimeo') ? (
<Embed id={videoID} source="vimeo" {...embedSettings} />
) : (
<>
{data.url.match(".mp4") ? (
{data.url.match('.mp4') ? (
// eslint-disable-next-line jsx-a11y/media-has-caption
<video
src={
isInternalURL(data.url)
? `${flattenToAppURL(data.url)}/@@download/file`
? data.url.includes('@@download')
? data.url
: `${flattenToAppURL(data.url)}/@@download/file`
: data.url
}
controls
Expand Down

0 comments on commit a30551e

Please sign in to comment.