Commit 857c2a3 1 parent d9115ea commit 857c2a3 Copy full SHA for 857c2a3
File tree 1 file changed +13
-0
lines changed
1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 1
1
use std:: collections:: HashMap ;
2
2
3
+ use gethostname:: gethostname;
3
4
use rocket:: serde:: json:: Json ;
4
5
5
6
use chrono:: DateTime ;
@@ -39,6 +40,10 @@ pub fn bucket_get(
39
40
}
40
41
}
41
42
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).
42
47
#[ post( "/<bucket_id>" , data = "<message>" , format = "application/json" ) ]
43
48
pub fn bucket_new (
44
49
bucket_id : String ,
@@ -49,6 +54,14 @@ pub fn bucket_new(
49
54
if bucket. id != bucket_id {
50
55
bucket. id = bucket_id;
51
56
}
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
+ }
52
65
let datastore = endpoints_get_lock ! ( state. datastore) ;
53
66
let ret = datastore. create_bucket ( & bucket) ;
54
67
match ret {
You can’t perform that action at this time.
0 commit comments