| 324 | } |
| 325 | |
| 326 | JSValue 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 | |
| 357 | JSValue native_srixLoad(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv) { |
| 358 | // usage: srixLoad(filename : string); |
nothing calls this directly
no test coverage detected