Bump to 0.3.1 and format/clippy
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -1,6 +1,6 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "actix"
|
name = "actix"
|
||||||
@@ -1534,7 +1534,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "image-api"
|
name = "image-api"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix",
|
"actix",
|
||||||
"actix-files",
|
"actix-files",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "image-api"
|
name = "image-api"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
authors = ["Cameron Cordes <cameronc.dev@gmail.com>"]
|
authors = ["Cameron Cordes <cameronc.dev@gmail.com>"]
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
|
|||||||
@@ -88,12 +88,10 @@ impl UserDao for SqliteUserDao {
|
|||||||
fn user_exists(&mut self, user: &str) -> bool {
|
fn user_exists(&mut self, user: &str) -> bool {
|
||||||
use schema::users::dsl::*;
|
use schema::users::dsl::*;
|
||||||
|
|
||||||
users
|
!users
|
||||||
.filter(username.eq(user))
|
.filter(username.eq(user))
|
||||||
.load::<User>(&mut self.connection)
|
.load::<User>(&mut self.connection)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default().is_empty()
|
||||||
.first()
|
|
||||||
.is_some()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
|||||||
let span_context = opentelemetry::Context::current_with_span(span);
|
let span_context = opentelemetry::Context::current_with_span(span);
|
||||||
|
|
||||||
let search_recursively = req.recursive.unwrap_or(false);
|
let search_recursively = req.recursive.unwrap_or(false);
|
||||||
if let Some(tag_ids) = &req.tag_ids {
|
if let Some(tag_ids) = &req.tag_ids
|
||||||
if search_recursively {
|
&& search_recursively {
|
||||||
let filter_mode = &req.tag_filter_mode.unwrap_or(FilterMode::Any);
|
let filter_mode = &req.tag_filter_mode.unwrap_or(FilterMode::Any);
|
||||||
info!(
|
info!(
|
||||||
"Searching for tags: {}. With path: '{}' and filter mode: {:?}",
|
"Searching for tags: {}. With path: '{}' and filter mode: {:?}",
|
||||||
@@ -142,7 +142,6 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
|||||||
.into_http_internal_err()
|
.into_http_internal_err()
|
||||||
.unwrap_or_else(|e| e.error_response());
|
.unwrap_or_else(|e| e.error_response());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
match file_system.get_files_for_path(search_path) {
|
match file_system.get_files_for_path(search_path) {
|
||||||
Ok(files) => {
|
Ok(files) => {
|
||||||
@@ -221,7 +220,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
|||||||
|
|
||||||
let dirs = files
|
let dirs = files
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&f| f.metadata().map_or(false, |md| md.is_dir()))
|
.filter(|&f| f.metadata().is_ok_and(|md| md.is_dir()))
|
||||||
.map(|path: &PathBuf| {
|
.map(|path: &PathBuf| {
|
||||||
let relative = path.strip_prefix(&app_state.base_path).unwrap();
|
let relative = path.strip_prefix(&app_state.base_path).unwrap();
|
||||||
relative.to_path_buf()
|
relative.to_path_buf()
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ async fn upload_image(
|
|||||||
while let Some(Ok(data)) = part.next().await {
|
while let Some(Ok(data)) = part.next().await {
|
||||||
file_content.put(data);
|
file_content.put(data);
|
||||||
}
|
}
|
||||||
} else if content_type.get_name().map_or(false, |name| name == "path") {
|
} else if content_type.get_name() == Some("path") {
|
||||||
while let Some(Ok(data)) = part.next().await {
|
while let Some(Ok(data)) = part.next().await {
|
||||||
if let Ok(path) = std::str::from_utf8(&data) {
|
if let Ok(path) = std::str::from_utf8(&data) {
|
||||||
file_path = Some(path.to_string())
|
file_path = Some(path.to_string())
|
||||||
|
|||||||
@@ -36,9 +36,8 @@ impl PathExcluder {
|
|||||||
let mut excluded_patterns = Vec::new();
|
let mut excluded_patterns = Vec::new();
|
||||||
|
|
||||||
for dir in raw_excluded {
|
for dir in raw_excluded {
|
||||||
if dir.starts_with('/') {
|
if let Some(rel) = dir.strip_prefix('/') {
|
||||||
// Absolute under base
|
// Absolute under base
|
||||||
let rel = &dir[1..];
|
|
||||||
if !rel.is_empty() {
|
if !rel.is_empty() {
|
||||||
excluded_dirs.push(base.join(rel));
|
excluded_dirs.push(base.join(rel));
|
||||||
}
|
}
|
||||||
@@ -64,7 +63,10 @@ impl PathExcluder {
|
|||||||
// Directory-based exclusions
|
// Directory-based exclusions
|
||||||
for excluded in &self.excluded_dirs {
|
for excluded in &self.excluded_dirs {
|
||||||
if path.starts_with(excluded) {
|
if path.starts_with(excluded) {
|
||||||
debug!("PathExcluder: excluded by dir: {:?} (rule: {:?})", path, excluded);
|
debug!(
|
||||||
|
"PathExcluder: excluded by dir: {:?} (rule: {:?})",
|
||||||
|
path, excluded
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,12 +75,8 @@ impl PathExcluder {
|
|||||||
// not substrings.
|
// not substrings.
|
||||||
if !self.excluded_patterns.is_empty() {
|
if !self.excluded_patterns.is_empty() {
|
||||||
for component in path.components() {
|
for component in path.components() {
|
||||||
if let Some(comp_str) = component.as_os_str().to_str() {
|
if let Some(comp_str) = component.as_os_str().to_str()
|
||||||
if self
|
&& self.excluded_patterns.iter().any(|pat| pat == comp_str) {
|
||||||
.excluded_patterns
|
|
||||||
.iter()
|
|
||||||
.any(|pat| pat == comp_str)
|
|
||||||
{
|
|
||||||
debug!(
|
debug!(
|
||||||
"PathExcluder: excluded by component pattern: {:?} (component: {:?}, patterns: {:?})",
|
"PathExcluder: excluded by component pattern: {:?} (component: {:?}, patterns: {:?})",
|
||||||
path, comp_str, self.excluded_patterns
|
path, comp_str, self.excluded_patterns
|
||||||
@@ -87,7 +85,6 @@ impl PathExcluder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@@ -255,20 +252,19 @@ fn extract_date_from_filename(filename: &str) -> Option<DateTime<FixedOffset>> {
|
|||||||
let timestamp_str = captures.get(1)?.as_str();
|
let timestamp_str = captures.get(1)?.as_str();
|
||||||
|
|
||||||
// Millisecond timestamp (13 digits)
|
// Millisecond timestamp (13 digits)
|
||||||
if timestamp_str.len() >= 13 {
|
if timestamp_str.len() >= 13
|
||||||
if let Some(date_time) = timestamp_str[0..13]
|
&& let Some(date_time) = timestamp_str[0..13]
|
||||||
.parse::<i64>()
|
.parse::<i64>()
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|timestamp_millis| DateTime::from_timestamp_millis(timestamp_millis))
|
.and_then(DateTime::from_timestamp_millis)
|
||||||
.map(|naive_dt| naive_dt.fixed_offset())
|
.map(|naive_dt| naive_dt.fixed_offset())
|
||||||
{
|
{
|
||||||
return Some(date_time);
|
return Some(date_time);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Second timestamp (10 digits)
|
// Second timestamp (10 digits)
|
||||||
if timestamp_str.len() >= 10 {
|
if timestamp_str.len() >= 10
|
||||||
if let Some(date_time) = timestamp_str[0..10]
|
&& let Some(date_time) = timestamp_str[0..10]
|
||||||
.parse::<i64>()
|
.parse::<i64>()
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|timestamp_secs| DateTime::from_timestamp(timestamp_secs, 0))
|
.and_then(|timestamp_secs| DateTime::from_timestamp(timestamp_secs, 0))
|
||||||
@@ -277,7 +273,6 @@ fn extract_date_from_filename(filename: &str) -> Option<DateTime<FixedOffset>> {
|
|||||||
return Some(date_time);
|
return Some(date_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -640,7 +635,10 @@ mod tests {
|
|||||||
let excluder = PathExcluder::new(base, &excluded);
|
let excluder = PathExcluder::new(base, &excluded);
|
||||||
|
|
||||||
assert!(excluder.is_excluded(&secret), "secret should be excluded");
|
assert!(excluder.is_excluded(&secret), "secret should be excluded");
|
||||||
assert!(excluder.is_excluded(&shot), "screenshots should be excluded");
|
assert!(
|
||||||
|
excluder.is_excluded(&shot),
|
||||||
|
"screenshots should be excluded"
|
||||||
|
);
|
||||||
assert!(
|
assert!(
|
||||||
!excluder.is_excluded(&ok),
|
!excluder.is_excluded(&ok),
|
||||||
"public photo should NOT be excluded"
|
"public photo should NOT be excluded"
|
||||||
@@ -740,4 +738,4 @@ mod tests {
|
|||||||
// keep.jpg doesn't match any rule
|
// keep.jpg doesn't match any rule
|
||||||
assert!(!excluder.is_excluded(&keep));
|
assert!(!excluder.is_excluded(&keep));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -504,12 +504,10 @@ impl TagDao for SqliteTagDao {
|
|||||||
trace_db_call(context, "query", "get_files_with_any_tags", |_| {
|
trace_db_call(context, "query", "get_files_with_any_tags", |_| {
|
||||||
use diesel::dsl::*;
|
use diesel::dsl::*;
|
||||||
// Create the placeholders for the IN clauses
|
// Create the placeholders for the IN clauses
|
||||||
let tag_placeholders = std::iter::repeat("?")
|
let tag_placeholders = std::iter::repeat_n("?", tag_ids.len())
|
||||||
.take(tag_ids.len())
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(",");
|
.join(",");
|
||||||
let exclude_placeholders = std::iter::repeat("?")
|
let exclude_placeholders = std::iter::repeat_n("?", exclude_tag_ids.len())
|
||||||
.take(exclude_tag_ids.len())
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(",");
|
.join(",");
|
||||||
|
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ impl Handler<GeneratePlaylistMessage> for PlaylistGenerator {
|
|||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.output()
|
.output()
|
||||||
.inspect_err(|e| error!("Failed to run ffmpeg on child process: {}", e))
|
.inspect_err(|e| error!("Failed to run ffmpeg on child process: {}", e))
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))
|
.map_err(|e| std::io::Error::other(e.to_string()))
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Hang on to the permit until we're done decoding and then explicitly drop
|
// Hang on to the permit until we're done decoding and then explicitly drop
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ impl Ffmpeg {
|
|||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.output()
|
.output()
|
||||||
.inspect_err(|e| error!("Failed to run ffmpeg on child process: {}", e))
|
.inspect_err(|e| error!("Failed to run ffmpeg on child process: {}", e))
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))
|
.map_err(|e| std::io::Error::other(e.to_string()))
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Ok(ref res) = ffmpeg_result {
|
if let Ok(ref res) = ffmpeg_result {
|
||||||
@@ -58,7 +58,7 @@ impl Ffmpeg {
|
|||||||
duration
|
duration
|
||||||
.parse::<f32>()
|
.parse::<f32>()
|
||||||
.map(|duration| duration as u32)
|
.map(|duration| duration as u32)
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))
|
.map_err(|e| std::io::Error::other(e.to_string()))
|
||||||
})
|
})
|
||||||
.inspect(|duration| debug!("Found video duration: {:?}", duration))
|
.inspect(|duration| debug!("Found video duration: {:?}", duration))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user