mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
Refactor to comply with PR feedback
This commit is contained in:
parent
b2a21c5cc1
commit
e863349531
@ -41,15 +41,24 @@ const S3DownloadButton = React.createClass({
|
|||||||
window.clearInterval(this.state.signatureExpiryTime);
|
window.clearInterval(this.state.signatureExpiryTime);
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidUpdate() {
|
transformS3UrlToS3Key(url) {
|
||||||
const { signatureExpiryTimerId, downloadUrl } = this.state;
|
return url.replace(`https://${AppConstants.cloudfrontDomain}/`, '');
|
||||||
|
},
|
||||||
|
|
||||||
if(!signatureExpiryTimerId && downloadUrl) {
|
signUrl() {
|
||||||
|
const { url, title, artistName } = this.props;
|
||||||
|
|
||||||
|
S3Fetcher
|
||||||
|
.signUrl(this.transformS3UrlToS3Key(url), title, artistName)
|
||||||
|
.then(({ signed_url: downloadUrl }) => {
|
||||||
|
const { signatureExpiryTimerId } = this.state;
|
||||||
|
let newState = { downloadUrl };
|
||||||
|
|
||||||
|
if(!signatureExpiryTimerId) {
|
||||||
/**
|
/**
|
||||||
* The signed url, however can expire, which is why
|
* The signed url, however can expire, which is why
|
||||||
* we need to renew it when it expires.
|
* we need to renew it when it expires.
|
||||||
*/
|
*/
|
||||||
const { downloadUrl } = this.state;
|
|
||||||
const expires = parseInt(queryParamsToArgs(downloadUrl.split('?')[1]).expires, 10);
|
const expires = parseInt(queryParamsToArgs(downloadUrl.split('?')[1]).expires, 10);
|
||||||
const now = new Date().getTime() / 1000;
|
const now = new Date().getTime() / 1000;
|
||||||
|
|
||||||
@ -60,23 +69,13 @@ const S3DownloadButton = React.createClass({
|
|||||||
*/
|
*/
|
||||||
const interval = (expires - now) * 1000;
|
const interval = (expires - now) * 1000;
|
||||||
|
|
||||||
this.setState({
|
Object.assign(newState, {
|
||||||
// Substract 5s to make sure there is a big enough window to sign again before expiration
|
// Substract 5s to make sure there is a big enough window to sign again before expiration
|
||||||
signatureExpiryTimerId: window.setInterval(this.signUrl, interval - 5000)
|
signatureExpiryTimerId: window.setInterval(this.signUrl, interval - 5000)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
this.setState(newState);
|
||||||
|
})
|
||||||
transformS3UrlToS3Key(url) {
|
|
||||||
return url.replace(`https://${AppConstants.cloudfrontDomain}/`, '');
|
|
||||||
},
|
|
||||||
|
|
||||||
signUrl(next) {
|
|
||||||
const { url, title, artistName } = this.props;
|
|
||||||
|
|
||||||
S3Fetcher
|
|
||||||
.signUrl(this.transformS3UrlToS3Key(url), title, artistName)
|
|
||||||
.then(({ signed_url: downloadUrl }) => this.setState({ downloadUrl }, next))
|
|
||||||
.catch(console.logGlobal);
|
.catch(console.logGlobal);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -34,10 +34,6 @@ class NotificationStore {
|
|||||||
this.editionListNotifications = res.notifications;
|
this.editionListNotifications = res.notifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
onFlushPieceListNotifications() {
|
|
||||||
this.editionListNotifications = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
onUpdateEditionNotifications(res) {
|
onUpdateEditionNotifications(res) {
|
||||||
this.editionNotifications = res.notification;
|
this.editionNotifications = res.notification;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user