Run cargo fmt
This commit is contained in:
@@ -137,9 +137,9 @@ pub enum PhotoSize {
|
|||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct ThumbnailRequest {
|
pub struct ThumbnailRequest {
|
||||||
pub(crate) path: String,
|
pub(crate) path: String,
|
||||||
pub(crate)size: Option<PhotoSize>,
|
pub(crate) size: Option<PhotoSize>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub(crate)format: Option<ThumbnailFormat>,
|
pub(crate) format: Option<ThumbnailFormat>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, PartialEq)]
|
#[derive(Debug, Deserialize, PartialEq)]
|
||||||
|
|||||||
50
src/files.rs
50
src/files.rs
@@ -516,9 +516,9 @@ mod tests {
|
|||||||
|
|
||||||
use crate::database::test::in_memory_db_connection;
|
use crate::database::test::in_memory_db_connection;
|
||||||
use crate::tags::SqliteTagDao;
|
use crate::tags::SqliteTagDao;
|
||||||
|
use actix_web::test::TestRequest;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use std::{fs, sync::Arc};
|
use std::{fs, sync::Arc};
|
||||||
use actix_web::test::TestRequest;
|
|
||||||
|
|
||||||
fn setup() {
|
fn setup() {
|
||||||
let _ = env_logger::builder().is_test(true).try_init();
|
let _ = env_logger::builder().is_test(true).try_init();
|
||||||
@@ -609,12 +609,22 @@ mod tests {
|
|||||||
|
|
||||||
let mut tag_dao = SqliteTagDao::new(in_memory_db_connection());
|
let mut tag_dao = SqliteTagDao::new(in_memory_db_connection());
|
||||||
|
|
||||||
let tag1 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag1").unwrap();
|
let tag1 = tag_dao
|
||||||
let _tag2 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag2").unwrap();
|
.create_tag(&opentelemetry::Context::current(), "tag1")
|
||||||
let tag3 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag3").unwrap();
|
.unwrap();
|
||||||
|
let _tag2 = tag_dao
|
||||||
|
.create_tag(&opentelemetry::Context::current(), "tag2")
|
||||||
|
.unwrap();
|
||||||
|
let tag3 = tag_dao
|
||||||
|
.create_tag(&opentelemetry::Context::current(), "tag3")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let _ = &tag_dao.tag_file(&opentelemetry::Context::current(), "test.jpg", tag1.id).unwrap();
|
let _ = &tag_dao
|
||||||
let _ = &tag_dao.tag_file(&opentelemetry::Context::current(), "test.jpg", tag3.id).unwrap();
|
.tag_file(&opentelemetry::Context::current(), "test.jpg", tag1.id)
|
||||||
|
.unwrap();
|
||||||
|
let _ = &tag_dao
|
||||||
|
.tag_file(&opentelemetry::Context::current(), "test.jpg", tag3.id)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut files = HashMap::new();
|
let mut files = HashMap::new();
|
||||||
files.insert(
|
files.insert(
|
||||||
@@ -654,15 +664,31 @@ mod tests {
|
|||||||
|
|
||||||
let mut tag_dao = SqliteTagDao::new(in_memory_db_connection());
|
let mut tag_dao = SqliteTagDao::new(in_memory_db_connection());
|
||||||
|
|
||||||
let tag1 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag1").unwrap();
|
let tag1 = tag_dao
|
||||||
let _tag2 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag2").unwrap();
|
.create_tag(&opentelemetry::Context::current(), "tag1")
|
||||||
let tag3 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag3").unwrap();
|
.unwrap();
|
||||||
|
let _tag2 = tag_dao
|
||||||
|
.create_tag(&opentelemetry::Context::current(), "tag2")
|
||||||
|
.unwrap();
|
||||||
|
let tag3 = tag_dao
|
||||||
|
.create_tag(&opentelemetry::Context::current(), "tag3")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let _ = &tag_dao.tag_file(&opentelemetry::Context::current(), "test.jpg", tag1.id).unwrap();
|
let _ = &tag_dao
|
||||||
let _ = &tag_dao.tag_file(&opentelemetry::Context::current(), "test.jpg", tag3.id).unwrap();
|
.tag_file(&opentelemetry::Context::current(), "test.jpg", tag1.id)
|
||||||
|
.unwrap();
|
||||||
|
let _ = &tag_dao
|
||||||
|
.tag_file(&opentelemetry::Context::current(), "test.jpg", tag3.id)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Should get filtered since it doesn't have tag3
|
// Should get filtered since it doesn't have tag3
|
||||||
tag_dao.tag_file(&opentelemetry::Context::current(), "some-other.jpg", tag1.id).unwrap();
|
tag_dao
|
||||||
|
.tag_file(
|
||||||
|
&opentelemetry::Context::current(),
|
||||||
|
"some-other.jpg",
|
||||||
|
tag1.id,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut files = HashMap::new();
|
let mut files = HashMap::new();
|
||||||
files.insert(
|
files.insert(
|
||||||
|
|||||||
12
src/state.rs
12
src/state.rs
@@ -32,7 +32,6 @@ impl AppState {
|
|||||||
gif_path,
|
gif_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AppState {
|
impl Default for AppState {
|
||||||
@@ -64,10 +63,10 @@ impl AppState {
|
|||||||
// Create the AppState with the temporary paths
|
// Create the AppState with the temporary paths
|
||||||
AppState::new(
|
AppState::new(
|
||||||
std::sync::Arc::new(crate::video::actors::StreamActor {}.start()),
|
std::sync::Arc::new(crate::video::actors::StreamActor {}.start()),
|
||||||
base_path.to_string_lossy().to_string(),
|
base_path.to_string_lossy().to_string(),
|
||||||
thumbnail_path.to_string_lossy().to_string(),
|
thumbnail_path.to_string_lossy().to_string(),
|
||||||
video_path.to_string_lossy().to_string(),
|
video_path.to_string_lossy().to_string(),
|
||||||
gif_path.to_string_lossy().to_string(),
|
gif_path.to_string_lossy().to_string(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,7 +75,6 @@ impl AppState {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn create_test_subdir(base_path: &std::path::Path, name: &str) -> std::path::PathBuf {
|
fn create_test_subdir(base_path: &std::path::Path, name: &str) -> std::path::PathBuf {
|
||||||
let dir_path = base_path.join(name);
|
let dir_path = base_path.join(name);
|
||||||
std::fs::create_dir_all(&dir_path)
|
std::fs::create_dir_all(&dir_path).expect(&format!("Failed to create {} directory", name));
|
||||||
.expect(&format!("Failed to create {} directory", name));
|
|
||||||
dir_path
|
dir_path
|
||||||
}
|
}
|
||||||
|
|||||||
46
src/tags.rs
46
src/tags.rs
@@ -552,8 +552,8 @@ impl TagDao for SqliteTagDao {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use actix_web::web::{Data, Json};
|
|
||||||
use actix_web::test::TestRequest;
|
use actix_web::test::TestRequest;
|
||||||
|
use actix_web::web::{Data, Json};
|
||||||
use std::{cell::RefCell, collections::HashMap};
|
use std::{cell::RefCell, collections::HashMap};
|
||||||
|
|
||||||
use diesel::result::Error::NotFound;
|
use diesel::result::Error::NotFound;
|
||||||
@@ -724,7 +724,9 @@ mod tests {
|
|||||||
add_tag(claims, request, web::Json(body), tag_data.clone()).await;
|
add_tag(claims, request, web::Json(body), tag_data.clone()).await;
|
||||||
|
|
||||||
let mut tag_dao = tag_data.lock().unwrap();
|
let mut tag_dao = tag_data.lock().unwrap();
|
||||||
let tags = tag_dao.get_all_tags(&opentelemetry::Context::current(), None).unwrap();
|
let tags = tag_dao
|
||||||
|
.get_all_tags(&opentelemetry::Context::current(), None)
|
||||||
|
.unwrap();
|
||||||
assert_eq!(tags.len(), 1);
|
assert_eq!(tags.len(), 1);
|
||||||
assert_eq!(tags.first().unwrap().1.name, "test-tag");
|
assert_eq!(tags.first().unwrap().1.name, "test-tag");
|
||||||
let tagged_photos = tag_dao.tagged_photos.borrow();
|
let tagged_photos = tag_dao.tagged_photos.borrow();
|
||||||
@@ -747,11 +749,19 @@ mod tests {
|
|||||||
|
|
||||||
let tag_data = Data::new(Mutex::new(tag_dao));
|
let tag_data = Data::new(Mutex::new(tag_dao));
|
||||||
let request = TestRequest::default().to_http_request();
|
let request = TestRequest::default().to_http_request();
|
||||||
add_tag(claims.clone(), request.clone(), web::Json(add_request), tag_data.clone()).await;
|
add_tag(
|
||||||
|
claims.clone(),
|
||||||
|
request.clone(),
|
||||||
|
web::Json(add_request),
|
||||||
|
tag_data.clone(),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
remove_tagged_photo(claims, request, web::Json(remove_request), tag_data.clone()).await;
|
remove_tagged_photo(claims, request, web::Json(remove_request), tag_data.clone()).await;
|
||||||
|
|
||||||
let mut tag_dao = tag_data.lock().unwrap();
|
let mut tag_dao = tag_data.lock().unwrap();
|
||||||
let tags = tag_dao.get_all_tags(&opentelemetry::Context::current(), None).unwrap();
|
let tags = tag_dao
|
||||||
|
.get_all_tags(&opentelemetry::Context::current(), None)
|
||||||
|
.unwrap();
|
||||||
assert!(tags.is_empty());
|
assert!(tags.is_empty());
|
||||||
let tagged_photos = tag_dao.tagged_photos.borrow();
|
let tagged_photos = tag_dao.tagged_photos.borrow();
|
||||||
let previously_added_tagged_photo = tagged_photos.get("test.png").unwrap();
|
let previously_added_tagged_photo = tagged_photos.get("test.png").unwrap();
|
||||||
@@ -761,12 +771,22 @@ mod tests {
|
|||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn replace_tags_keeps_existing_tags_removes_extras_adds_missing_test() {
|
async fn replace_tags_keeps_existing_tags_removes_extras_adds_missing_test() {
|
||||||
let mut tag_dao = TestTagDao::new();
|
let mut tag_dao = TestTagDao::new();
|
||||||
let new_tag = tag_dao.create_tag(&opentelemetry::Context::current(), "Test").unwrap();
|
let new_tag = tag_dao
|
||||||
let new_tag2 = tag_dao.create_tag(&opentelemetry::Context::current(), "Test2").unwrap();
|
.create_tag(&opentelemetry::Context::current(), "Test")
|
||||||
let _ = tag_dao.create_tag(&opentelemetry::Context::current(), "Test3").unwrap();
|
.unwrap();
|
||||||
|
let new_tag2 = tag_dao
|
||||||
|
.create_tag(&opentelemetry::Context::current(), "Test2")
|
||||||
|
.unwrap();
|
||||||
|
let _ = tag_dao
|
||||||
|
.create_tag(&opentelemetry::Context::current(), "Test3")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
tag_dao.tag_file(&opentelemetry::Context::current(), "test.jpg", new_tag.id).unwrap();
|
tag_dao
|
||||||
tag_dao.tag_file(&opentelemetry::Context::current(), "test.jpg", new_tag2.id).unwrap();
|
.tag_file(&opentelemetry::Context::current(), "test.jpg", new_tag.id)
|
||||||
|
.unwrap();
|
||||||
|
tag_dao
|
||||||
|
.tag_file(&opentelemetry::Context::current(), "test.jpg", new_tag2.id)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let claims = Claims::valid_user(String::from("1"));
|
let claims = Claims::valid_user(String::from("1"));
|
||||||
let tag_data = Data::new(Mutex::new(tag_dao));
|
let tag_data = Data::new(Mutex::new(tag_dao));
|
||||||
@@ -777,7 +797,13 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let request = TestRequest::default().to_http_request();
|
let request = TestRequest::default().to_http_request();
|
||||||
update_tags(claims, tag_data.clone(), request, web::Json(add_tags_request)).await;
|
update_tags(
|
||||||
|
claims,
|
||||||
|
tag_data.clone(),
|
||||||
|
request,
|
||||||
|
web::Json(add_tags_request),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
let tag_dao = tag_data.lock().unwrap();
|
let tag_dao = tag_data.lock().unwrap();
|
||||||
let tags_for_test_photo = &tag_dao.tagged_photos.borrow()["test.jpg"];
|
let tags_for_test_photo = &tag_dao.tagged_photos.borrow()["test.jpg"];
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use futures::TryFutureExt;
|
use futures::TryFutureExt;
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use std::io::{Result};
|
use std::io::Result;
|
||||||
use std::process::{Output, Stdio};
|
use std::process::{Output, Stdio};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
@@ -182,4 +182,4 @@ impl Ffmpeg {
|
|||||||
|
|
||||||
Ok(output.status.code().unwrap_or(-1))
|
Ok(output.status.code().unwrap_or(-1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use crate::otel::global_tracer;
|
use crate::otel::global_tracer;
|
||||||
use crate::video::ffmpeg::{Ffmpeg, GifType};
|
use crate::video::ffmpeg::{Ffmpeg, GifType};
|
||||||
use crate::{is_video, update_media_counts};
|
use crate::{is_video, update_media_counts};
|
||||||
use log::{info};
|
use log::info;
|
||||||
use opentelemetry::trace::{Tracer};
|
use opentelemetry::trace::Tracer;
|
||||||
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::{fs};
|
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
pub mod actors;
|
pub mod actors;
|
||||||
@@ -43,8 +43,9 @@ pub async fn generate_video_gifs() {
|
|||||||
let gif_path = Path::new(gif_directory).join(relative_path);
|
let gif_path = Path::new(gif_directory).join(relative_path);
|
||||||
let gif_path = gif_path.with_extension("gif");
|
let gif_path = gif_path.with_extension("gif");
|
||||||
if let Some(parent_dir) = gif_path.parent() {
|
if let Some(parent_dir) = gif_path.parent() {
|
||||||
fs::create_dir_all(parent_dir).unwrap_or_else(|_| panic!("There was an issue creating gif directory {:?}",
|
fs::create_dir_all(parent_dir).unwrap_or_else(|_| {
|
||||||
gif_path));
|
panic!("There was an issue creating gif directory {:?}", gif_path)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
info!("Generating gif for {:?}", path);
|
info!("Generating gif for {:?}", path);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user