mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-08-08 10:12:50 +00:00
Finished first version of Chrome extension to cast to FCast. Added support for WebSocket to terminal client. Added global support for setting playback speed. Added support for casting local file using terminal client. Added global support for playback error messages. Fixed crash caused by failing to unregister MDNS. Fixed issue where subtitles would always show for HLS. Added support for fractional seconds globally. Layout fixes to desktop casting client. Added footer telling user they can close the window.
This commit is contained in:
parent
fd9a63dac0
commit
18b61d549c
26 changed files with 1116 additions and 193 deletions
36
clients/terminal/src/file_server.rs
Normal file
36
clients/terminal/src/file_server.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
struct FileServer {
|
||||
base_url: String,
|
||||
base_path: String,
|
||||
}
|
||||
|
||||
impl FileServer {
|
||||
fn new(base_url: String, base_path: String) -> Self {
|
||||
FileServer { base_url, base_path }
|
||||
}
|
||||
|
||||
async fn serve(&self) {
|
||||
let file_server = warp::fs::dir(&self.base_path);
|
||||
warp::serve(file_server).run(([127, 0, 0, 1], 3030)).await;
|
||||
}
|
||||
|
||||
fn get_url(&self, file_name: &str) -> String {
|
||||
format!("{}/{}", self.base_url, file_name)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn host_file_and_get_url(file_path: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let file_name = Path::new(file_path).file_name().ok_or("Invalid file path")?.to_str().ok_or("Invalid file name")?;
|
||||
let file_server = FileServer::new("http://127.0.0.1:3030".to_string(), "path/to/hosted/files".to_string());
|
||||
|
||||
// Copy the file to the hosting directory
|
||||
let destination = Path::new(&file_server.base_path).join(file_name);
|
||||
tokio::fs::copy(file_path, &destination).await?;
|
||||
|
||||
// Start the server if not already running
|
||||
// This part needs synchronization in a real-world scenario
|
||||
tokio::spawn(async move {
|
||||
file_server.serve().await;
|
||||
});
|
||||
|
||||
Ok(file_server.get_url(file_name))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue