MCPcopy Create free account
hub / github.com/BruceDevices/firmware / native_srixSave

Function native_srixSave

src/modules/bjs_interpreter/rfid_js.cpp:326–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

324}
325
326JSValue native_srixSave(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv) {
327 // usage: srixSave(filename : string);
328 // returns: { success: boolean, message: string, filepath: string }
329
330 if (argc < 1 || !JS_IsString(ctx, argv[0])) { return JS_NULL; }
331
332 JSCStringBuf buf;
333 const char *filename = JS_ToCString(ctx, argv[0], &buf);
334 if (!filename) { return JS_NULL; }
335
336 SRIXTool *srixReader = getSRIXReader();
337
338 // Save file
339 String result = srixReader->save_file_headless(String(filename));
340
341 // Create return object
342 JSValue obj = JS_NewObject(ctx);
343
344 if (!result.isEmpty()) {
345 JS_SetPropertyStr(ctx, obj, "success", JS_NewBool(true));
346 JS_SetPropertyStr(ctx, obj, "message", JS_NewString(ctx, "File saved successfully"));
347 JS_SetPropertyStr(ctx, obj, "filepath", JS_NewString(ctx, result.c_str()));
348 } else {
349 JS_SetPropertyStr(ctx, obj, "success", JS_NewBool(false));
350 JS_SetPropertyStr(ctx, obj, "message", JS_NewString(ctx, "Error saving file"));
351 JS_SetPropertyStr(ctx, obj, "filepath", JS_NewString(ctx, ""));
352 }
353
354 return obj;
355}
356
357JSValue native_srixLoad(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv) {
358 // usage: srixLoad(filename : string);

Callers

nothing calls this directly

Calls 2

getSRIXReaderFunction · 0.85
save_file_headlessMethod · 0.45

Tested by

no test coverage detected