Improve testability and remove boxing #20
@@ -185,6 +185,7 @@ mod tests {
|
|||||||
web::Data::new(AppState::new(
|
web::Data::new(AppState::new(
|
||||||
Arc::new(StreamActor {}.start()),
|
Arc::new(StreamActor {}.start()),
|
||||||
String::from("/tmp"),
|
String::from("/tmp"),
|
||||||
|
String::from("/tmp/thumbs"),
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@@ -222,6 +223,7 @@ mod tests {
|
|||||||
web::Data::new(AppState::new(
|
web::Data::new(AppState::new(
|
||||||
Arc::new(StreamActor {}.start()),
|
Arc::new(StreamActor {}.start()),
|
||||||
String::from("/tmp"),
|
String::from("/tmp"),
|
||||||
|
String::from("/tmp/thumbs"),
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|||||||
35
src/main.rs
35
src/main.rs
@@ -7,7 +7,7 @@ use actix_web_prom::PrometheusMetricsBuilder;
|
|||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use prometheus::{self, IntGauge};
|
use prometheus::{self, IntGauge};
|
||||||
use std::sync::{mpsc::channel, Arc};
|
use std::sync::mpsc::channel;
|
||||||
use std::{collections::HashMap, io::prelude::*};
|
use std::{collections::HashMap, io::prelude::*};
|
||||||
use std::{env, fs::File};
|
use std::{env, fs::File};
|
||||||
use std::{
|
use std::{
|
||||||
@@ -16,7 +16,6 @@ use std::{
|
|||||||
};
|
};
|
||||||
use walkdir::{DirEntry, WalkDir};
|
use walkdir::{DirEntry, WalkDir};
|
||||||
|
|
||||||
use actix::prelude::*;
|
|
||||||
use actix_files::NamedFile;
|
use actix_files::NamedFile;
|
||||||
use actix_multipart as mp;
|
use actix_multipart as mp;
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
@@ -33,12 +32,14 @@ use crate::auth::login;
|
|||||||
use crate::data::*;
|
use crate::data::*;
|
||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use crate::files::{is_image_or_video, is_valid_full_path};
|
use crate::files::{is_image_or_video, is_valid_full_path};
|
||||||
|
use crate::state::AppState;
|
||||||
use crate::video::*;
|
use crate::video::*;
|
||||||
|
|
||||||
mod auth;
|
mod auth;
|
||||||
mod data;
|
mod data;
|
||||||
mod database;
|
mod database;
|
||||||
mod files;
|
mod files;
|
||||||
|
mod state;
|
||||||
mod video;
|
mod video;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -513,33 +514,3 @@ fn watch_files() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppState {
|
|
||||||
stream_manager: Arc<Addr<StreamActor>>,
|
|
||||||
base_path: String,
|
|
||||||
thumbnail_path: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AppState {
|
|
||||||
fn new(
|
|
||||||
stream_manager: Arc<Addr<StreamActor>>,
|
|
||||||
base_path: String,
|
|
||||||
thumbnail_path: String,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
stream_manager,
|
|
||||||
base_path,
|
|
||||||
thumbnail_path,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for AppState {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new(
|
|
||||||
Arc::new(StreamActor {}.start()),
|
|
||||||
env::var("BASE_PATH").expect("BASE_PATH was not set in the env"),
|
|
||||||
env::var("THUMBNAILS").expect("THUMBNAILS was not set in the env"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
33
src/state.rs
Normal file
33
src/state.rs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
use crate::StreamActor;
|
||||||
|
use actix::{Actor, Addr};
|
||||||
|
use std::{env, sync::Arc};
|
||||||
|
|
||||||
|
pub struct AppState {
|
||||||
|
pub stream_manager: Arc<Addr<StreamActor>>,
|
||||||
|
pub base_path: String,
|
||||||
|
pub thumbnail_path: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AppState {
|
||||||
|
pub fn new(
|
||||||
|
stream_manager: Arc<Addr<StreamActor>>,
|
||||||
|
base_path: String,
|
||||||
|
thumbnail_path: String,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
stream_manager,
|
||||||
|
base_path,
|
||||||
|
thumbnail_path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for AppState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new(
|
||||||
|
Arc::new(StreamActor {}.start()),
|
||||||
|
env::var("BASE_PATH").expect("BASE_PATH was not set in the env"),
|
||||||
|
env::var("THUMBNAILS").expect("THUMBNAILS was not set in the env"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user