1use std::{sync::LazyLock, time::SystemTime};
3
4use serde::{Deserialize, Serialize};
5
6#[cfg(not(target_arch = "wasm32"))]
7mod server;
8#[cfg(not(target_arch = "wasm32"))]
9pub use server::surver_main;
10
11pub const HTTP_SERVER_KEY: &str = "Server";
12pub const HTTP_SERVER_VALUE_SURFER: &str = "Surfer";
13pub const X_WELLEN_VERSION: &str = "x-wellen-version";
14pub const X_SURFER_VERSION: &str = "x-surfer-version";
15pub const SURFER_VERSION: &str = env!("CARGO_PKG_VERSION");
16pub const WELLEN_VERSION: &str = wellen::VERSION;
17
18pub const WELLEN_SURFER_DEFAULT_OPTIONS: wellen::LoadOptions = wellen::LoadOptions {
19 multi_thread: true,
20 remove_scopes_with_empty_name: true,
21};
22
23#[derive(Debug, Deserialize)]
24pub struct SurverConfig {
25 pub bind_address: String,
27 pub port: u16,
29}
30
31#[derive(Debug, Serialize, Deserialize)]
32pub struct SurverStatus {
33 pub wellen_version: String,
34 pub surfer_version: String,
35 pub file_infos: Vec<SurverFileInfo>,
36}
37
38#[derive(Debug, Serialize, Deserialize, Clone)]
39pub struct SurverFileInfo {
40 pub bytes: u64,
41 pub bytes_loaded: u64,
42 pub filename: String,
43 pub format: wellen::FileFormat,
44 pub reloading: bool,
45 pub last_load_ok: bool,
46 pub last_modification_time: Option<SystemTime>,
47}
48
49impl SurverFileInfo {
50 pub fn modification_time_string(&self) -> String {
51 modification_time_string(self.last_modification_time)
52 }
53}
54
55pub static BINCODE_OPTIONS: LazyLock<bincode::DefaultOptions> =
56 LazyLock::new(bincode::DefaultOptions::new);
57
58pub(crate) fn modification_time_string(mtime: Option<SystemTime>) -> String {
59 if let Some(mtime) = mtime {
60 let dur = mtime
61 .duration_since(std::time::UNIX_EPOCH)
62 .unwrap_or_default();
63 return chrono::DateTime::<chrono::Utc>::from_timestamp(
64 dur.as_secs() as i64,
65 dur.subsec_nanos(),
66 )
67 .map_or_else(
68 || "Incorrect timestamp".to_string(),
69 |dt| dt.format("%Y-%m-%d %H:%M:%S UTC").to_string(),
70 );
71 }
72 "unknown".to_string()
73}