fix: add revision date endpoint

This commit is contained in:
qaz741wsd856 2025-11-28 14:02:47 +08:00
parent 1d45beebe2
commit ce0b1a39f8
2 changed files with 27 additions and 0 deletions

View file

@ -9,6 +9,7 @@ use crate::{
db,
error::AppError,
models::user::{PreloginResponse, RegisterRequest, User},
auth::Claims,
};
#[worker::send]
@ -102,3 +103,27 @@ pub async fn register(
pub async fn send_verification_email() -> String {
"fixed-token-to-mock".to_string()
}
#[worker::send]
pub async fn revision_date(
claims: Claims,
State(env): State<Arc<Env>>,
) -> Result<Json<i64>, AppError> {
let db = db::get_db(&env)? ;
// get the user's updated_at timestamp
let updated_at: Option<String> = db
.prepare("SELECT updated_at FROM users WHERE id = ?1")
.bind(&[claims.sub. into()])?
.first(Some("updated_at"))
.await
.map_err(|_| AppError::Database)?;
// convert the timestamp to a millisecond-level Unix timestamp
let revision_date = updated_at
.and_then(|ts| chrono::DateTime::parse_from_rfc3339(&ts). ok())
. map(|dt| dt.timestamp_millis())
.unwrap_or_else(|| chrono::Utc::now().timestamp_millis());
Ok(Json(revision_date))
}

View file

@ -24,6 +24,8 @@ pub fn api_router(env: Env) -> Router {
)
// Main data sync route
.route("/api/sync", get(sync::get_sync_data))
// For on-demand sync checks
.route("/api/accounts/revision-date", get(accounts::revision_date))
// Ciphers CRUD
.route("/api/ciphers", post(ciphers::create_cipher_simple))
.route("/api/ciphers/create", post(ciphers::create_cipher))