Skip to content

Commit

Permalink
Change text/plain API responses to application/json
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jjlin authored and dani-garcia committed Jan 9, 2023
1 parent 6be26f0 commit 18b72da
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/api/core/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,9 @@ async fn delete_account(data: JsonUpcase<PasswordData>, headers: Headers, mut co
}

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

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

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

0 comments on commit 18b72da

Please sign in to comment.