11use crate :: cli:: { GenerateArgs , PluginArgs , PluginCommands , PluginPathArg } ;
22use crate :: ui;
3+ use crate :: utils:: http;
34use keyring:: Entry ;
45use rand:: Rng ;
56use rolldown:: {
67 Bundler , BundlerOptions , ExperimentalOptions , InputItem , LogLevel , OutputFormat , Platform ,
78 WatchOption , Watcher ,
89} ;
910use serde:: Deserialize ;
10- use serde_json:: Value ;
1111use std:: collections:: HashSet ;
1212use std:: fs;
1313use std:: io:: { self , IsTerminal , Read , Write } ;
@@ -186,10 +186,8 @@ async fn publish(args: PluginPathArg) -> CommandResult {
186186
187187 ui:: info ( "Uploading plugin" ) ;
188188 let url = format ! ( "{}/api/v1/plugins/publish" , environment. api_base_url( ) ) ;
189- let response = reqwest :: Client :: new ( )
189+ let response = http :: build_client ( Some ( & token ) ) ?
190190 . post ( url)
191- . header ( "X-Yaak-Session" , token)
192- . header ( reqwest:: header:: USER_AGENT , user_agent ( ) )
193191 . header ( reqwest:: header:: CONTENT_TYPE , "application/zip" )
194192 . body ( archive)
195193 . send ( )
@@ -201,7 +199,7 @@ async fn publish(args: PluginPathArg) -> CommandResult {
201199 response. text ( ) . await . map_err ( |e| format ! ( "Failed reading publish response body: {e}" ) ) ?;
202200
203201 if !status. is_success ( ) {
204- return Err ( parse_api_error ( status. as_u16 ( ) , & body) ) ;
202+ return Err ( http :: parse_api_error ( status. as_u16 ( ) , & body) ) ;
205203 }
206204
207205 let published: PublishResponse = serde_json:: from_str ( & body)
@@ -389,32 +387,6 @@ fn get_auth_token(environment: Environment) -> CommandResult<Option<String>> {
389387 }
390388}
391389
392- fn parse_api_error ( status : u16 , body : & str ) -> String {
393- if let Ok ( value) = serde_json:: from_str :: < Value > ( body) {
394- if let Some ( message) = value. get ( "message" ) . and_then ( Value :: as_str) {
395- return message. to_string ( ) ;
396- }
397- if let Some ( error) = value. get ( "error" ) . and_then ( Value :: as_str) {
398- return error. to_string ( ) ;
399- }
400- }
401-
402- format ! ( "API error {status}: {body}" )
403- }
404-
405- fn user_agent ( ) -> String {
406- format ! ( "YaakCli/{} ({})" , env!( "CARGO_PKG_VERSION" ) , ua_platform( ) )
407- }
408-
409- fn ua_platform ( ) -> & ' static str {
410- match std:: env:: consts:: OS {
411- "windows" => "Win" ,
412- "darwin" => "Mac" ,
413- "linux" => "Linux" ,
414- _ => "Unknown" ,
415- }
416- }
417-
418390fn random_name ( ) -> String {
419391 const ADJECTIVES : & [ & str ] = & [
420392 "young" , "youthful" , "yellow" , "yielding" , "yappy" , "yawning" , "yummy" , "yucky" , "yearly" ,
0 commit comments