Compare commits

...

2 Commits

Author SHA1 Message Date
Dendy 39adc3fb62 feat: Make the bind address configurable 2024-09-25 13:14:14 +02:00
Dendy 2c27dc3bf6 fix: Get all necessary info before locking 2024-09-25 13:12:03 +02:00
4 changed files with 9 additions and 4 deletions

View File

@ -1,2 +1,3 @@
[settings]
base_directory = "/strg/drw"
bind_address = "127.0.0.1:3012"

View File

@ -10,6 +10,7 @@ pub struct Config {
#[derive(Deserialize)]
pub struct Settings {
pub base_directory: String,
pub bind_address: String,
}
pub fn read_config() -> Result<Config, Box<dyn std::error::Error>> {

View File

@ -15,6 +15,7 @@ pub async fn list_files(
let template = ListTemplate {
files: files.to_vec(),
};
HtmlTemplate(template)
}
@ -22,11 +23,11 @@ pub async fn rescan_files(
base_path: String,
State(state): State<Arc<RwLock<Vec<utils::FileEntry>>>>,
) -> impl IntoResponse {
let new_files = utils::find_files(&base_path).expect("Error trying to refresh list");
let mut files = state.write().unwrap(); // Adquire lock
files.clear();
files.extend(utils::find_files(&base_path).expect("Error trying to refresh list"));
files.extend(new_files);
"Files rescanned successfuly"
}

View File

@ -30,7 +30,9 @@ async fn main() {
)
.with_state(files);
let listener = TcpListener::bind("127.0.0.1:3004").await.unwrap();
let listener = TcpListener::bind(config.settings.bind_address)
.await
.unwrap();
println!("Listening on {}", listener.local_addr().unwrap());
axum::serve(listener, app).await.unwrap();