Skip to content

Commit 18b72da

Browse files
jjlindani-garcia
authored andcommitted
Change text/plain API responses to application/json
Recent versions of the Bitwarden clients (see bitwarden/clients#3574) won't parse non-JSON responses. The most noticeable consequence is that `/api/accounts/revision-date` responses won't be parsed, leading to `/api/sync` always being called, even when it's not necessary.
1 parent 6be26f0 commit 18b72da

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/api/core/accounts.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,9 @@ async fn delete_account(data: JsonUpcase<PasswordData>, headers: Headers, mut co
660660
}
661661

662662
#[get("/accounts/revision-date")]
663-
fn revision_date(headers: Headers) -> String {
663+
fn revision_date(headers: Headers) -> JsonResult {
664664
let revision_date = headers.user.updated_at.timestamp_millis();
665-
revision_date.to_string()
665+
Ok(Json(json!(revision_date)))
666666
}
667667

668668
#[derive(Deserialize)]
@@ -792,14 +792,11 @@ async fn rotate_api_key(data: JsonUpcase<SecretVerificationRequest>, headers: He
792792
}
793793

794794
#[get("/devices/knowndevice/<email>/<uuid>")]
795-
async fn get_known_device(email: String, uuid: String, mut conn: DbConn) -> String {
795+
async fn get_known_device(email: String, uuid: String, mut conn: DbConn) -> JsonResult {
796796
// This endpoint doesn't have auth header
797+
let mut result = false;
797798
if let Some(user) = User::find_by_mail(&email, &mut conn).await {
798-
match Device::find_by_uuid_and_user(&uuid, &user.uuid, &mut conn).await {
799-
Some(_) => String::from("true"),
800-
_ => String::from("false"),
801-
}
802-
} else {
803-
String::from("false")
799+
result = Device::find_by_uuid_and_user(&uuid, &user.uuid, &mut conn).await.is_some();
804800
}
801+
Ok(Json(json!(result)))
805802
}

0 commit comments

Comments
 (0)