Files
tuneparty_pre1_server/src/main.rs
skybldev 48f548be6d feat: add basic HTTP, websocket functionality
- add ntex and serde as requirements
- add HTTP server with index/ and ws/ endpoints
- add websocket types and systems, basic Ping and GetTracks endpoints
- add serialize/deserialize support to models::Tracks
- add handle and get_tracks method to library
- clean up types.rs
2026-10-26 02:09:19 -04:00

56 lines
1.4 KiB
Rust

use std::{
fs::metadata,
path::{Path, PathBuf},
string,
};
use diesel::prelude::*;
use dotenvy::dotenv;
use std::env;
mod library;
mod models;
mod net;
mod schema;
mod types;
use library::{Handle, Importer, Library};
fn open_db_file() -> SqliteConnection {
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL missing");
SqliteConnection::establish(&database_url)
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
}
fn open_db_in_memory() -> SqliteConnection {
use diesel_migrations::{EmbeddedMigrations, MigrationHarness, embed_migrations};
const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
let mut conn = SqliteConnection::establish(":memory:")
.unwrap_or_else(|_| panic!("Error starting in-memory database"));
conn.run_pending_migrations(MIGRATIONS)
.unwrap_or_else(|e| panic!("Error applying in-memory migrations: {}", e));
conn
}
fn main() {
println!("Hello, world!");
dotenv().ok();
let mut library_instance = Library::new(open_db_in_memory());
let import_path = env::var("IMPORT_PATH").expect("IMPORT_PATH not set!");
Importer::import_scan(&mut library_instance, Path::new(&import_path))
.expect("Error importing files");
library_instance.print().expect("Error printing library");
let library_handle = Handle::new(library_instance);
net::http::start(library_handle).expect("HTTP server failed to start");
}