unclean SPARC

This commit is contained in:
STEINNI
2025-08-27 07:03:09 +00:00
commit f308460931
430 changed files with 54426 additions and 0 deletions
+53
View File
@@ -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('')
}
}
}
+55
View File
@@ -0,0 +1,55 @@
/**
* AWS File upload
* @extends FileUpload
* @author Nike
* @version 1.0
* @category MyEic
* @subcategory Libraries
*/
class AwsFileUpload extends FileUpload {
constructor(el, options) {
super(el, options);
this.filename = options.filename
this.pic = options.pic
this.pid = options.pid
}
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 onBeforeUploadOneStart(file) {
let response
let ext = file.name.substring(file.name.lastIndexOf('.')+1) //Get the extension from the user file name
if((!this.filename) || (this.filename != this.createFileName(this.pic, this.pid)+'.'+ext)) { // Carefull: extension could change !
this.filename = this.createFileName(this.pic, this.pid)+'.'+ext
}
let uri = this.options.getSignedUrl+this.filename
try {
response = await fetch(uri, {
method: this.options.getSignedMethod,
headers: { 'Accept': 'application/json',
'Content-Type': file.type,
},
credentials: 'include',
}).then( response => response.json())
let payload = response.payload
this.options.uploadUrl = payload.url // Signed url is here
this.options.uploadMethod = 'PUT'
} catch(debugMessage) {
console.warn('Error getting upload signed URL:',debugMessage)
return(false)
}
return(true)
}
createFileName(pic, pid) { return(pic+'_'+pid+'_'+crypto.randomUUID()) }
}