1- use std:: sync:: Arc ;
1+ use std:: { fmt :: Display , sync:: Arc } ;
22
33use ohkami:: {
44 IntoResponse , Ohkami , Query , Route ,
@@ -7,9 +7,11 @@ use ohkami::{
77 openapi:: { self , Schema } ,
88 serde:: Deserialize ,
99} ;
10+ use serde:: Serialize ;
11+ use tracing:: instrument;
1012
1113use crate :: {
12- app:: { AppState , lock:: lock_handler, logger:: LogRequest , png:: Png } ,
14+ app:: { AppState , cache :: cache_handler , lock:: lock_handler, logger:: LogRequest , png:: Png } ,
1315 error:: Error ,
1416} ;
1517
@@ -20,26 +22,40 @@ pub fn skin_router() -> Ohkami {
2022 openapi:: Tag ( "skin" ) ,
2123 "/" . GET ( skin_handler) ,
2224 "/store" . GET ( lock_handler) ,
25+ "/cache" . GET ( cache_handler) ,
2326 ) )
2427}
2528
26- #[ derive( Debug , Clone , Copy , Deserialize , Schema , Hash , PartialEq , Eq ) ]
29+ #[ derive( Debug , Clone , Deserialize , Schema , Hash , PartialEq , Eq , Serialize ) ]
2730/// Params for expose Tee
28- pub struct SkinQuery < ' req > {
29- pub name : & ' req str ,
31+ pub struct SkinQuery {
32+ pub name : String ,
3033 pub body : Option < u32 > ,
3134 pub feet : Option < u32 > ,
3235}
3336
37+ impl Display for SkinQuery {
38+ fn fmt (
39+ & self ,
40+ f : & mut std:: fmt:: Formatter < ' _ > ,
41+ ) -> std:: fmt:: Result {
42+ f. debug_struct ( "SkinQuery" )
43+ . field ( "name" , & self . name )
44+ . field ( "body" , & self . body )
45+ . field ( "feet" , & self . feet )
46+ . finish ( )
47+ }
48+ }
49+
3450#[ inline( always) ]
51+ #[ instrument( skip( state) ) ]
3552/// Represent GET method to return a builded skin by query
3653async fn skin_handler < ' a > (
37- Context ( state) : Context < ' a , Arc < AppState < ' a > > > ,
38- // Context(cache): Context<'a, Cache<'a>>,
39- Query ( query) : Query < SkinQuery < ' a > > ,
40- ) -> Result < impl IntoResponse + ' a , Error > {
41- Ok ( Created ( Png ( match state. cache . get ( query) . await {
42- Ok ( Some ( e) ) => e,
54+ Context ( state) : Context < ' a , Arc < AppState > > ,
55+ Query ( query) : Query < SkinQuery > ,
56+ ) -> Result < impl IntoResponse , Error > {
57+ Ok ( Created ( Png ( match state. cache . get ( & query) . await {
58+ Ok ( Some ( e) ) => e. to_vec ( ) ,
4359 _ => state. lock . get ( state. cache . clone ( ) , query) . await ?,
4460 } ) ) )
4561}
0 commit comments