Render a file list from the filesystem #24
|
@ -73,7 +73,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="./dist/main.js" type="module"></script>
|
<script src="./main.js" type="module"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,7 +4,7 @@
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "browserify src/main.ts -p [ tsify ] > dist/bundle.js",
|
"build": "browserify src/main.ts -p [ tsify ] > dist/bundle.js && cp index.html styles.css dist",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"watch": "exa index.html styles.css src/* | entr -s 'npm run build'"
|
"watch": "exa index.html styles.css src/* | entr -s 'npm run build'"
|
||||||
},
|
},
|
||||||
|
@ -18,7 +18,6 @@
|
||||||
"@types/lodash": "^4.14.191",
|
"@types/lodash": "^4.14.191",
|
||||||
"babelify": "^10.0.0",
|
"babelify": "^10.0.0",
|
||||||
"browserify": "^17.0.0",
|
"browserify": "^17.0.0",
|
||||||
"live-server": "^1.2.2",
|
|
||||||
"tsify": "^5.0.4",
|
"tsify": "^5.0.4",
|
||||||
"typescript": "^4.9.4",
|
"typescript": "^4.9.4",
|
||||||
"watchify": "^4.0.0"
|
"watchify": "^4.0.0"
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
use flow::Flow;
|
use flow::Flow;
|
||||||
use std::{io::stdin, path::PathBuf, sync::Arc, thread, time::Duration};
|
use std::{
|
||||||
// use warp::Filter;
|
io::stdin,
|
||||||
|
net::{IpAddr, Ipv4Addr, SocketAddr},
|
||||||
|
path::PathBuf,
|
||||||
|
sync::Arc,
|
||||||
|
thread,
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
use warp::{Filter, Reply};
|
||||||
|
|
||||||
use music_player::{core::Core, database::MemoryIndex};
|
use music_player::{core::Core, database::MemoryIndex};
|
||||||
|
|
||||||
|
@ -48,27 +55,61 @@ fn tracks() -> Vec<Track> {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
enum Bundle {
|
||||||
|
Index,
|
||||||
|
App,
|
||||||
|
Styles,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Bundle {
|
||||||
|
fn read(self, root: PathBuf) -> String {
|
||||||
|
let mut path = root;
|
||||||
|
match self {
|
||||||
|
Bundle::Index => path.push(PathBuf::from("index.html")),
|
||||||
|
Bundle::App => path.push(PathBuf::from("bundle.js")),
|
||||||
|
Bundle::Styles => path.push(PathBuf::from("styles.css")),
|
||||||
|
};
|
||||||
|
println!("path: {:?}", path);
|
||||||
|
std::fs::read_to_string(path).expect("to find the file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn main() {
|
pub async fn main() {
|
||||||
/*
|
let dev = std::env::var("DEV")
|
||||||
match Core::new(Arc::new(MemoryIndex::new())) {
|
.ok()
|
||||||
Flow::Ok(core) => {
|
.and_then(|v| v.parse::<bool>().ok())
|
||||||
let mut buf = String::new();
|
.unwrap_or(false);
|
||||||
let _ = stdin().read_line(&mut buf).unwrap();
|
let bundle_root = std::env::var("BUNDLE_ROOT")
|
||||||
core.exit();
|
.map(|b| PathBuf::from(b))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
println!("config: {:?} {:?}", dev, bundle_root);
|
||||||
|
|
||||||
|
let index = warp::path!().and(warp::get()).map({
|
||||||
|
let bundle_root = bundle_root.clone();
|
||||||
|
move || {
|
||||||
|
warp::http::Response::builder()
|
||||||
|
.header("content-type", "text/html")
|
||||||
|
.body(Bundle::Index.read(bundle_root.clone()))
|
||||||
}
|
}
|
||||||
Flow::Err(err) => println!("non-fatal error: {:?}", err),
|
});
|
||||||
Flow::Fatal(err) => println!("fatal error: {:?}", err),
|
let app = warp::path!("bundle.js").and(warp::get()).map({
|
||||||
}
|
let bundle_root = bundle_root.clone();
|
||||||
*/
|
move || {
|
||||||
|
warp::http::Response::builder()
|
||||||
/*
|
.header("content-type", "text/javascript")
|
||||||
let connection = Connection::new_session().expect("to connect to dbus");
|
.body(Bundle::App.read(bundle_root.clone()))
|
||||||
|
}
|
||||||
for player in list_players(connection) {
|
});
|
||||||
println!("player found: {}", player.identity());
|
let styles = warp::path!("styles.css").and(warp::get()).map({
|
||||||
}
|
let bundle_root = bundle_root.clone();
|
||||||
*/
|
move || {
|
||||||
|
warp::http::Response::builder()
|
||||||
|
.header("content-type", "text/css")
|
||||||
|
.body(Bundle::Styles.read(bundle_root.clone()))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
let devices = warp::path!("api" / "v1" / "devices")
|
let devices = warp::path!("api" / "v1" / "devices")
|
||||||
|
@ -105,6 +146,8 @@ pub async fn main() {
|
||||||
.or(tracks_for_artist)
|
.or(tracks_for_artist)
|
||||||
.or(queue)
|
.or(queue)
|
||||||
.or(playing_status);
|
.or(playing_status);
|
||||||
|
*/
|
||||||
|
let routes = index.or(app).or(styles);
|
||||||
let server = warp::serve(routes);
|
let server = warp::serve(routes);
|
||||||
server
|
server
|
||||||
.run(SocketAddr::new(
|
.run(SocketAddr::new(
|
||||||
|
@ -112,5 +155,4 @@ pub async fn main() {
|
||||||
8002,
|
8002,
|
||||||
))
|
))
|
||||||
.await;
|
.await;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue