Compare commits

...

3 commits

Author SHA1 Message Date
80bca69e5e cargo fmt 2025-09-25 01:06:55 -04:00
cecb0e3db3 updates 2025-09-25 01:06:43 -04:00
2d580d2b78 flake update 2025-09-25 00:50:30 -04:00
7 changed files with 988 additions and 808 deletions

1689
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -15,14 +15,14 @@ actix-web-actors = "4.1.0"
argon2 = "0.4.1"
askama = "0.11.1"
askama_actix = "0.13"
base64 = "0.13"
base64 = "0.22"
bytes = "1.1.0"
bytesize = "1.1.0"
bytesize = "2"
crc32fast = "1.3.2"
dotenvy = "0.15"
env_logger = "0.11.3"
futures-core = "0.3"
inotify = "0.10"
inotify = "0.11"
jsondb = "0.4.0"
libc = "0.2"
log = "0.4"
@ -34,8 +34,8 @@ rand = "0.8.5"
sanitise-file-name = "1.0.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_with = { version = "2", features = ["time_0_3"] }
thiserror = "1"
serde_with = { version = "3", features = ["time_0_3"] }
thiserror = "2"
time = "0.3.9"
tokio = { version = "1.17.0", features = ["full"] }
unicode-normalization = "0.1.19"

24
flake.lock generated
View file

@ -6,11 +6,11 @@
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1754290399,
"narHash": "sha256-KwYm1/FeLqP9uE4Sbw+j2nI2/ErNbc9Mn+LPcrEOpX0=",
"lastModified": 1758695884,
"narHash": "sha256-rnHjtBRkcwRkrUZxg0RqN1qWTG+QC/gj4vn9uzEkBww=",
"owner": "nix-community",
"repo": "fenix",
"rev": "f53ddf7518d85d59b58df6e9955b25b0ac25f569",
"rev": "9cdb79384d02234fb2868eba6c7d390253ef6f83",
"type": "github"
},
"original": {
@ -21,11 +21,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1753939845,
"narHash": "sha256-K2ViRJfdVGE8tpJejs8Qpvvejks1+A4GQej/lBk5y7I=",
"lastModified": 1758427187,
"narHash": "sha256-pHpxZ/IyCwoTQPtFIAG2QaxuSm8jWzrzBGjwQZIttJc=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "94def634a20494ee057c76998843c015909d6311",
"rev": "554be6495561ff07b6c724047bdd7e0716aa7b46",
"type": "github"
},
"original": {
@ -37,11 +37,11 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1754214453,
"narHash": "sha256-Q/I2xJn/j1wpkGhWkQnm20nShYnG7TI99foDBpXm1SY=",
"lastModified": 1758427187,
"narHash": "sha256-pHpxZ/IyCwoTQPtFIAG2QaxuSm8jWzrzBGjwQZIttJc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5b09dc45f24cf32316283e62aec81ffee3c3e376",
"rev": "554be6495561ff07b6c724047bdd7e0716aa7b46",
"type": "github"
},
"original": {
@ -61,11 +61,11 @@
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1754218780,
"narHash": "sha256-M+bLCsYRYA7iudlZkeOf+Azm/1TUvihIq51OKia6KJ8=",
"lastModified": 1758620797,
"narHash": "sha256-Ly4rHgrixFMBnkbMursVt74mxnntnE6yVdF5QellJ+A=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "8d75311400a108d7ffe17dc9c38182c566952e6e",
"rev": "905641f3520230ad6ef421bcf5da9c6b49f2479b",
"type": "github"
},
"original": {

View file

@ -290,12 +290,13 @@ pub(crate) fn new_live_reader(
file: File,
storage_path: PathBuf,
) -> impl Stream<Item = Result<Bytes, Error>> {
let mut inotify = Inotify::init().expect("failed to init inotify");
let inotify = Inotify::init().expect("failed to init inotify");
inotify
.add_watch(storage_path, WatchMask::MODIFY | WatchMask::CLOSE_WRITE)
.watches()
.add(storage_path, WatchMask::MODIFY | WatchMask::CLOSE_WRITE)
.expect("Failed to add inotify watch");
let events = inotify
.event_stream([0; 1024])
.into_event_stream([0; 1024])
.expect("failed to set up event stream");
LiveFileReader {
size,

View file

@ -15,6 +15,7 @@ use actix_web::{
use actix_web_actors::ws;
use argon2::{Argon2, PasswordVerifier};
use askama_actix::{Template, TemplateToResponse};
use base64::prelude::*;
use bytesize::ByteSize;
use log::{error, warn};
use password_hash::PasswordHashString;
@ -395,13 +396,16 @@ async fn main() -> std::io::Result<()> {
let admin_password_hash: PasswordHashString = env_or_panic("TRANSBEAM_ADMIN_PASSWORD_HASH");
let cookie_secret_base64: String = env_or_panic("TRANSBEAM_COOKIE_SECRET");
let cookie_key =
cookie::Key::from(&base64::decode(&cookie_secret_base64).unwrap_or_else(|_| {
panic!(
"Value {} for TRANSBEAM_COOKIE_SECRET is not valid base64",
cookie_secret_base64
)
}));
let cookie_key = cookie::Key::from(
&BASE64_STANDARD
.decode(&cookie_secret_base64)
.unwrap_or_else(|_| {
panic!(
"Value {} for TRANSBEAM_COOKIE_SECRET is not valid base64",
cookie_secret_base64
)
}),
);
let state_file: PathBuf = match std::env::var("TRANSBEAM_STATE_FILE") {
Ok(v) => v

View file

@ -3,6 +3,7 @@ use jsondb::JsonDb;
pub mod prelude {
pub use std::collections::HashMap;
use bytesize::ByteSize;
pub use jsondb::Schema;
pub use serde::{Deserialize, Serialize};
pub use serde_with::serde_as;
@ -13,7 +14,11 @@ pub mod prelude {
fn size(&self) -> u64;
fn formatted_size(&self) -> String {
bytesize::to_string(self.size(), false).replace(' ', "")
ByteSize(self.size())
.display()
.si()
.to_string()
.replace(' ', "")
}
}
}

View file

@ -1,4 +1,4 @@
use std::{collections::HashSet, fs::File, io::Write, path::Path, path::Component};
use std::{collections::HashSet, fs::File, io::Write, path::Component, path::Path};
use actix::{fut::future::ActorFutureExt, Actor, ActorContext, AsyncContext, StreamHandler};
use actix_http::ws::{CloseReason, Item};
@ -30,28 +30,32 @@ fn sanitise_path_component(name: &str, extension_length: usize) -> String {
sanitise_with_options(
&name,
&SanOptions {
length_limit: SanOptions::DEFAULT.length_limit.saturating_sub(extension_length),
length_limit: SanOptions::DEFAULT
.length_limit
.saturating_sub(extension_length),
..SanOptions::DEFAULT
},
)
}
fn sanitise_path(path: &str) -> String {
let mut san_path = Path::new(path).components().rfold(String::new(), |subpath, c| {
if subpath.len() >= SanOptions::DEFAULT.length_limit*8 {
return subpath;
}
if let Component::Normal(s) = c {
let mut component = sanitise_path_component(&s.to_string_lossy(), 0);
if !subpath.is_empty() {
component.push('/');
component.push_str(&subpath);
let mut san_path = Path::new(path)
.components()
.rfold(String::new(), |subpath, c| {
if subpath.len() >= SanOptions::DEFAULT.length_limit * 8 {
return subpath;
}
component
} else {
subpath
}
});
if let Component::Normal(s) = c {
let mut component = sanitise_path_component(&s.to_string_lossy(), 0);
if !subpath.is_empty() {
component.push('/');
component.push_str(&subpath);
}
component
} else {
subpath
}
});
if san_path.is_empty() {
san_path.push('_');
}
@ -306,8 +310,9 @@ impl Uploader {
if files.len() > 1 {
info!("Wrapping in zipfile generator");
let now = OffsetDateTime::now_utc();
let collection_name =
collection_name.map(|f| sanitise_path_component(&f, 4)).unwrap_or_else(|| {
let collection_name = collection_name
.map(|f| sanitise_path_component(&f, 4))
.unwrap_or_else(|| {
super::APP_NAME.to_owned()
+ &now.format(FILENAME_DATE_FORMAT).unwrap()
});