Skip to content

Commit

Permalink
Formatted code in server/ and applied clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mervin committed Jul 24, 2024
1 parent e9c16dc commit ef0863b
Show file tree
Hide file tree
Showing 24 changed files with 133 additions and 90 deletions.
2 changes: 1 addition & 1 deletion server/chroma/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion server/chroma/src/config.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 7 additions & 4 deletions server/chroma/src/routes/authorization.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions server/chroma/src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use actix_web::web;
use actix_web::web::ServiceConfig;

use routable::Routable;

pub mod appdata;
Expand Down
10 changes: 6 additions & 4 deletions server/chroma/src/routes/v1/access.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
Expand Down
10 changes: 6 additions & 4 deletions server/chroma/src/routes/v1/album/create.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 6 additions & 4 deletions server/chroma/src/routes/v1/album/delete.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down
12 changes: 7 additions & 5 deletions server/chroma/src/routes/v1/album/get.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
13 changes: 7 additions & 6 deletions server/chroma/src/routes/v1/album/list.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion server/chroma/src/routes/v1/album/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
10 changes: 6 additions & 4 deletions server/chroma/src/routes/v1/album/update.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 6 additions & 4 deletions server/chroma/src/routes/v1/login.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions server/chroma/src/routes/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
20 changes: 11 additions & 9 deletions server/chroma/src/routes/v1/photo/create.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -236,7 +239,6 @@ fn resize_and_save(
"Photo {} with quality {} was not created successfully (AWS returned an error)",
photo_id, quality
);
return;
}
});
}
Expand Down
12 changes: 7 additions & 5 deletions server/chroma/src/routes/v1/photo/delete.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
21 changes: 12 additions & 9 deletions server/chroma/src/routes/v1/photo/get.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 8 additions & 6 deletions server/chroma/src/routes/v1/photo/list.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion server/chroma/src/routes/v1/photo/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 4 additions & 2 deletions server/chroma/src/routes/v1/user/available_scopes.rs
Original file line number Diff line number Diff line change
@@ -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<Payload<GetAvailableScopesResponse>> {
Expand Down
10 changes: 6 additions & 4 deletions server/chroma/src/routes/v1/user/get.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions server/chroma/src/routes/v1/user/list.rs
Original file line number Diff line number Diff line change
@@ -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<Payload<ListUserResponse>> {
if !auth.is_admin {
return Err(Error::Forbidden);
Expand Down
3 changes: 2 additions & 1 deletion server/chroma/src/routes/v1/user/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading

0 comments on commit ef0863b

Please sign in to comment.