mirror of
https://github.com/ilyakooo0/urbit.git
synced 2025-01-08 08:08:35 +03:00
links: add soundcloud embeds
This commit is contained in:
parent
254c3cf3a7
commit
116bfac640
@ -7,7 +7,8 @@ export class LinkPreview extends Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
timeSinceLinkPost: this.getTimeSinceLinkPost()
|
timeSinceLinkPost: this.getTimeSinceLinkPost(),
|
||||||
|
embed: ""
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +68,12 @@ export class LinkPreview extends Component {
|
|||||||
/(?:(?:(?:(?:watch\?)?(?:time_continue=(?:[0-9]+))?.+v=)?([a-zA-Z0-9_-]+))(?:\?t\=(?:[0-9a-zA-Z]+))?)/.source // id
|
/(?:(?:(?:(?:watch\?)?(?:time_continue=(?:[0-9]+))?.+v=)?([a-zA-Z0-9_-]+))(?:\?t\=(?:[0-9a-zA-Z]+))?)/.source // id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let soundcloudRegex = new RegExp('' +
|
||||||
|
/(https?:\/\/(?:www.)?soundcloud.com\/[\w-]+\/?(?:sets\/)?[\w-]+)/.source
|
||||||
|
);
|
||||||
|
|
||||||
|
let isSoundcloud = soundcloudRegex.exec(props.url);
|
||||||
|
|
||||||
let ytMatch = youTubeRegex.exec(props.url);
|
let ytMatch = youTubeRegex.exec(props.url);
|
||||||
|
|
||||||
let embed = "";
|
let embed = "";
|
||||||
@ -91,13 +98,26 @@ export class LinkPreview extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isSoundcloud && this.state.embed === "") {
|
||||||
|
fetch(
|
||||||
|
'https://soundcloud.com/oembed?format=json&url=' +
|
||||||
|
encodeURIComponent(props.url))
|
||||||
|
.then((response) => {
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then((json) => {
|
||||||
|
console.log(json)
|
||||||
|
this.setState({embed: json.html})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
let nameClass = props.nickname ? "inter" : "mono";
|
let nameClass = props.nickname ? "inter" : "mono";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="pb6 w-100">
|
<div className="pb6 w-100">
|
||||||
<div
|
<div
|
||||||
className={"w-100 tc " + (ytMatch ? "embed-container" : "")}>
|
className={"w-100 tc " + (ytMatch ? "embed-container" : "")}>
|
||||||
{embed}
|
{embed || <div dangerouslySetInnerHTML={{__html: this.state.embed}}/>}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-column ml2 pt6 flex-auto">
|
<div className="flex flex-column ml2 pt6 flex-auto">
|
||||||
<a href={props.url} className="w-100 flex" target="_blank">
|
<a href={props.url} className="w-100 flex" target="_blank">
|
||||||
|
Loading…
Reference in New Issue
Block a user