also looking at this
fix(bridge): stop discarding the fields the page actually sends
#82
7 files
+375
-34
| @@ -152,7 +152,13 @@ pub const FSBridge = struct { | ||
| 152 | 152 | /// JSON: {"path": "/path/to/file", "content": "data", "callbackId": "cb1"} |
| 153 | 153 | fn writeFile(self: *Self, data: []const u8) !void { |
| 154 | 154 | const path = json_utils.getString(data, "path") orelse ""; |
| 155 | const content = json_utils.getString(data, "content") orelse ""; | |
| 155 | // `craft.fs.writeFile(path, data)` sends the bytes under `data`; this | |
| 156 | // read `content`, which the page has never sent, so `orelse ""` fired | |
| 157 | // on every call and the file was created empty. `content` stays | |
| 158 | // accepted for anything posting raw bridge messages against the old | |
| 159 | // spelling. | |
| 160 | const content = json_utils.getString(data, "data") orelse | |
| 161 | json_utils.getString(data, "content") orelse ""; | |
| 156 | 162 | const callback_id = json_utils.getString(data, "callbackId") orelse ""; |
| 157 | 163 | |
| 158 | 164 | if (path.len == 0) return BridgeError.MissingData; |
| @@ -179,7 +185,10 @@ pub const FSBridge = struct { | ||
| 179 | 185 | /// JSON: {"path": "/path/to/file", "content": "data", "callbackId": "cb1"} |
| 180 | 186 | fn appendFile(self: *Self, data: []const u8) !void { |
| 181 | 187 | const path = json_utils.getString(data, "path") orelse ""; |
| 182 | const content = json_utils.getString(data, "content") orelse ""; | |
| 188 | // Same mismatch as `writeFile`: the page sends `data`, this read | |
| 189 | // `content`, and the append wrote nothing while reporting success. | |
| 190 | const content = json_utils.getString(data, "data") orelse | |
| 191 | json_utils.getString(data, "content") orelse ""; | |
| 183 | 192 | const callback_id = json_utils.getString(data, "callbackId") orelse ""; |
| 184 | 193 | |
| 185 | 194 | if (path.len == 0) return BridgeError.MissingData; |
| @@ -451,8 +460,13 @@ pub const FSBridge = struct { | ||
| 451 | 460 | /// Copy file |
| 452 | 461 | /// JSON: {"src": "/path/from", "dest": "/path/to", "callbackId": "cb1"} |
| 453 | 462 | fn copy(self: *Self, data: []const u8) !void { |
| 454 | const src = json_utils.getString(data, "src") orelse ""; | |
| 455 | const dest = json_utils.getString(data, "dest") orelse ""; | |
| 463 | // `craft.fs.copy(from, to)` sends `from`/`to`; this read `src`/`dest`, | |
| 464 | // so both were empty and the call failed its own path check while the | |
| 465 | // caller's promise resolved. | |
| 466 | const src = json_utils.getString(data, "from") orelse | |
| 467 | json_utils.getString(data, "src") orelse ""; | |
| 468 | const dest = json_utils.getString(data, "to") orelse | |
| 469 | json_utils.getString(data, "dest") orelse ""; | |
| 456 | 470 | const callback_id = json_utils.getString(data, "callbackId") orelse ""; |
| 457 | 471 | |
| 458 | 472 | if (src.len == 0 or dest.len == 0) return BridgeError.MissingData; |
| @@ -473,8 +487,13 @@ pub const FSBridge = struct { | ||
| 473 | 487 | /// Move/rename file |
| 474 | 488 | /// JSON: {"src": "/path/from", "dest": "/path/to", "callbackId": "cb1"} |
| 475 | 489 | fn move(self: *Self, data: []const u8) !void { |
| 476 | const src = json_utils.getString(data, "src") orelse ""; | |
| 477 | const dest = json_utils.getString(data, "dest") orelse ""; | |
| 490 | // `craft.fs.move(from, to)` sends `from`/`to`; this read `src`/`dest`, | |
| 491 | // so both were empty and the call failed its own path check while the | |
| 492 | // caller's promise resolved. | |
| 493 | const src = json_utils.getString(data, "from") orelse | |
| 494 | json_utils.getString(data, "src") orelse ""; | |
| 495 | const dest = json_utils.getString(data, "to") orelse | |
| 496 | json_utils.getString(data, "dest") orelse ""; | |
| 478 | 497 | const callback_id = json_utils.getString(data, "callbackId") orelse ""; |
| 479 | 498 | |
| 480 | 499 | if (src.len == 0 or dest.len == 0) return BridgeError.MissingData; |