diff --git a/README.md b/README.md index 67c7d61..65c33c8 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,11 @@ Devolve un link para descargalo. ## Execución ``` -UPLOADS="/tmp/uploads/" PORT=4000 cargo run +UPLOADS="/tmp/uploads/" BASE_URL="http://127.0.0.1" PORT=4000 cargo run ``` -As variables de entorno UPLOADS e PORT son opcionais tendo como valores por defecto: +As variables de entorno UPLOADS, BASE_URL e PORT son opcionais tendo como valores por defecto: - UPLOADS = "uploads/" +- BASE_URL = "http://127.0.0.1" - PORT = 3000 ## Funcionamento diff --git a/src/lib.rs b/src/lib.rs index c82a04a..0309527 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,3 +26,14 @@ pub fn env_listen_port() -> u16 { None => 3000, } } + +// le a variable de entorno BASE_URL para configurar o porto de escoita +// por defecto: http://localhost:3000 +pub fn env_base_url() -> String { + let port = env_listen_port(); + + match env::var_os("BASE_URL") { + Some(val) => format!("{}:{}", val.into_string().unwrap(), port), + None => format!("{}:{}", "http://localhost", port), + } +} diff --git a/src/vistas/root.rs b/src/vistas/root.rs index 9731009..c942dd4 100644 --- a/src/vistas/root.rs +++ b/src/vistas/root.rs @@ -1,16 +1,18 @@ use axum::response::{Html, IntoResponse, Response}; +use crate::lib::env_base_url; // basic handler that responds with a static string pub async fn basic() -> Response { - Html( + let url = env_base_url(); + let html = format!( "
 SH4R.IN
 =======
 
 HTTP POST files here:
-curl -F'file=@yourfile.png' https://sh4r.in
+curl -F'file=@yourfile.png' {}
 You can also POST remote URLs:
-curl -F'url=http://example.com/image.jpg' https://sh4r.in
+curl -F'url=http://example.com/image.jpg' {}
 
 File URLs are valid for aproximately 5 days.
 
@@ -34,11 +36,11 @@ and the originating IP address blocked from further uploads.
 UPLOAD DIRECTLY
 ---------------
 
-
+
", - ) - .into_response() + url, url, url); + Html(html).into_response() } diff --git a/src/vistas/upload.rs b/src/vistas/upload.rs index a5f1b30..06ff85f 100644 --- a/src/vistas/upload.rs +++ b/src/vistas/upload.rs @@ -1,4 +1,4 @@ -use crate::lib::{randstr, env_uploads_dir}; +use crate::lib::{randstr, env_uploads_dir, env_base_url}; use axum::{ extract::Multipart, response::{IntoResponse, Response}, @@ -28,7 +28,7 @@ pub async fn upload(mut multipart: Multipart) -> Response { let mut file = File::create(dest).await.expect("error creando arquivo"); file.write_all(&data).await.expect("error gardando contido"); - link = format!("https://sh4r.in/f/{}", fillo); + link = format!("{}/f/{}", env_base_url(), fillo); } link.into_response()