1- //! Uploading the engine infolog to logs.springrts.com , reproducing what the
1+ //! Uploading the engine infolog to a public paste service , reproducing what the
22//! launcher's "Upload Log" button did — without the launcher.
33//!
4- //! The plugin carries no HTTP client, so the POST is delegated to `curl` (the
5- //! same shell-out approach the map compiler uses for its external tools). It
6- //! runs on the IO thread since it blocks on the network, and reports the
7- //! resulting URL — copied to the clipboard — through a toast.
4+ //! The old springrts log host is gone (it now 302s to the homepage), so this
5+ //! posts to paste.rs, which takes a raw body and replies with the URL as plain
6+ //! text. The plugin carries no HTTP client, so the POST is delegated to `curl`
7+ //! (the same shell-out approach the map compiler uses). It runs on the IO thread
8+ //! since it blocks on the network, and reports the resulting URL — copied to the
9+ //! clipboard — through a toast.
810
911use std:: io:: Write ;
1012use std:: path:: PathBuf ;
1113use std:: process:: { Command as OsCommand , Stdio } ;
1214
1315use serde:: Deserialize ;
14- use serde_json:: json;
1516
1617use crate :: sbc:: command_system:: command:: Command ;
1718use crate :: sbc:: command_system:: context:: Context ;
@@ -21,7 +22,7 @@ use crate::sbc::io::io_api::{IoJob, IoOutcome};
2122use crate :: sbc:: notifications:: NotificationManager ;
2223use crate :: sbc:: sbc:: SBC ;
2324
24- const UPLOAD_URL : & str = "http ://logs.springrts.com/logfiles/ " ;
25+ const UPLOAD_URL : & str = "https ://paste.rs " ;
2526
2627/// Queues the log upload as background IO. Not serialized from Lua; constructed
2728/// directly by the status bar.
@@ -89,23 +90,16 @@ impl IoOutcome for UploadLogOutcome {
8990}
9091
9192fn upload ( log_path : & PathBuf ) -> Result < String , String > {
92- let text = std:: fs:: read_to_string ( log_path)
93+ let text = std:: fs:: read ( log_path)
9394 . map_err ( |err| format ! ( "cannot read {}: {err}" , log_path. display( ) ) ) ?;
94- let body = json ! ( {
95- "name" : "SpringBoard log" ,
96- "text" : text,
97- "tags" : [ "springboard" , "native" ] ,
98- } )
99- . to_string ( ) ;
10095
10196 let mut child = OsCommand :: new ( "curl" )
10297 . args ( [
10398 "--silent" ,
10499 "--show-error" ,
100+ "--location" ,
105101 "--max-time" ,
106102 "30" ,
107- "-H" ,
108- "Content-Type: application/json" ,
109103 "--data-binary" ,
110104 "@-" ,
111105 UPLOAD_URL ,
@@ -120,7 +114,7 @@ fn upload(log_path: &PathBuf) -> Result<String, String> {
120114 . stdin
121115 . take ( )
122116 . ok_or ( "curl stdin unavailable" ) ?
123- . write_all ( body . as_bytes ( ) )
117+ . write_all ( & text )
124118 . map_err ( |err| format ! ( "writing to curl: {err}" ) ) ?;
125119
126120 let output = child
@@ -134,16 +128,15 @@ fn upload(log_path: &PathBuf) -> Result<String, String> {
134128 ) ) ;
135129 }
136130
137- let response = String :: from_utf8_lossy ( & output. stdout ) ;
138- let parsed: UploadResponse =
139- serde_json:: from_str ( response. trim ( ) ) . map_err ( |err| format ! ( "unexpected reply: {err}" ) ) ?;
140- // The service returns http; the launcher rewrites it to https for sharing.
141- Ok ( parsed. url . replacen ( "http://" , "https://" , 1 ) )
142- }
143-
144- #[ derive( Deserialize ) ]
145- struct UploadResponse {
146- url : String ,
131+ // paste.rs replies with the URL as plain text (or an error message on
132+ // failure); accept only a real URL.
133+ let reply = String :: from_utf8_lossy ( & output. stdout ) ;
134+ let url = reply. trim ( ) ;
135+ if url. starts_with ( "https://" ) || url. starts_with ( "http://" ) {
136+ Ok ( url. to_string ( ) )
137+ } else {
138+ Err ( format ! ( "unexpected reply: {url}" ) )
139+ }
147140}
148141
149142register_command ! ( UploadLogCommand , "UploadLogCommand" ) ;
0 commit comments