Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
writeOut = e => {
if (this.props.field.get("extraInfo")) {
try {
const { id, provider, mediaType } = urlParser.parse(e.target.value);
const videoInfo = urlParser.parse(e.target.value);
this.props.onChange({
url: e.target.value,
id: id,
mediaType: mediaType,
imageURL: urlParser.create({
videoInfo,
format: "longImage",
params: { imageQuality: "maxresdefault" }
})
});
} catch (err) {
console.error("Not a valid Youtube URL");
this.props.onChange(e.target.value);
}
} else {
this.props.onChange(e.target.value);
writeOut = e => {
if (this.props.field.get("extraInfo")) {
try {
const { id, provider, mediaType } = urlParser.parse(e.target.value);
const videoInfo = urlParser.parse(e.target.value);
this.props.onChange({
url: e.target.value,
id: id,
mediaType: mediaType,
imageURL: urlParser.create({
videoInfo,
format: "longImage",
params: { imageQuality: "maxresdefault" }
})
});
} catch (err) {
console.error("Not a valid Youtube URL");
this.props.onChange(e.target.value);
}
} else {
this.props.onChange(e.target.value);
}
};
checkSource(rule: string, value: string, callback: any) {
try {
const videoObj = videoParser.parse(value);
if (
(videoObj && videoObj.provider === "youtube") ||
videoObj.provider === "dailymotion" ||
videoObj.provider === "vimeo" ||
videoObj.provider === "youku"
) {
callback();
return;
}
return callback("URL not support");
} catch (e) {
return callback("URL not support");
}
}
fetchFromAPI = e => {
const { id = "" } = urlParser.parse(e.target.value) || "";
const APIKey = this.props.field.get("APIkey");
const data = fetch(
`https://www.googleapis.com/youtube/v3/videos?part=snippet&id=${id}&key=${APIKey}`
)
.then(res => res.json())
.then(json => {
if (json !== undefined) {
this.setState({ valid: true, data: json.items[0].snippet });
} else {
this.setState({ valid: false });
}
})
.catch(err => {
this.setState({ valid: false, data: {} });
return false;
});
searchVideo() {
if (this.match && this.match.videoURL) {
const video = urlParser.parse(this.match.videoURL);
let embedURL = urlParser.create({
videoInfo: video,
params: 'internal',
format: 'embed'
});
if (embedURL) {
if (embedURL.startsWith('//')) {
embedURL = 'https:' + embedURL;
}
this.videoSafeURL = this.sanitizer.bypassSecurityTrustResourceUrl(embedURL);
}
}
}
}
export function isYoutubeURL(url: string): boolean {
return !!url && !!urlParser.parse(url);
}
form.validateFields((err, values) => {
if (!err) {
const href = values.href;
if (href) {
const videoObj = videoParser.parse(href);
let slateObj: Object = {};
if (videoObj && videoObj.provider === "youtube") {
slateObj = {
type: youtubeType,
isVoid: true,
data: { [idKey]: videoObj.id }
};
} else if (videoObj && videoObj.provider === "dailymotion") {
slateObj = {
type: dailymotionType,
isVoid: true,
data: { [idKey]: videoObj.id }
};
} else if (videoObj && videoObj.provider === "vimeo") {
slateObj = {
export function fetchVideos(term: string): Promise {
const parsedTerm = urlParser.parse(term);
if (!parsedTerm) {
return Promise.resolve([]);
}
if (parsedTerm.list) {
return fetchVideosFromList(term);
}
return fetchVideoFromSingle(term);
}
validateURL = e => {
if (urlParser.parse(e.target.value)) {
this.setState({ valid: true });
} else {
this.setState({ valid: false });
}
this.writeOut(e);
};
searchVideo() {
if (this.match && this.match.videoURL) {
const video = urlParser.parse(this.match.videoURL);
let embedURL = urlParser.create({
videoInfo: video,
params: 'internal',
format: 'embed'
});
if (embedURL) {
if (embedURL.startsWith('//')) {
embedURL = 'https:' + embedURL;
}
this.videoSafeURL = this.sanitizer.bypassSecurityTrustResourceUrl(embedURL);
}
}
}
}