File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 11use std:: collections:: HashMap ;
22
3+ use gethostname:: gethostname;
34use rocket:: serde:: json:: Json ;
45
56use 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" ) ]
4348pub 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 {
You can’t perform that action at this time.
0 commit comments