feature/memories #35

Merged
cameron merged 11 commits from feature/memories into master 2025-08-16 16:42:39 +00:00
6 changed files with 89 additions and 38 deletions
Showing only changes of commit b3a885de28 - Show all commits

View File

@@ -137,9 +137,9 @@ pub enum PhotoSize {
#[derive(Debug, Deserialize)]
pub struct ThumbnailRequest {
pub(crate) path: String,
pub(crate)size: Option<PhotoSize>,
pub(crate) size: Option<PhotoSize>,
#[serde(default)]
pub(crate)format: Option<ThumbnailFormat>,
pub(crate) format: Option<ThumbnailFormat>,
}
#[derive(Debug, Deserialize, PartialEq)]

View File

@@ -516,9 +516,9 @@ mod tests {
use crate::database::test::in_memory_db_connection;
use crate::tags::SqliteTagDao;
use actix_web::test::TestRequest;
use actix_web::web::Data;
use std::{fs, sync::Arc};
use actix_web::test::TestRequest;
fn setup() {
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 tag1 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag1").unwrap();
let _tag2 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag2").unwrap();
let tag3 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag3").unwrap();
let tag1 = tag_dao
.create_tag(&opentelemetry::Context::current(), "tag1")
.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.tag_file(&opentelemetry::Context::current(), "test.jpg", tag3.id).unwrap();
let _ = &tag_dao
.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();
files.insert(
@@ -654,15 +664,31 @@ mod tests {
let mut tag_dao = SqliteTagDao::new(in_memory_db_connection());
let tag1 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag1").unwrap();
let _tag2 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag2").unwrap();
let tag3 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag3").unwrap();
let tag1 = tag_dao
.create_tag(&opentelemetry::Context::current(), "tag1")
.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.tag_file(&opentelemetry::Context::current(), "test.jpg", tag3.id).unwrap();
let _ = &tag_dao
.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
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();
files.insert(

View File

@@ -32,7 +32,6 @@ impl AppState {
gif_path,
}
}
}
impl Default for AppState {
@@ -64,10 +63,10 @@ impl AppState {
// Create the AppState with the temporary paths
AppState::new(
std::sync::Arc::new(crate::video::actors::StreamActor {}.start()),
base_path.to_string_lossy().to_string(),
thumbnail_path.to_string_lossy().to_string(),
video_path.to_string_lossy().to_string(),
gif_path.to_string_lossy().to_string(),
base_path.to_string_lossy().to_string(),
thumbnail_path.to_string_lossy().to_string(),
video_path.to_string_lossy().to_string(),
gif_path.to_string_lossy().to_string(),
)
}
}
@@ -76,7 +75,6 @@ impl AppState {
#[cfg(test)]
fn create_test_subdir(base_path: &std::path::Path, name: &str) -> std::path::PathBuf {
let dir_path = base_path.join(name);
std::fs::create_dir_all(&dir_path)
.expect(&format!("Failed to create {} directory", name));
std::fs::create_dir_all(&dir_path).expect(&format!("Failed to create {} directory", name));
dir_path
}

View File

@@ -552,8 +552,8 @@ impl TagDao for SqliteTagDao {
#[cfg(test)]
mod tests {
use actix_web::web::{Data, Json};
use actix_web::test::TestRequest;
use actix_web::web::{Data, Json};
use std::{cell::RefCell, collections::HashMap};
use diesel::result::Error::NotFound;
@@ -724,7 +724,9 @@ mod tests {
add_tag(claims, request, web::Json(body), tag_data.clone()).await;
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.first().unwrap().1.name, "test-tag");
let tagged_photos = tag_dao.tagged_photos.borrow();
@@ -747,11 +749,19 @@ mod tests {
let tag_data = Data::new(Mutex::new(tag_dao));
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;
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());
let tagged_photos = tag_dao.tagged_photos.borrow();
let previously_added_tagged_photo = tagged_photos.get("test.png").unwrap();
@@ -761,12 +771,22 @@ mod tests {
#[actix_rt::test]
async fn replace_tags_keeps_existing_tags_removes_extras_adds_missing_test() {
let mut tag_dao = TestTagDao::new();
let new_tag = tag_dao.create_tag(&opentelemetry::Context::current(), "Test").unwrap();
let new_tag2 = tag_dao.create_tag(&opentelemetry::Context::current(), "Test2").unwrap();
let _ = tag_dao.create_tag(&opentelemetry::Context::current(), "Test3").unwrap();
let new_tag = tag_dao
.create_tag(&opentelemetry::Context::current(), "Test")
.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_file(&opentelemetry::Context::current(), "test.jpg", new_tag2.id).unwrap();
tag_dao
.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 tag_data = Data::new(Mutex::new(tag_dao));
@@ -777,7 +797,13 @@ mod tests {
};
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 tags_for_test_photo = &tag_dao.tagged_photos.borrow()["test.jpg"];

View File

@@ -1,6 +1,6 @@
use futures::TryFutureExt;
use log::{debug, error, info, warn};
use std::io::{Result};
use std::io::Result;
use std::process::{Output, Stdio};
use std::time::Instant;
use tokio::process::Command;
@@ -182,4 +182,4 @@ impl Ffmpeg {
Ok(output.status.code().unwrap_or(-1))
}
}
}

View File

@@ -1,10 +1,10 @@
use crate::otel::global_tracer;
use crate::video::ffmpeg::{Ffmpeg, GifType};
use crate::{is_video, update_media_counts};
use log::{info};
use opentelemetry::trace::{Tracer};
use log::info;
use opentelemetry::trace::Tracer;
use std::fs;
use std::path::{Path, PathBuf};
use std::{fs};
use walkdir::WalkDir;
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 = gif_path.with_extension("gif");
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 {:?}",
gif_path));
fs::create_dir_all(parent_dir).unwrap_or_else(|_| {
panic!("There was an issue creating gif directory {:?}", gif_path)
});
}
info!("Generating gif for {:?}", path);