Render a file list from the filesystem #24

Merged
savanni merged 9 commits from track-list into main 2023-02-26 03:17:01 +00:00
4 changed files with 65 additions and 3954 deletions
Showing only changes of commit 99ba020b7c - Show all commits

View File

@ -73,7 +73,7 @@
</div>
</div>
<script src="./dist/main.js" type="module"></script>
<script src="./main.js" type="module"></script>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
"description": "",
"main": "main.js",
"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",
"watch": "exa index.html styles.css src/* | entr -s 'npm run build'"
},
@ -18,7 +18,6 @@
"@types/lodash": "^4.14.191",
"babelify": "^10.0.0",
"browserify": "^17.0.0",
"live-server": "^1.2.2",
"tsify": "^5.0.4",
"typescript": "^4.9.4",
"watchify": "^4.0.0"

View File

@ -1,6 +1,13 @@
use flow::Flow;
use std::{io::stdin, path::PathBuf, sync::Arc, thread, time::Duration};
// use warp::Filter;
use std::{
io::stdin,
net::{IpAddr, Ipv4Addr, SocketAddr},
path::PathBuf,
sync::Arc,
thread,
time::Duration,
};
use warp::{Filter, Reply};
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]
pub async fn main() {
/*
match Core::new(Arc::new(MemoryIndex::new())) {
Flow::Ok(core) => {
let mut buf = String::new();
let _ = stdin().read_line(&mut buf).unwrap();
core.exit();
let dev = std::env::var("DEV")
.ok()
.and_then(|v| v.parse::<bool>().ok())
.unwrap_or(false);
let bundle_root = std::env::var("BUNDLE_ROOT")
.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 connection = Connection::new_session().expect("to connect to dbus");
for player in list_players(connection) {
println!("player found: {}", player.identity());
}
*/
});
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")
.body(Bundle::App.read(bundle_root.clone()))
}
});
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")
@ -105,6 +146,8 @@ pub async fn main() {
.or(tracks_for_artist)
.or(queue)
.or(playing_status);
*/
let routes = index.or(app).or(styles);
let server = warp::serve(routes);
server
.run(SocketAddr::new(
@ -112,5 +155,4 @@ pub async fn main() {
8002,
))
.await;
*/
}