added format and endpoint into constructor,

fixed processing of parameters in methods,
added return for HTML manual,
chaged TypeScript code to class object export as default
This commit is contained in:
2025-06-01 19:19:48 +02:00
parent 2f7f63b620
commit a59044102c
3 changed files with 63 additions and 17 deletions

View File

@ -5,8 +5,8 @@
* <?php echo date('Y-m-d H:i:s'); ?>
*/
export const backend = {
endpont: window.location.origin + "<?php echo $this->apiName; ?>.php",
class <?php echo $this->apiName; ?> {
endpont = "<?php echo $this->endpoint; ?>";
/* ----------------------------------------------------
* General API call
@ -31,7 +31,7 @@ export const backend = {
});
xhttp.open('POST', this.endpont + '?action=' + method);
xhttp.send(form_data);
},
}
callPromise(method, data) {
return new Promise((resolve, reject) => {
@ -43,20 +43,22 @@ export const backend = {
}
});
})
},
}
/* ----------------------------------------------------
* API actions
*/
help() {
return this.callPromise('__HELP__', {});
},
}
<?php if (is_array($this->methods)) foreach ($this->methods as $method) {
echo "\t".$method['name'].'('.implode(', ', array_map(function($param) { return $param['name']; }, $method['params'])).') {';
echo "\n\t\treturn this.callPromise('".$method['name']."', {".implode(', ', array_map(function($param) { return $param['name'].': '.$param['name']; }, $method['params']))."});";
echo "\n\t},\n\n";
echo "\n\t}\n\n";
}
?>
};
export default new BackendAPI();