mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-01 11:33:41 +03:00
links: check for soundcloud url on mount
This commit is contained in:
parent
116bfac640
commit
9ee62d2e0d
@ -28,6 +28,27 @@ export class LinkPreview extends Component {
|
||||
timeSinceLinkPost: this.getTimeSinceLinkPost()
|
||||
});
|
||||
}, 60000);
|
||||
|
||||
// check for soundcloud for fetching embed
|
||||
let soundcloudRegex = new RegExp('' +
|
||||
/(https?:\/\/(?:www.)?soundcloud.com\/[\w-]+\/?(?:sets\/)?[\w-]+)/.source
|
||||
);
|
||||
|
||||
let isSoundcloud = soundcloudRegex.exec(this.props.url);
|
||||
|
||||
if (isSoundcloud && this.state.embed === "") {
|
||||
fetch(
|
||||
'https://soundcloud.com/oembed?format=json&url=' +
|
||||
encodeURIComponent(this.props.url))
|
||||
.then((response) => {
|
||||
return response.json();
|
||||
})
|
||||
.then((json) => {
|
||||
this.setState({ embed: json.html })
|
||||
});
|
||||
} else if (!isSoundcloud) {
|
||||
this.setState({ embed: "" });
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
@ -68,12 +89,6 @@ export class LinkPreview extends Component {
|
||||
/(?:(?:(?:(?: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 embed = "";
|
||||
@ -98,19 +113,6 @@ 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";
|
||||
|
||||
return (
|
||||
|
Loading…
Reference in New Issue
Block a user