make drivers and KV also preflightless

This commit is contained in:
ProgrammerIn-wonderland
2025-09-14 17:01:16 -04:00
committed by Neal Shah
parent 135d7b81a4
commit 1e620c73bc
5 changed files with 13 additions and 7 deletions

View File

@@ -53,6 +53,8 @@ module.exports = function eggspress (route, settings, handler) {
// A hack so plain text is parsed as JSON in methods which need to be lower latency/avoid the cors roundtrip
if ( settings.noReallyItsJson ) mw.push(express.json({ type: '*/*' }));
mw.push(express.json({ type: (req) => req.headers['content-type'] === "text/plain;actually=json" }));
if ( settings.auth ) mw.push(require('../../../middleware/auth'));
if ( settings.auth2 ) mw.push(require('../../../middleware/auth2'));

View File

@@ -53,6 +53,7 @@ let _handle_multipart;
module.exports = eggspress('/drivers/call', {
subdomain: 'api',
auth2: true,
// noReallyItsJson: true,
allowedMethods: ['POST'],
}, async (req, res, next) => {
const x = Context.get();
@@ -64,6 +65,8 @@ module.exports = eggspress('/drivers/call', {
({ params: body, p_data_end: p_request } = await _handle_multipart(req));
} else body = req.body;
console.log("Driver call body: ")
const interface_name = body.interface;
const test_mode = body.test_mode;

View File

@@ -77,7 +77,7 @@ function uuidv4(){
*
* @returns {XMLHttpRequest} The initialized XMLHttpRequest object.
*/
function initXhr(endpoint, APIOrigin, authToken, method= "post", contentType = "application/json;charset=UTF-8", responseType = undefined) {
function initXhr(endpoint, APIOrigin, authToken, method= "post", contentType = "text/plain;actually=json", responseType = undefined) {
const xhr = new XMLHttpRequest();
xhr.open(method, APIOrigin + endpoint, true);
if (authToken)
@@ -279,7 +279,7 @@ async function driverCall_(
resolve_func, reject_func,
driverInterface, driverName, driverMethod, driverArgs,
method,
contentType = 'application/json;charset=UTF-8',
contentType = 'text/plain;actually=json',
settings = {},
) {
// Generate request ID for logging
@@ -319,7 +319,7 @@ async function driverCall_(
const success_cb = Valid.callback(options.success) ?? NOOP;
const error_cb = Valid.callback(options.error) ?? NOOP;
// create xhr object
const xhr = initXhr('/drivers/call', puter.APIOrigin, puter.authToken, 'POST', contentType);
const xhr = initXhr('/drivers/call', puter.APIOrigin, undefined, 'POST', contentType);
// Store request info for later logging
if (requestInfo) {
@@ -528,6 +528,7 @@ async function driverCall_(
test_mode: settings?.test_mode,
method: driverMethod,
args: driverArgs,
auth_token: puter.authToken
}));
}

View File

@@ -34,8 +34,7 @@ class FetchDriverCallBackend {
try {
const resp = await fetch(`${this.context.APIOrigin}/drivers/call`, {
headers: {
Authorization: `Bearer ${this.context.authToken}`,
'Content-Type': 'application/json',
'Content-Type': 'text/plain;actually=json',
},
method: 'POST',
body: JSON.stringify({
@@ -45,6 +44,7 @@ class FetchDriverCallBackend {
: {}),
method: method_name,
args: parameters,
auth_token: this.context.authToken
}),
});

View File

@@ -42,8 +42,7 @@ class KV{
const resp = await fetch(`${this.APIOrigin}/drivers/call`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.authToken}`,
'Content-Type': 'text/plain;actually=json',
},
body: JSON.stringify({
interface: 'puter-kvstore',
@@ -51,6 +50,7 @@ class KV{
args: {
key: gui_cache_keys,
},
auth_token: this.authToken
}),
});
const arr_values = await resp.json();