api: Move sendPostRequest Javascript function to post.js asset

This commit is contained in:
Luke Dashjr 2025-03-11 19:49:37 +00:00
parent 86dd75305e
commit 382377f7ee
No known key found for this signature in database
GPG Key ID: A291A2C45D0C504A
3 changed files with 17 additions and 3 deletions

View File

@ -30,6 +30,7 @@ set(WEB_RESOURCES
www/coinbaser_top.html
www/threads_top.html
www/foot.html
www/assets/post.js
www/assets/style.css
www/assets/icons/datum_logo.svg
www/assets/icons/favicon.ico

View File

@ -753,7 +753,9 @@ int datum_api_thread_dashboard(struct MHD_Connection *connection) {
}
sz += snprintf(&output[sz], max_sz-1-sz, "</TABLE></form>");
if (have_admin) {
sz += snprintf(&output[sz], max_sz-1-sz, "<script>function sendPostRequest(url, data){data.csrf='%s';fetch(url,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(data)});}</script>", datum_config.api_csrf_token);
sz += snprintf(&output[sz], max_sz-1-sz, "<script>");
sz += snprintf(&output[sz], max_sz-1-sz, www_assets_post_js, datum_config.api_csrf_token);
sz += snprintf(&output[sz], max_sz-1-sz, "</script>");
}
sz += snprintf(&output[sz], max_sz-1-sz, "%s", www_foot_html);
@ -863,8 +865,9 @@ int datum_api_client_dashboard(struct MHD_Connection *connection) {
}
}
sz += snprintf(&output[sz], max_sz-1-sz, "</TABLE></form><p class=\"table-footer\">Total active hashrate estimate: %.2f Th/s</p><script>function sendPostRequest(url, data){data.csrf='%s';fetch(url,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(data)});}</script>", thr, datum_config.api_csrf_token);
sz += snprintf(&output[sz], max_sz-1-sz, "%s", www_foot_html);
sz += snprintf(&output[sz], max_sz-1-sz, "</TABLE></form><p class=\"table-footer\">Total active hashrate estimate: %.2f Th/s</p><script>", thr);
sz += snprintf(&output[sz], max_sz-1-sz, www_assets_post_js, datum_config.api_csrf_token);
sz += snprintf(&output[sz], max_sz-1-sz, "</script>%s", www_foot_html);
// return the home page with some data and such
response = MHD_create_response_from_buffer (sz, (void *) output, MHD_RESPMEM_MUST_FREE);

10
www/assets/post.js Normal file
View File

@ -0,0 +1,10 @@
function sendPostRequest(url, data) {
data.csrf = '%s';
fetch(url, {
method: 'POST',
headers: {
'Content-Type':'application/json'
},
body: JSON.stringify(data)
});
}