Skip to content

Commit 857c2a3

Browse files
authored
feat: added special hostname !local (#399)
1 parent d9115ea commit 857c2a3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

aw-server/src/endpoints/bucket.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::HashMap;
22

3+
use gethostname::gethostname;
34
use rocket::serde::json::Json;
45

56
use chrono::DateTime;
@@ -39,6 +40,10 @@ pub fn bucket_get(
3940
}
4041
}
4142

43+
/// Create a new bucket
44+
///
45+
/// If hostname is "!local", the hostname and device_id will be set from the server info.
46+
/// This is useful for watchers which are known/assumed to run locally but might not know their hostname (like aw-watcher-web).
4247
#[post("/<bucket_id>", data = "<message>", format = "application/json")]
4348
pub fn bucket_new(
4449
bucket_id: String,
@@ -49,6 +54,14 @@ pub fn bucket_new(
4954
if bucket.id != bucket_id {
5055
bucket.id = bucket_id;
5156
}
57+
if bucket.hostname == "!local" {
58+
bucket.hostname = gethostname()
59+
.into_string()
60+
.unwrap_or_else(|_| "unknown".to_string());
61+
bucket
62+
.data
63+
.insert("device_id".to_string(), state.device_id.clone().into());
64+
}
5265
let datastore = endpoints_get_lock!(state.datastore);
5366
let ret = datastore.create_bucket(&bucket);
5467
match ret {

0 commit comments

Comments
 (0)