diff --git a/server/chroma/Cargo.toml b/server/chroma/Cargo.toml index e52031a..0c82c3b 100644 --- a/server/chroma/Cargo.toml +++ b/server/chroma/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] actix-cors = "0.6.4" -actix-multiresponse = { version = "0.4.2", features = ["xml"]} +actix-multiresponse = { version = "0.4.2", features = ["xml"] } actix-web = "4.3.0" actix-governor = "0.4.0" color-eyre = "0.6.2" diff --git a/server/chroma/src/config.rs b/server/chroma/src/config.rs index be6b312..67a21c1 100644 --- a/server/chroma/src/config.rs +++ b/server/chroma/src/config.rs @@ -1,8 +1,9 @@ use color_eyre::eyre::Error; -use dal::database::DbConfig; use serde::Deserialize; use tracing::{info, warn}; +use dal::database::DbConfig; + #[derive(Debug, Clone, Deserialize)] pub struct Config { // ANCHOR: config diff --git a/server/chroma/src/routes/authorization.rs b/server/chroma/src/routes/authorization.rs index 41304a3..d15e233 100644 --- a/server/chroma/src/routes/authorization.rs +++ b/server/chroma/src/routes/authorization.rs @@ -1,15 +1,18 @@ -use crate::routes::appdata::{SessionIdCache, WebData}; +use std::future::Future; +use std::pin::Pin; + use actix_web::body::BoxBody; use actix_web::dev::Payload; use actix_web::http::StatusCode; 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; use tap::TapFallible; use thiserror::Error; use tracing::{info, trace}; +use dal::database::{ChromaScope, Database, DbResult, ServiceTokenUser, User, UserType}; + +use crate::routes::appdata::{SessionIdCache, WebData}; + #[derive(Clone)] pub struct Authorization { pub user: AuthorizedUser, diff --git a/server/chroma/src/routes/mod.rs b/server/chroma/src/routes/mod.rs index 68dba13..d957255 100644 --- a/server/chroma/src/routes/mod.rs +++ b/server/chroma/src/routes/mod.rs @@ -1,5 +1,6 @@ use actix_web::web; use actix_web::web::ServiceConfig; + use routable::Routable; pub mod appdata; diff --git a/server/chroma/src/routes/v1/access.rs b/server/chroma/src/routes/v1/access.rs index ecd0170..954ed12 100644 --- a/server/chroma/src/routes/v1/access.rs +++ b/server/chroma/src/routes/v1/access.rs @@ -1,11 +1,13 @@ -use crate::routes::appdata::WebData; -use crate::routes::authorization::Authorization; -use crate::routes::error::WebResult; use actix_multiresponse::Payload; use actix_web::web; -use proto::AccessResponse; use serde::Deserialize; +use proto::AccessResponse; + +use crate::routes::appdata::WebData; +use crate::routes::authorization::Authorization; +use crate::routes::error::WebResult; + #[derive(Debug, Deserialize)] pub struct Query { scope: Option, diff --git a/server/chroma/src/routes/v1/album/create.rs b/server/chroma/src/routes/v1/album/create.rs index 63e29c3..8d627e2 100644 --- a/server/chroma/src/routes/v1/album/create.rs +++ b/server/chroma/src/routes/v1/album/create.rs @@ -1,10 +1,12 @@ -use crate::routes::appdata::WebData; -use crate::routes::authorization::Authorization; -use crate::routes::error::{Error, WebResult}; use actix_multiresponse::Payload; +use tracing::trace; + use dal::database::Album; use proto::{CreateAlbumRequest, CreateAlbumResponse}; -use tracing::trace; + +use crate::routes::appdata::WebData; +use crate::routes::authorization::Authorization; +use crate::routes::error::{Error, WebResult}; /// Create a new empty album. /// The album will not contain any photos yet. diff --git a/server/chroma/src/routes/v1/album/delete.rs b/server/chroma/src/routes/v1/album/delete.rs index 96a8e00..0361afc 100644 --- a/server/chroma/src/routes/v1/album/delete.rs +++ b/server/chroma/src/routes/v1/album/delete.rs @@ -1,12 +1,14 @@ -use crate::routes::appdata::WebData; -use crate::routes::authorization::Authorization; -use crate::routes::empty::Empty; -use crate::routes::error::{Error, WebResult}; use actix_multiresponse::Payload; + use dal::database::PhotoQuality; use dal::database::{Album, Photo}; use proto::DeleteAlbumRequest; +use crate::routes::appdata::WebData; +use crate::routes::authorization::Authorization; +use crate::routes::empty::Empty; +use crate::routes::error::{Error, WebResult}; + /// Delete an existing album. /// All photos in this album will consequently also be deleted. /// diff --git a/server/chroma/src/routes/v1/album/get.rs b/server/chroma/src/routes/v1/album/get.rs index 032e6c3..164b856 100644 --- a/server/chroma/src/routes/v1/album/get.rs +++ b/server/chroma/src/routes/v1/album/get.rs @@ -1,14 +1,16 @@ -use crate::routes::appdata::{AlbumIdCache, WebData}; -use crate::routes::authorization::Authorization; -use crate::routes::error::{Error, WebResult}; use actix_multiresponse::Payload; use actix_web::web; +use futures::future::join_all; +use serde::Deserialize; + use dal::database::PhotoQuality; use dal::database::{Album, Photo}; use dal::DalError; -use futures::future::join_all; use proto::{AlbumWithCoverPhoto, GetAlbumResponse}; -use serde::Deserialize; + +use crate::routes::appdata::{AlbumIdCache, WebData}; +use crate::routes::authorization::Authorization; +use crate::routes::error::{Error, WebResult}; #[derive(Debug, Deserialize)] pub struct Query { diff --git a/server/chroma/src/routes/v1/album/list.rs b/server/chroma/src/routes/v1/album/list.rs index 124a7ef..c5e989e 100644 --- a/server/chroma/src/routes/v1/album/list.rs +++ b/server/chroma/src/routes/v1/album/list.rs @@ -1,17 +1,18 @@ -use crate::routes::appdata::{AlbumIdCache, WebData}; -use crate::routes::authorization::Authorization; -use crate::routes::error::{Error, WebResult}; -use crate::routes::v1::PhotoQuality; use actix_multiresponse::Payload; use actix_web::web; +use futures::future::{join_all, try_join_all}; +use serde::Deserialize; use dal::database::{Album, Photo}; use dal::storage_engine::aws_error::GetObjectErrorKind; use dal::storage_engine::error::{SdkError, StorageError}; use dal::DalError; -use futures::future::{join_all, try_join_all}; use proto::{AlbumWithCoverPhoto, ListAlbumsResponse}; -use serde::Deserialize; + +use crate::routes::appdata::{AlbumIdCache, WebData}; +use crate::routes::authorization::Authorization; +use crate::routes::error::{Error, WebResult}; +use crate::routes::v1::PhotoQuality; #[derive(Debug, Deserialize)] pub struct Query { diff --git a/server/chroma/src/routes/v1/album/mod.rs b/server/chroma/src/routes/v1/album/mod.rs index a1b06f2..236cb7d 100644 --- a/server/chroma/src/routes/v1/album/mod.rs +++ b/server/chroma/src/routes/v1/album/mod.rs @@ -1,7 +1,8 @@ -use crate::routes::routable::Routable; use actix_web::web; use actix_web::web::ServiceConfig; +use crate::routes::routable::Routable; + mod create; mod delete; mod get; diff --git a/server/chroma/src/routes/v1/album/update.rs b/server/chroma/src/routes/v1/album/update.rs index 7cf668e..f77b393 100644 --- a/server/chroma/src/routes/v1/album/update.rs +++ b/server/chroma/src/routes/v1/album/update.rs @@ -1,12 +1,14 @@ -use crate::routes::appdata::{AlbumIdCache, WebData}; -use crate::routes::authorization::Authorization; -use crate::routes::empty::Empty; -use crate::routes::error::{Error, WebResult}; use actix_multiresponse::Payload; use actix_web::web; + use dal::database::{Album, Photo}; use proto::UpdateAlbumRequest; +use crate::routes::appdata::{AlbumIdCache, WebData}; +use crate::routes::authorization::Authorization; +use crate::routes::empty::Empty; +use crate::routes::error::{Error, WebResult}; + /// Update the metadata of an existing album. /// Currently, only the following properties can be updated: /// - The name diff --git a/server/chroma/src/routes/v1/login.rs b/server/chroma/src/routes/v1/login.rs index 4ef13e1..9f16fc2 100644 --- a/server/chroma/src/routes/v1/login.rs +++ b/server/chroma/src/routes/v1/login.rs @@ -1,11 +1,13 @@ -use crate::routes::appdata::WebData; -use crate::routes::error::{Error, WebResult}; -use crate::routes::redirect::Redirect; use actix_web::web; -use dal::database::{OAuthAccess, User}; use serde::Deserialize; use tracing::trace; +use dal::database::{OAuthAccess, User}; + +use crate::routes::appdata::WebData; +use crate::routes::error::{Error, WebResult}; +use crate::routes::redirect::Redirect; + #[derive(Debug, Deserialize)] pub struct Query { /// The OAuth code generated by Koala diff --git a/server/chroma/src/routes/v1/mod.rs b/server/chroma/src/routes/v1/mod.rs index 0986ceb..eca45a0 100644 --- a/server/chroma/src/routes/v1/mod.rs +++ b/server/chroma/src/routes/v1/mod.rs @@ -1,10 +1,12 @@ -use crate::routes::routable::Routable; +use std::time::Duration; + use actix_governor::governor::middleware::StateInformationMiddleware; use actix_governor::{Governor, GovernorConfig, GovernorConfigBuilder, PeerIpKeyExtractor}; use actix_web::web; use actix_web::web::ServiceConfig; use serde::Deserialize; -use std::time::Duration; + +use crate::routes::routable::Routable; mod access; mod album; diff --git a/server/chroma/src/routes/v1/photo/create.rs b/server/chroma/src/routes/v1/photo/create.rs index d2b109d..104c3dc 100644 --- a/server/chroma/src/routes/v1/photo/create.rs +++ b/server/chroma/src/routes/v1/photo/create.rs @@ -1,24 +1,27 @@ -use crate::routes::appdata::WebData; -use crate::routes::authorization::Authorization; -use crate::routes::error::{Error, ImagePipelineError, WebResult}; +use std::io::Cursor; + use actix_multiresponse::Payload; -use dal::database::{Album, Database, Photo, PhotoQuality}; -use dal::storage_engine::Storage; use exif::{In, Tag}; use governor::clock::Clock; use image::imageops::FilterType; use image::io::Reader; use image::{DynamicImage, GenericImageView}; use img_parts::{Bytes, DynImage, ImageEXIF}; -use proto::photo_respone::Response; -use proto::{CreatePhotoRequest, CreatePhotoResponse}; -use std::io::Cursor; use tap::TapFallible; use time::OffsetDateTime; use tokio::time::Instant; use tracing::{debug, instrument, trace, warn}; use webp::Encoder; +use dal::database::{Album, Database, Photo, PhotoQuality}; +use dal::storage_engine::Storage; +use proto::photo_respone::Response; +use proto::{CreatePhotoRequest, CreatePhotoResponse}; + +use crate::routes::appdata::WebData; +use crate::routes::authorization::Authorization; +use crate::routes::error::{Error, ImagePipelineError, WebResult}; + /// Create a new photo in an existing album. /// /// # Errors @@ -236,7 +239,6 @@ fn resize_and_save( "Photo {} with quality {} was not created successfully (AWS returned an error)", photo_id, quality ); - return; } }); } diff --git a/server/chroma/src/routes/v1/photo/delete.rs b/server/chroma/src/routes/v1/photo/delete.rs index 8214be7..e25d916 100644 --- a/server/chroma/src/routes/v1/photo/delete.rs +++ b/server/chroma/src/routes/v1/photo/delete.rs @@ -1,12 +1,14 @@ -use crate::routes::appdata::WebData; -use crate::routes::authorization::Authorization; -use crate::routes::empty::Empty; -use crate::routes::error::{Error, WebResult}; use actix_multiresponse::Payload; +use reqwest::StatusCode; + use dal::database::PhotoQuality; use dal::database::{Album, Photo}; use proto::DeletePhotoRequest; -use reqwest::StatusCode; + +use crate::routes::appdata::WebData; +use crate::routes::authorization::Authorization; +use crate::routes::empty::Empty; +use crate::routes::error::{Error, WebResult}; /// Delete a photo. /// If this photo is the cover of it's album, the album will no longer have a defined cover image. diff --git a/server/chroma/src/routes/v1/photo/get.rs b/server/chroma/src/routes/v1/photo/get.rs index fac6084..e02aada 100644 --- a/server/chroma/src/routes/v1/photo/get.rs +++ b/server/chroma/src/routes/v1/photo/get.rs @@ -1,19 +1,22 @@ -use crate::routes::appdata::WebData; -use crate::routes::authorization::Authorization; -use crate::routes::error::{Error, WebResult}; -use crate::routes::v1::PhotoQuality; +use std::io::Cursor; + use actix_multiresponse::Payload; use actix_web::web; -use dal::database::Photo; -use dal::DalError; use image::{DynamicImage, ImageOutputFormat}; -use proto::photo_respone::Response; -use proto::{GetPhotoResponse, PhotoRespone}; use serde::Deserialize; -use std::io::Cursor; use tap::TapFallible; use tracing::warn; +use dal::database::Photo; +use dal::DalError; +use proto::photo_respone::Response; +use proto::{GetPhotoResponse, PhotoRespone}; + +use crate::routes::appdata::WebData; +use crate::routes::authorization::Authorization; +use crate::routes::error::{Error, WebResult}; +use crate::routes::v1::PhotoQuality; + #[derive(Debug, Deserialize)] pub struct Query { /// The ID of the photo to retrieve diff --git a/server/chroma/src/routes/v1/photo/list.rs b/server/chroma/src/routes/v1/photo/list.rs index fcbafbe..a6ce475 100644 --- a/server/chroma/src/routes/v1/photo/list.rs +++ b/server/chroma/src/routes/v1/photo/list.rs @@ -1,14 +1,16 @@ -use crate::routes::appdata::WebData; -use crate::routes::authorization::Authorization; -use crate::routes::error::{Error, WebResult}; -use crate::routes::v1::PhotoQuality; use actix_multiresponse::Payload; use actix_web::web; +use futures::future::join_all; +use serde::Deserialize; + use dal::database::Photo; use dal::DalError; -use futures::future::join_all; use proto::ListPhotoResponse; -use serde::Deserialize; + +use crate::routes::appdata::WebData; +use crate::routes::authorization::Authorization; +use crate::routes::error::{Error, WebResult}; +use crate::routes::v1::PhotoQuality; #[derive(Debug, Deserialize)] pub struct Query { diff --git a/server/chroma/src/routes/v1/photo/mod.rs b/server/chroma/src/routes/v1/photo/mod.rs index 41b71c8..70fba50 100644 --- a/server/chroma/src/routes/v1/photo/mod.rs +++ b/server/chroma/src/routes/v1/photo/mod.rs @@ -1,7 +1,8 @@ -use crate::routes::routable::Routable; use actix_web::web; use actix_web::web::ServiceConfig; +use crate::routes::routable::Routable; + mod create; mod delete; mod get; diff --git a/server/chroma/src/routes/v1/user/available_scopes.rs b/server/chroma/src/routes/v1/user/available_scopes.rs index 37a9c4e..bf0ef47 100644 --- a/server/chroma/src/routes/v1/user/available_scopes.rs +++ b/server/chroma/src/routes/v1/user/available_scopes.rs @@ -1,8 +1,10 @@ -use crate::routes::authorization::Authorization; -use crate::routes::error::{Error, WebResult}; use actix_multiresponse::Payload; + use proto::GetAvailableScopesResponse; +use crate::routes::authorization::Authorization; +use crate::routes::error::{Error, WebResult}; + pub async fn available_scopes( auth: Authorization, ) -> WebResult> { diff --git a/server/chroma/src/routes/v1/user/get.rs b/server/chroma/src/routes/v1/user/get.rs index 615e183..fd3c204 100644 --- a/server/chroma/src/routes/v1/user/get.rs +++ b/server/chroma/src/routes/v1/user/get.rs @@ -1,11 +1,13 @@ -use crate::routes::appdata::WebData; -use crate::routes::authorization::Authorization; -use crate::routes::error::{Error, WebResult}; use actix_multiresponse::Payload; use actix_web::web; +use serde::Deserialize; + use dal::database::User; use proto::GetUserResponse; -use serde::Deserialize; + +use crate::routes::appdata::WebData; +use crate::routes::authorization::Authorization; +use crate::routes::error::{Error, WebResult}; #[derive(Debug, Deserialize)] pub struct Query { diff --git a/server/chroma/src/routes/v1/user/list.rs b/server/chroma/src/routes/v1/user/list.rs index b34361f..07717ae 100644 --- a/server/chroma/src/routes/v1/user/list.rs +++ b/server/chroma/src/routes/v1/user/list.rs @@ -1,10 +1,12 @@ -use crate::routes::appdata::WebData; -use crate::routes::authorization::Authorization; -use crate::routes::error::{Error, WebResult}; use actix_multiresponse::Payload; + use dal::database::User; use proto::ListUserResponse; +use crate::routes::appdata::WebData; +use crate::routes::authorization::Authorization; +use crate::routes::error::{Error, WebResult}; + pub async fn list(data: WebData, auth: Authorization) -> WebResult> { if !auth.is_admin { return Err(Error::Forbidden); diff --git a/server/chroma/src/routes/v1/user/mod.rs b/server/chroma/src/routes/v1/user/mod.rs index 9105a08..3d083e1 100644 --- a/server/chroma/src/routes/v1/user/mod.rs +++ b/server/chroma/src/routes/v1/user/mod.rs @@ -1,7 +1,8 @@ -use crate::routes::routable::Routable; use actix_web::web; use actix_web::web::ServiceConfig; +use crate::routes::routable::Routable; + mod available_scopes; mod get; mod list; diff --git a/server/chroma/src/routes/v1/user/update.rs b/server/chroma/src/routes/v1/user/update.rs index ba0ae2d..499c688 100644 --- a/server/chroma/src/routes/v1/user/update.rs +++ b/server/chroma/src/routes/v1/user/update.rs @@ -1,11 +1,14 @@ +use std::collections::HashSet; + +use actix_multiresponse::Payload; + +use dal::database::User; +use proto::UpdateUserRequest; + use crate::routes::appdata::WebData; use crate::routes::authorization::{Authorization, AuthorizedUser}; use crate::routes::empty::Empty; use crate::routes::error::{Error, WebResult}; -use actix_multiresponse::Payload; -use dal::database::User; -use proto::UpdateUserRequest; -use std::collections::HashSet; pub async fn update( data: WebData, diff --git a/server/dal/src/database/photo.rs b/server/dal/src/database/photo.rs index f69ab0e..20474f6 100644 --- a/server/dal/src/database/photo.rs +++ b/server/dal/src/database/photo.rs @@ -1,12 +1,14 @@ -use crate::database::{Album, Database, DbResult}; -use crate::storage_engine::Storage; -use crate::DalError; -use proto::photo_respone::Response; -use proto::PhotoRespone; use rand::Rng; use sqlx::{FromRow, Type}; use strum_macros::Display; +use proto::photo_respone::Response; +use proto::PhotoRespone; + +use crate::database::{Album, Database, DbResult}; +use crate::storage_engine::Storage; +use crate::DalError; + #[derive(Clone)] pub struct Photo<'a> { db: &'a Database, @@ -216,7 +218,7 @@ impl<'a> Photo<'a> { /// /// If a database error occurs pub async fn is_quality_created(&self, quality: &PhotoQuality) -> DbResult { - PhotoS3Url::get_for_photo(&self.db, &self.id, quality) + PhotoS3Url::get_for_photo(self.db, &self.id, quality) .await .map(|maybe_url| maybe_url.is_some()) }