unclean SPARC
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* AWS download helper
|
||||
* @author Nike
|
||||
* @version 1.0
|
||||
* @category MyEic
|
||||
* @subcategory Libraries
|
||||
*/
|
||||
class AwsFileDownload {
|
||||
|
||||
options = {
|
||||
pdf : { url: 'https://api.dev.eismea.eu/stable/vod/source?file=',
|
||||
method: 'GET',
|
||||
headers: { 'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
credentials: 'include',
|
||||
},
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
this.mergeOptionsNode(this.options, options);
|
||||
}
|
||||
|
||||
mergeOptionsNode(target, source) {
|
||||
for (let option in source) {
|
||||
if(typeof source[option] === 'object' && !Array.isArray(source[option]) && (option in target) && !(target[option] instanceof(Element))) {
|
||||
this.mergeOptionsNode(target[option], source[option]);
|
||||
} else {
|
||||
target[option] = source[option];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async getDownloadUrl(type, filename) {
|
||||
let response
|
||||
let uri = this.options[type].url+filename
|
||||
try {
|
||||
let foptions = {
|
||||
method: this.options[type].method,
|
||||
headers: this.options[type].headers,
|
||||
}
|
||||
if(this.options[type].credentials) foptions['credentials'] = this.options[type].credentials
|
||||
response = await fetch(uri, foptions)
|
||||
response = await response.json()
|
||||
if(response && response.payload && response.payload.url) return(response.payload.url)
|
||||
return(null)
|
||||
} catch(debugMessage) {
|
||||
console.warn('Error getting upload signed URL:',debugMessage)
|
||||
return('')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user