Skip to content

Commit

Permalink
fix: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
TroyKomodo committed Jan 31, 2024
1 parent 391b9fe commit f96a887
Show file tree
Hide file tree
Showing 81 changed files with 919 additions and 737 deletions.
6 changes: 3 additions & 3 deletions binary-helper/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{net::SocketAddr, sync::Arc};

use crate::logging;
use std::net::SocketAddr;
use std::sync::Arc;

use super::Config;
use crate::logging;

#[derive(Debug, Clone, PartialEq, config::Config, serde::Deserialize)]
#[serde(default)]
Expand Down
14 changes: 7 additions & 7 deletions binary-helper/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ use std::time::Duration;
use anyhow::Context as _;
use async_nats::ServerAddr;
use bytes::Bytes;
use utils::http::RouteError;
use fred::interfaces::ClientLike;
use fred::types::ServerConfig;
use hyper::StatusCode;
use crate::config::{DatabaseConfig, NatsConfig, RedisConfig};
use rustls::RootCertStore;
use utils::database::deadpool_postgres::{ManagerConfig, PoolConfig, RecyclingMethod, Runtime};
use utils::database::tokio_postgres::NoTls;
use utils::database::Pool;
use fred::interfaces::ClientLike;
use fred::types::ServerConfig;
use rustls::RootCertStore;
use utils::http::RouteError;

use crate::config::{DatabaseConfig, NatsConfig, RedisConfig};

#[macro_export]
macro_rules! impl_global_traits {
Expand Down Expand Up @@ -79,7 +80,6 @@ pub trait GlobalRedis {
fn redis(&self) -> &Arc<fred::clients::RedisPool>;
}


pub async fn setup_nats(
name: &str,
config: &NatsConfig,
Expand Down Expand Up @@ -287,4 +287,4 @@ impl<E, B> RequestGlobalExt<E> for hyper::Request<B> {
.upgrade()
.ok_or((StatusCode::INTERNAL_SERVER_ERROR, "failed to upgrade global state"))?)
}
}
}
9 changes: 5 additions & 4 deletions binary-helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ use std::sync::Arc;
use std::time::Duration;

use anyhow::Context as _;
use self::config::GrpcConfig;
use utils::context::Context;
use utils::signal;
use tokio::signal::unix::SignalKind;
use tokio::{select, time};
use tonic::transport::{Certificate, Identity, Server, ServerTlsConfig};
pub use traits::{Config, Global};
use utils::context::Context;
use utils::signal;

use self::config::GrpcConfig;

pub mod config;
pub mod global;
pub mod grpc_health;
pub mod traits;
pub mod logging;
pub mod s3;
pub mod traits;

pub async fn bootstrap<C: Config, G: Global<C>, F: Future<Output = anyhow::Result<()>> + Send + 'static>(
process: impl FnOnce(Arc<G>) -> F,
Expand Down
3 changes: 1 addition & 2 deletions binary-helper/src/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use aws_sdk_s3::primitives::ByteStream;
use aws_sdk_s3::types::ObjectCannedAcl;
use bytes::Bytes;

use crate::config::S3BucketConfig;
use crate::config::S3CredentialsConfig;
use crate::config::{S3BucketConfig, S3CredentialsConfig};

#[derive(Debug, Clone)]
pub struct Bucket {
Expand Down
2 changes: 1 addition & 1 deletion platform/api/src/api/auth.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::collections::HashMap;
use std::sync::Arc;

use utils::http::RouteError;
use hyper::StatusCode;
use ulid::Ulid;
use utils::http::RouteError;

use super::error::ApiError;
use crate::database::{Role, RolePermission, Session, User};
Expand Down
2 changes: 1 addition & 1 deletion platform/api/src/api/middleware/auth.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::sync::Arc;

use binary_helper::global::RequestGlobalExt;
use hyper::http::header;
use utils::http::ext::*;
use utils::http::router::ext::RequestExt;
use utils::http::router::middleware::Middleware;
use utils::http::RouteError;
use hyper::http::header;

use crate::api::auth::{AuthData, AuthError};
use crate::api::error::ApiError;
Expand Down
6 changes: 3 additions & 3 deletions platform/api/src/api/middleware/cors.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::sync::Arc;

use hyper::body::Incoming;
use hyper::http::header;
use serde_json::json;
use utils::http::router::extend::{extend_fn, ExtendRouter};
use utils::http::router::middleware::Middleware;
use utils::http::RouteError;
use utils::make_response;
use hyper::body::Incoming;
use hyper::http::header;
use serde_json::json;

use crate::api::error::ApiError;
use crate::api::Body;
Expand Down
6 changes: 3 additions & 3 deletions platform/api/src/api/middleware/response_headers.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::sync::{Arc, Mutex};

use hyper::body::Incoming;
use hyper::header::IntoHeaderName;
use hyper::Request;
use utils::http::router::ext::RequestExt as _;
use utils::http::router::extend::{extend_fn, ExtendRouter};
use utils::http::router::middleware::Middleware;
use utils::http::RouteError;
use hyper::body::Incoming;
use hyper::header::IntoHeaderName;
use hyper::Request;

use crate::api::error::ApiError;
use crate::api::Body;
Expand Down
26 changes: 13 additions & 13 deletions platform/api/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ use std::time::Duration;

use anyhow::Context;
use bytes::Bytes;
use utils::context::ContextExt;
use utils::http::router::Router;
use utils::http::RouteError;
use utils::make_response;
use utils::prelude::FutureTimeout;
use http_body_util::Full;
use hyper::body::Incoming;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper_util::rt::TokioIo;
use serde_json::json;
use tokio::net::TcpSocket;
use utils::context::ContextExt;
use utils::http::router::Router;
use utils::http::RouteError;
use utils::make_response;
use utils::prelude::FutureTimeout;

use self::error::ApiError;
use crate::config::ApiConfig;
Expand Down Expand Up @@ -124,15 +124,15 @@ pub async fn run<G: ApiGlobal>(global: Arc<G>) -> anyhow::Result<()> {
return;
};
tracing::debug!("TLS handshake complete");
http.serve_connection(
TokioIo::new(socket),
service,
).with_upgrades().await.ok();
http.serve_connection(TokioIo::new(socket), service)
.with_upgrades()
.await
.ok();
} else {
http.serve_connection(
TokioIo::new(socket),
service,
).with_upgrades().await.ok();
http.serve_connection(TokioIo::new(socket), service)
.with_upgrades()
.await
.ok();
}
});
}
Expand Down
15 changes: 10 additions & 5 deletions platform/api/src/api/v1/gql/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ use async_graphql::http::{WebSocketProtocols, WsMessage};
use async_graphql::Data;
use binary_helper::global::RequestGlobalExt;
use bytes::Bytes;
use utils::context::ContextExt;
use utils::http::ext::*;
use utils::http::router::compat::BodyExt as _;
use utils::http::router::ext::RequestExt;
use futures_util::{SinkExt, StreamExt};
use http_body_util::Full;
use hyper::body::Incoming;
Expand All @@ -19,6 +15,10 @@ use hyper_tungstenite::tungstenite::protocol::CloseFrame;
use hyper_tungstenite::tungstenite::Message;
use hyper_tungstenite::HyperWebsocket;
use serde_json::json;
use utils::context::ContextExt;
use utils::http::ext::*;
use utils::http::router::compat::BodyExt as _;
use utils::http::router::ext::RequestExt;

use super::error::GqlError;
use super::ext::RequestExt as _;
Expand Down Expand Up @@ -103,7 +103,12 @@ async fn websocket_handler<G: ApiGlobal>(
// This is interesting since when we shutdown we interrupt the stream forward
// rather then waiting for the stream to finish.
if stream.forward(&mut tx).context(global.ctx()).await.is_err() {
tx.send(Message::Close(Some(CloseFrame { code: CloseCode::Restart, reason: "server is restarting".into() }))).await.ok();
tx.send(Message::Close(Some(CloseFrame {
code: CloseCode::Restart,
reason: "server is restarting".into(),
})))
.await
.ok();
} else {
tx.close().await.ok();
}
Expand Down
4 changes: 2 additions & 2 deletions platform/api/src/api/v1/gql/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::sync::Arc;

use async_graphql::{extensions, Schema};
use hyper::body::Incoming;
use hyper::Response;
use utils::http::router::builder::RouterBuilder;
use utils::http::router::Router;
use utils::http::RouteError;
use hyper::body::Incoming;
use hyper::Response;

use crate::api::error::ApiError;
use crate::api::Body;
Expand Down
2 changes: 1 addition & 1 deletion platform/api/src/api/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::sync::Arc;

use hyper::body::Incoming;
use utils::http::router::builder::RouterBuilder;
use utils::http::router::Router;
use utils::http::RouteError;
use hyper::body::Incoming;

use super::error::ApiError;
use super::Body;
Expand Down
6 changes: 3 additions & 3 deletions platform/api/src/api/v1/upload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use std::sync::Arc;

use binary_helper::global::RequestGlobalExt;
use bytes::Bytes;
use hyper::body::Incoming;
use hyper::{Request, Response, StatusCode};
use multer::{Constraints, SizeLimit};
use utils::http::ext::{OptionExt, ResultExt};
use utils::http::router::builder::RouterBuilder;
use utils::http::router::compat::BodyExt;
use utils::http::router::ext::RequestExt;
use utils::http::router::Router;
use utils::http::RouteError;
use hyper::body::Incoming;
use hyper::{Request, Response, StatusCode};
use multer::{Constraints, SizeLimit};

use self::profile_picture::ProfilePicture;
use crate::api::auth::AuthData;
Expand Down
15 changes: 5 additions & 10 deletions platform/api/src/api/v1/upload/profile_picture.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::sync::Arc;

use aws_sdk_s3::types::ObjectCannedAcl;
use bytes::Bytes;
use utils::http::ext::ResultExt;
use utils::http::RouteError;
use utils::make_response;
use binary_helper::s3::PutObjectOptions;
use bytes::Bytes;
use hyper::{Response, StatusCode};
use pb::scuffle::platform::internal::image_processor;
use pb::scuffle::platform::internal::types::{uploaded_file_metadata, ImageFormat, UploadedFileMetadata};
use serde_json::json;
use ulid::Ulid;
use utils::http::ext::ResultExt;
use utils::http::RouteError;
use utils::make_response;

use super::UploadType;
use crate::api::auth::AuthData;
Expand Down Expand Up @@ -47,12 +47,7 @@ fn create_task(file_id: Ulid, input_path: &str, config: &ImageUploaderConfig, ow
resize_algorithm: image_processor::task::ResizeAlgorithm::Lanczos3 as i32,
upscale: image_processor::task::Upscale::NoPreserveSource as i32,
input_image_scaling: true,
scales: vec![
64,
128,
256,
384,
],
scales: vec![64, 128, 256, 384],
resize_method: image_processor::task::ResizeMethod::PadCenter as i32,
output_prefix: format!("{owner_id}/{file_id}"),
}
Expand Down
2 changes: 1 addition & 1 deletion platform/api/src/database/channel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use async_graphql::SimpleObject;
use chrono::{DateTime, Utc};
use utils::database::json;
use ulid::Ulid;
use utils::database::json;

#[derive(Debug, Clone, Default, postgres_from_row::FromRow)]
pub struct Channel {
Expand Down
2 changes: 1 addition & 1 deletion platform/api/src/database/two_fa_request.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::sync::Arc;

use chrono::{Duration, Utc};
use utils::database::protobuf;
use pb::ext::UlidExt;
use pb::scuffle::platform::internal::two_fa::two_fa_request_action::{ChangePassword, Login};
use pb::scuffle::platform::internal::two_fa::TwoFaRequestAction;
use ulid::Ulid;
use utils::database::protobuf;

use super::{Session, User};
use crate::global::ApiGlobal;
Expand Down
2 changes: 1 addition & 1 deletion platform/api/src/database/uploaded_file.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use utils::database::protobuf;
use ulid::Ulid;
use utils::database::protobuf;

use super::{FileType, UploadedFileStatus};

Expand Down
2 changes: 1 addition & 1 deletion platform/api/src/dataloader/category.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use utils::dataloader::{DataLoader, Loader, LoaderOutput};
use ulid::Ulid;
use utils::dataloader::{DataLoader, Loader, LoaderOutput};

use crate::database::Category;

Expand Down
2 changes: 1 addition & 1 deletion platform/api/src/dataloader/role.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use utils::dataloader::{DataLoader, Loader, LoaderOutput};
use ulid::Ulid;
use utils::dataloader::{DataLoader, Loader, LoaderOutput};

use crate::database::Role;

Expand Down
2 changes: 1 addition & 1 deletion platform/api/src/dataloader/session.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use utils::dataloader::{DataLoader, Loader, LoaderOutput};
use ulid::Ulid;
use utils::dataloader::{DataLoader, Loader, LoaderOutput};

use crate::database::Session;

Expand Down
2 changes: 1 addition & 1 deletion platform/api/src/dataloader/uploaded_file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use utils::dataloader::{DataLoader, Loader, LoaderOutput};
use ulid::Ulid;
use utils::dataloader::{DataLoader, Loader, LoaderOutput};

use crate::database::UploadedFile;

Expand Down
2 changes: 1 addition & 1 deletion platform/api/src/dataloader/user.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use utils::dataloader::{DataLoader, Loader, LoaderOutput};
use ulid::Ulid;
use utils::dataloader::{DataLoader, Loader, LoaderOutput};

use crate::database::User;

Expand Down
5 changes: 1 addition & 4 deletions platform/api/src/igdb_cron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,7 @@ fn create_task(
callback_subject: config.callback_subject.clone(),
upscale: image_processor::task::Upscale::NoPreserveSource as i32,
output_prefix: format!("categories/{category_id}/{id}"),
scales: vec![
720,
1080,
],
scales: vec![720, 1080],
input_image_scaling: true,
limits: Some(image_processor::task::Limits {
max_processing_time_ms: 60000,
Expand Down
Loading

0 comments on commit f96a887

Please sign in to comment.