Skip to content

Commit

Permalink
Refactor rice packing and update API request to use JSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro-balades committed Dec 27, 2024
1 parent 4482476 commit f2423ed
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/browser/base/zen-components/ZenRices.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
}

async packRice() {
return this._collector.packRice();
return await this._collector.packRice();
}

get shareDialog() {
Expand Down Expand Up @@ -280,18 +280,18 @@
}

async _sendRice({ name, author, rice }) {
// Encode the rice as base64 and send it as request body, change user agent to "ZenBrowser" and send author info in the headers
const base64 = btoa(JSON.stringify(rice));
const headers = new Headers();
headers.append("X-Zen-Rice-Name", name);
headers.append("X-Zen-Rice-Author", author);
headers.append("User-Agent", this.userAgent);
headers.append("Content-Type", "application/json");
headers.append("Accept", "application/json");
let response;
try {
response = await fetch(`${ZEN_RICE_API}/rices`, {
method: "POST",
headers,
body: base64,
body: JSON.stringify(rice),
});
} catch (e) {
this.showErrorMessage("An error occurred while sharing your rice. Please try again later.");
Expand Down

0 comments on commit f2423ed

Please sign in to comment.