Skip to content

Commit

Permalink
Update last_registration for running connections
Browse files Browse the repository at this point in the history
  • Loading branch information
p1gp1g committed Sep 10, 2024
1 parent e193702 commit 3775b18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ CREATE TABLE IF NOT EXISTS connections(
Ok(())
}

pub fn update_last_registration(&self, uuid: &str) -> Result<()> {
let now = OptTime::from(SystemTime::now());
self.db.lock().unwrap().execute(
"UPDATE connections
SET last_registration = ?
WHERE uuid = ?;",
[&u64::from(&now).to_string(), uuid],
)?;
Ok(())
}

pub fn list(&self) -> Result<Vec<Connection>> {
self.db
.lock()
Expand Down
3 changes: 1 addition & 2 deletions src/server/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ async fn register(co_data: Json<ConnectionData>) -> Json<Response> {
}
}
RegistrationStatus::Running => {
//TODO: Update last registration for ::Running

// If the connection is "Running" then the device creds still exists,
// if the user register on another server or delete the linked device,
// then the connection ends with a 403 Forbidden
// If the connection is for an invalid uuid or an error occured : we
// have nothing to do, except if the request ask for a ping
DB.update_last_registration(&co_data.uuid).unwrap();
if co_data.ping.unwrap_or(false) {
ping_endpoint(&co_data).await;
}
Expand Down

0 comments on commit 3775b18

Please sign in to comment.