From f2423edb66815f9f754a265e2e022b88523e44be Mon Sep 17 00:00:00 2001 From: "mr. M" Date: Fri, 27 Dec 2024 16:24:03 +0100 Subject: [PATCH] Refactor rice packing and update API request to use JSON format --- src/browser/base/zen-components/ZenRices.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/browser/base/zen-components/ZenRices.mjs b/src/browser/base/zen-components/ZenRices.mjs index bf31eef68..50e81d58c 100644 --- a/src/browser/base/zen-components/ZenRices.mjs +++ b/src/browser/base/zen-components/ZenRices.mjs @@ -128,7 +128,7 @@ } async packRice() { - return this._collector.packRice(); + return await this._collector.packRice(); } get shareDialog() { @@ -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.");