updated names of client asset functions
This commit is contained in:
parent
0ae03d0684
commit
6ae79ff054
2 changed files with 53 additions and 35 deletions
|
@ -76,49 +76,67 @@ const Asset = function () {
|
||||||
failureMessage.hidden = false;
|
failureMessage.hidden = false;
|
||||||
errorMessage.innerText = msg;
|
errorMessage.innerText = msg;
|
||||||
};
|
};
|
||||||
this.checkClaimAvailability = function () {
|
this.checkFileAndRenderAsset = function () {
|
||||||
const that = this;
|
const that = this;
|
||||||
|
this.isFileAvailable()
|
||||||
|
.then(isAvailable => {
|
||||||
|
if (!isAvailable) {
|
||||||
|
console.log('file is not yet available on spee.ch');
|
||||||
|
that.showSearchMessage();
|
||||||
|
return that.getAssetOnSpeech();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
that.showAsset();
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
that.showFailureMessage(error);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
this.isFileAvailable = function () {
|
||||||
|
console.log(`checking if file is available for ${this.state.claimName}#${this.state.claimId}`)
|
||||||
const uri = `/api/file-is-available/${this.state.claimName}/${this.state.claimId}`;
|
const uri = `/api/file-is-available/${this.state.claimName}/${this.state.claimId}`;
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
console.log(`checking local availability for ${this.state.claimName}#${this.state.claimId}`)
|
return new Promise((resolve, reject) => {
|
||||||
xhr.open("GET", uri, true);
|
xhr.open("GET", uri, true);
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
if (xhr.readyState == 4) {
|
if (xhr.readyState == 4) {
|
||||||
const response = JSON.parse(xhr.response);
|
const response = JSON.parse(xhr.response);
|
||||||
if (xhr.status == 200) {
|
if (xhr.status == 200) {
|
||||||
if (response.message === true) {
|
console.log('isFileAvailable succeeded:', response);
|
||||||
console.log('local asset is available on spee.ch')
|
if (response.message === true) {
|
||||||
that.showAsset();
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
that.showSearchMessage();
|
console.log('isFileAvailable failed:', response);
|
||||||
that.getAsset()
|
reject('Well this sucks, but we can\'t seem to phone home');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
console.log('get failed:', response);
|
|
||||||
that.showFailureMessage('Well this sucks, but we can\'t seem to phone home');
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
xhr.send();
|
||||||
xhr.send();
|
})
|
||||||
};
|
};
|
||||||
this.getAsset = function() {
|
this.getAssetOnSpeech = function() {
|
||||||
const that = this;
|
console.log(`getting claim for ${this.state.claimName}#${this.state.claimId}`)
|
||||||
const uri = `/api/claim-get/${this.state.claimName}/${this.state.claimId}`;
|
const uri = `/api/claim-get/${this.state.claimName}/${this.state.claimId}`;
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
console.log(`getting ${this.state.claimName}#${this.state.claimId}`)
|
return new Promise((resolve, reject) => {
|
||||||
xhr.open("GET", uri, true);
|
xhr.open("GET", uri, true);
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
if (xhr.readyState == 4) {
|
if (xhr.readyState == 4) {
|
||||||
const response = JSON.parse(xhr.response);
|
const response = JSON.parse(xhr.response);
|
||||||
if (xhr.status == 200) {
|
if (xhr.status == 200) {
|
||||||
console.log('get returned successfully', response);
|
console.log('getAssetOnSpeech succeeded:', response)
|
||||||
that.showAsset();
|
resolve(true);
|
||||||
} else {
|
} else {
|
||||||
console.log('get failed:', response);
|
console.log('getAssetOnSpeech failed:', response);
|
||||||
that.showFailureMessage(`${response.message}`);
|
reject(response.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
xhr.send();
|
||||||
xhr.send();
|
})
|
||||||
};
|
};
|
||||||
};
|
};
|
|
@ -32,6 +32,6 @@
|
||||||
asset.setState('fileExt', '{{claimInfo.fileExt}}');
|
asset.setState('fileExt', '{{claimInfo.fileExt}}');
|
||||||
asset.setState('contentType', '{{claimInfo.contentType}}');
|
asset.setState('contentType', '{{claimInfo.contentType}}');
|
||||||
console.log('asset state:', asset.state);
|
console.log('asset state:', asset.state);
|
||||||
asset.checkClaimAvailability();
|
asset.checkFileAndRenderAsset();
|
||||||
|
|
||||||
</script>
|
</script>
|
Loading…
Add table
Reference in a new issue