Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions src/auth/github.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::auth::AuthenticationError;
use crate::database::repository::github_login_attempts;
use crate::types::models::github_login_attempt::StoredLoginAttempt;
use reqwest::{Client, header::HeaderValue};
use reqwest::{header::HeaderValue, Client};
use serde::{Deserialize, Serialize};
use serde_json::json;
use sqlx::{PgConnection, types::ipnetwork::IpNetwork};
use sqlx::{types::ipnetwork::IpNetwork, PgConnection};
use uuid::Uuid;

#[derive(Debug, Deserialize, Serialize)]
Expand All @@ -16,7 +16,7 @@ pub struct GithubStartAuth {
interval: i32,
}

#[derive(Deserialize)]
#[derive(Deserialize, Default)]
pub enum GithubDeviceFlowErrorString {
#[serde(rename(deserialize = "authorization_pending"))]
AuthorizationPending,
Expand All @@ -34,15 +34,10 @@ pub enum GithubDeviceFlowErrorString {
AccessDenied,
#[serde(rename(deserialize = "device_flow_disabled"))]
DeviceFlowDisabled,
#[default]
Unknown,
}

impl Default for GithubDeviceFlowErrorString {
fn default() -> Self {
GithubDeviceFlowErrorString::Unknown
}
}

#[derive(Deserialize)]
pub struct GithubErrorResponse {
error: GithubDeviceFlowErrorString,
Expand Down Expand Up @@ -108,9 +103,7 @@ impl GithubClient {
}))
.send()
.await
.inspect_err(|e| {
tracing::error!("Failed to start OAuth device flow with GitHub: {e}")
})?;
.inspect_err(|e| tracing::error!("Failed to start OAuth device flow with GitHub: {e}"))?;

if !res.status().is_success() {
tracing::error!(
Expand Down Expand Up @@ -261,9 +254,7 @@ impl GithubClient {
let body = resp
.json::<serde_json::Value>()
.await
.inspect_err(|e| {
tracing::error!("github::get_installation: failed to parse response: {e}")
})
.inspect_err(|e| tracing::error!("github::get_installation: failed to parse response: {e}"))
.or(Err(AuthenticationError::InternalError(
"Failed to parse response from GitHub".into(),
)))?;
Expand Down
24 changes: 11 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::time::Duration;
use std::{sync::Arc, time::Duration};

use moka::future::Cache;

use crate::storage::{PrivateStorage, PublicStorage, StaticStorage};
use crate::{
endpoints::mods::IndexQueryParams,
types::{
endpoints::mods::IndexQueryParams, storage::{LocalBackend, PrivateDisk, PublicDisk}, types::{
api::{ApiResponse, PaginatedData},
models::mod_entity::Mod,
},
Expand All @@ -19,9 +17,9 @@ pub struct AppData {
github: GitHubClientData,
webhook_url: String,
index_admin_webhook_url: String,
static_storage: StaticStorage,
public_storage: PublicStorage,
private_storage: PrivateStorage,
static_storage: PublicDisk,
public_storage: PublicDisk,
private_storage: PrivateDisk,
disable_downloads: bool,
max_download_mb: u32,
port: u16,
Expand Down Expand Up @@ -78,9 +76,9 @@ pub async fn build_config() -> anyhow::Result<AppData> {
},
webhook_url,
index_admin_webhook_url,
static_storage: StaticStorage::new(app_url.clone()),
public_storage: PublicStorage::new(app_url.clone()),
private_storage: PrivateStorage::new(),
static_storage: PublicDisk::new(Arc::new(LocalBackend::new("static")), format!("{app_url}/static")),
public_storage: PublicDisk::new(Arc::new(LocalBackend::new("storage/public")), format!("{app_url}/storage")),
private_storage: PrivateDisk::new(Arc::new(LocalBackend::new("storage/private"))),
disable_downloads,
max_download_mb,
port,
Expand Down Expand Up @@ -140,15 +138,15 @@ impl AppData {
self.debug
}

pub fn static_storage(&self) -> &StaticStorage {
pub fn static_storage(&self) -> &PublicDisk {
&self.static_storage
}

pub fn public_storage(&self) -> &PublicStorage {
pub fn public_storage(&self) -> &PublicDisk {
&self.public_storage
}

pub fn private_storage(&self) -> &PrivateStorage {
pub fn private_storage(&self) -> &PrivateDisk {
&self.private_storage
}

Expand Down
31 changes: 0 additions & 31 deletions src/database/repository/mods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,37 +254,6 @@ pub async fn increment_downloads(id: &str, conn: &mut PgConnection) -> Result<()
Ok(())
}

#[tracing::instrument(skip_all, fields(mod_id = %the_mod.id))]
pub async fn update_with_json(
mut the_mod: Mod,
json: &ModJson,
conn: &mut PgConnection,
) -> Result<Mod, DatabaseError> {
sqlx::query!(
"UPDATE mods
SET repository = $1,
about = $2,
changelog = $3,
image = $4,
updated_at = NOW()
WHERE id = $5",
json.repository,
json.about,
json.changelog,
json.logo,
the_mod.id
)
.execute(conn)
.await
.inspect_err(|e| tracing::error!("{:?}", e))?;

the_mod.repository = json.repository.clone();
the_mod.about = json.about.clone();
the_mod.changelog = json.changelog.clone();

Ok(the_mod)
}

#[tracing::instrument(skip_all, fields(mod_id = %the_mod.id))]
pub async fn update_with_json_moved(
mut the_mod: Mod,
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub enum ApiError {
#[error("{0}")]
Database(#[from] crate::database::DatabaseError),
#[error("{0}")]
Storage(#[from] crate::storage::StorageError),
#[error("{0}")]
ModZip(#[from] ModZipError),
#[error("Database error")]
SqlxError(#[from] sqlx::Error),
Expand Down
1 change: 0 additions & 1 deletion src/endpoints/mod_status_badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use actix_web::{HttpResponse, Responder, get, web};
use serde::Deserialize;
use utoipa::{IntoParams, ToSchema};

use crate::storage::StorageDisk;
use urlencoding;

const LABEL_COLOR: &str = "#0c0811";
Expand Down
3 changes: 1 addition & 2 deletions src/endpoints/mod_version_submissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::database::DatabaseError;
use crate::database::repository::{developers, mod_version_submissions, mod_versions, mods};
use crate::events::thread_comment::NewThreadComment;
use crate::extractors::auth::Auth;
use crate::storage::StorageDisk;
use crate::types::api::{ApiResponse, PaginatedData};
use crate::types::models::audit_actions::{AuditAction, AuditActionRow};
use crate::types::models::developer::Developer;
Expand Down Expand Up @@ -863,7 +862,7 @@ pub async fn upload_attachments(
for webp_bytes in &processed {
let filename = data
.public_storage()
.store_hashed_with_extension("submission-attachments", webp_bytes, Some("webp"))
.store_hashed("submission-attachments", webp_bytes, Some("webp"))
.await?;
stored_filenames.push(filename.clone());
let row =
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::openapi::ApiDoc;
use crate::storage::StorageDisk;
use crate::types::api;
use actix_cors::Cors;
use actix_web::{
Expand Down
Loading
Loading