Skip to content

Commit

Permalink
feat: added special hostname !local (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Jul 7, 2023
1 parent d9115ea commit 857c2a3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions aw-server/src/endpoints/bucket.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;

use gethostname::gethostname;
use rocket::serde::json::Json;

use chrono::DateTime;
Expand Down Expand Up @@ -39,6 +40,10 @@ pub fn bucket_get(
}
}

/// Create a new bucket
///
/// If hostname is "!local", the hostname and device_id will be set from the server info.
/// This is useful for watchers which are known/assumed to run locally but might not know their hostname (like aw-watcher-web).
#[post("/<bucket_id>", data = "<message>", format = "application/json")]
pub fn bucket_new(
bucket_id: String,
Expand All @@ -49,6 +54,14 @@ pub fn bucket_new(
if bucket.id != bucket_id {
bucket.id = bucket_id;
}
if bucket.hostname == "!local" {
bucket.hostname = gethostname()
.into_string()
.unwrap_or_else(|_| "unknown".to_string());
bucket
.data
.insert("device_id".to_string(), state.device_id.clone().into());
}
let datastore = endpoints_get_lock!(state.datastore);
let ret = datastore.create_bucket(&bucket);
match ret {
Expand Down

0 comments on commit 857c2a3

Please sign in to comment.