Skip to content

Commit

Permalink
Remove albums with no known photos
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasDeBruijn committed Mar 13, 2024
1 parent 3a71cbb commit 005f4b5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chroma",
"version": "0.1.21",
"version": "0.1.22",
"private": true,
"scripts": {
"serve": "vue-cli-service serve --port 8008",
Expand Down
2 changes: 1 addition & 1 deletion server/chroma/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chroma"
version = "0.1.21"
version = "0.1.22"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion server/chroma/src/routes/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::routes::appdata::{SessionIdCache, WebData};
use actix_web::body::BoxBody;
use actix_web::dev::Payload;
use actix_web::http::StatusCode;
use actix_web::{FromRequest, HttpRequest, HttpResponse, ResponseError, web};
use actix_web::{web, FromRequest, HttpRequest, HttpResponse, ResponseError};
use dal::database::{ChromaScope, Database, DbResult, ServiceTokenUser, User, UserType};
use std::future::Future;
use std::pin::Pin;
Expand Down
40 changes: 35 additions & 5 deletions server/chroma/src/routes/v1/album/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::routes::v1::PhotoQuality;
use actix_multiresponse::Payload;
use actix_web::web;
use dal::database::{Album, Photo};
use dal::storage_engine::EngineType;
use dal::s3::aws_errors::GetObjectErrorKind;
use dal::s3::{S3Error, SdkError};
use dal::storage_engine::{EngineType, StorageEngineError};
use dal::DalError;
use futures::future::{join_all, try_join_all};
use proto::{AlbumWithCoverPhoto, ListAlbumsResponse};
Expand Down Expand Up @@ -89,6 +91,7 @@ pub async fn list(
let database = data.db.clone();
let qpref: dal::storage_engine::PhotoQuality = query.quality_preference.clone().into();
let include_cover_photo = query.include_cover_photo;
let album_id_cache = &**album_id_cache;

async move {
// Fetch the cover photo if it is requested
Expand All @@ -103,7 +106,31 @@ pub async fn list(
};

let photo = match storage.engine_type() {
EngineType::S3 => photo.photo_to_proto_url(&storage, quality).await?,
EngineType::S3 => match photo.photo_to_proto_url(&storage, quality).await {
Ok(v) => v,
Err(e) => {
return match &e {
DalError::Storage(s) => match s {
StorageEngineError::S3(s) => match s {
S3Error::GetObject(s) => match s {
SdkError::ServiceError(s) => match s.err().kind {
GetObjectErrorKind::NoSuchKey(_) => {
album_id_cache.remove(&album.id).await;
album.delete(&database).await?;
Ok(None)
}
_ => Err(e),
},
_ => Err(e),
},
_ => Err(e),
},
_ => Err(e),
},
_ => Err(e),
}
}
},
EngineType::File => photo.photo_to_proto_bytes(&storage, quality).await?,
};

Expand All @@ -115,10 +142,10 @@ pub async fn list(
None
};

Ok(AlbumWithCoverPhoto {
Ok(Some(AlbumWithCoverPhoto {
album: Some(album.to_proto(&database).await?),
cover_photo,
})
}))
}
}))
.await
Expand All @@ -127,7 +154,10 @@ pub async fn list(
.map_err(|e| match e {
DalError::Storage(e) => Error::from(e),
DalError::Db(e) => Error::from(e),
})?;
})?
.into_iter()
.filter_map(|v| v)
.collect::<Vec<_>>();

Ok(Payload(ListAlbumsResponse { albums }))
}
4 changes: 3 additions & 1 deletion server/dal/src/s3.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use aws_credential_types::Credentials;
use aws_sdk_s3::error::{DeleteObjectError, GetObjectError, PutObjectError};
use aws_sdk_s3::presigning::config::PresigningConfig;
use aws_sdk_s3::types::{ByteStream, SdkError};
use aws_sdk_s3::types::ByteStream;
use aws_sdk_s3::{Client, Config, Region};
use std::ops::Deref;
use std::time::Duration;
Expand All @@ -11,6 +11,8 @@ pub mod aws_errors {
pub use aws_sdk_s3::error::*;
}

pub use aws_sdk_s3::types::SdkError;

#[derive(Debug, Error)]
pub enum S3InitError {
#[error("Invalid App name provided")]
Expand Down

0 comments on commit 005f4b5

Please sign in to comment.