Compare commits
2 Commits
0fa5fd4d04
...
39adc3fb62
Author | SHA1 | Date |
---|---|---|
Dendy | 39adc3fb62 | |
Dendy | 2c27dc3bf6 |
|
@ -1,2 +1,3 @@
|
||||||
[settings]
|
[settings]
|
||||||
base_directory = "/strg/drw"
|
base_directory = "/strg/drw"
|
||||||
|
bind_address = "127.0.0.1:3012"
|
||||||
|
|
|
@ -10,6 +10,7 @@ pub struct Config {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
pub base_directory: String,
|
pub base_directory: String,
|
||||||
|
pub bind_address: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_config() -> Result<Config, Box<dyn std::error::Error>> {
|
pub fn read_config() -> Result<Config, Box<dyn std::error::Error>> {
|
||||||
|
|
|
@ -15,6 +15,7 @@ pub async fn list_files(
|
||||||
let template = ListTemplate {
|
let template = ListTemplate {
|
||||||
files: files.to_vec(),
|
files: files.to_vec(),
|
||||||
};
|
};
|
||||||
|
|
||||||
HtmlTemplate(template)
|
HtmlTemplate(template)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,11 +23,11 @@ pub async fn rescan_files(
|
||||||
base_path: String,
|
base_path: String,
|
||||||
State(state): State<Arc<RwLock<Vec<utils::FileEntry>>>>,
|
State(state): State<Arc<RwLock<Vec<utils::FileEntry>>>>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
|
let new_files = utils::find_files(&base_path).expect("Error trying to refresh list");
|
||||||
|
|
||||||
let mut files = state.write().unwrap(); // Adquire lock
|
let mut files = state.write().unwrap(); // Adquire lock
|
||||||
|
|
||||||
files.clear();
|
files.clear();
|
||||||
|
files.extend(new_files);
|
||||||
files.extend(utils::find_files(&base_path).expect("Error trying to refresh list"));
|
|
||||||
|
|
||||||
"Files rescanned successfuly"
|
"Files rescanned successfuly"
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,9 @@ async fn main() {
|
||||||
)
|
)
|
||||||
.with_state(files);
|
.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());
|
println!("Listening on {}", listener.local_addr().unwrap());
|
||||||
axum::serve(listener, app).await.unwrap();
|
axum::serve(listener, app).await.unwrap();
|
||||||
|
|
Loading…
Reference in New Issue