| 131 | } |
| 132 | |
| 133 | JSValue native_rfidSave(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv) { |
| 134 | // usage: rfidSave(filename : string); |
| 135 | // returns: { success: boolean, message: string, filepath: string } |
| 136 | |
| 137 | if (argc < 1 || !JS_IsString(ctx, argv[0])) { return JS_NULL; } |
| 138 | |
| 139 | JSCStringBuf buf; |
| 140 | const char *filename = JS_ToCString(ctx, argv[0], &buf); |
| 141 | if (!filename) { return JS_NULL; } |
| 142 | |
| 143 | TagOMatic *tagReader = getTagReader(); |
| 144 | |
| 145 | // Save file |
| 146 | String result = tagReader->save_file_headless(String(filename)); |
| 147 | |
| 148 | // Create return object |
| 149 | JSValue obj = JS_NewObject(ctx); |
| 150 | |
| 151 | if (!result.isEmpty()) { |
| 152 | JS_SetPropertyStr(ctx, obj, "success", JS_NewBool(true)); |
| 153 | JS_SetPropertyStr(ctx, obj, "message", JS_NewString(ctx, "File saved successfully")); |
| 154 | JS_SetPropertyStr(ctx, obj, "filepath", JS_NewString(ctx, result.c_str())); |
| 155 | } else { |
| 156 | JS_SetPropertyStr(ctx, obj, "success", JS_NewBool(false)); |
| 157 | JS_SetPropertyStr(ctx, obj, "message", JS_NewString(ctx, "Error saving file")); |
| 158 | JS_SetPropertyStr(ctx, obj, "filepath", JS_NewString(ctx, "")); |
| 159 | } |
| 160 | |
| 161 | return obj; |
| 162 | } |
| 163 | |
| 164 | JSValue native_rfidLoad(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv) { |
| 165 | // usage: rfidLoad(filename : string); |
nothing calls this directly
no test coverage detected