Skip to content
Open
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DROP TABLE IF EXISTS geode_version_download;

ALTER TABLE geode_versions
DROP COLUMN resources_url,
DROP COLUMN resources_hash;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE geode_version_download (
tag TEXT NOT NULL REFERENCES geode_versions(tag) ON DELETE CASCADE,
platform TEXT NOT NULL,
url TEXT NOT NULL,
hash TEXT NOT NULL,
PRIMARY KEY (tag, platform)
);

ALTER TABLE geode_versions
ADD COLUMN resources_url TEXT,
ADD COLUMN resources_hash TEXT;
10 changes: 5 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct AppData {
static_storage: PublicDisk,
public_storage: PublicDisk,
private_storage: PrivateDisk,
mod_storage: Option<PublicDisk>,
cdn_storage: Option<PublicDisk>,
disable_downloads: bool,
max_download_mb: u32,
port: u16,
Expand Down Expand Up @@ -79,7 +79,7 @@ pub async fn build_config() -> anyhow::Result<AppData> {
.time_to_live(Duration::from_mins(10))
.build();

let mod_storage = if let Some(s3_config) = S3Configuration::from_env()? {
let cdn_storage = if let Some(s3_config) = S3Configuration::from_env()? {
let backend = Arc::new(S3Backend::new(&s3_config)?);
Some(PublicDisk::new(backend, s3_config.public_url))
} else {
Expand Down Expand Up @@ -113,7 +113,7 @@ pub async fn build_config() -> anyhow::Result<AppData> {
format!("{app_url}/storage"),
),
private_storage: PrivateDisk::new(Arc::new(LocalBackend::new("storage/private"))),
mod_storage,
cdn_storage,
disable_downloads,
max_download_mb,
port,
Expand Down Expand Up @@ -192,8 +192,8 @@ impl AppData {
&self.private_storage
}

pub fn mod_storage(&self) -> Option<&PublicDisk> {
self.mod_storage.as_ref()
pub fn cdn_storage(&self) -> Option<&PublicDisk> {
self.cdn_storage.as_ref()
}

pub fn mods_cache(&self) -> &Cache<IndexQueryParams, ApiResponse<PaginatedData<Mod>>> {
Expand Down
44 changes: 44 additions & 0 deletions src/database/repository/geode_versions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use sqlx::PgConnection;

use crate::database::DatabaseError;

#[tracing::instrument(skip_all, fields(tag = %tag, platform = %platform, url = %url, hash = %hash))]
pub async fn upsert_download(
tag: &str,
platform: &str,
url: &str,
hash: &str,
conn: &mut PgConnection,
) -> Result<(), DatabaseError> {
sqlx::query(
"INSERT INTO geode_version_download (tag, platform, url, hash) VALUES ($1, $2, $3, $4)
ON CONFLICT (tag, platform) DO UPDATE SET url = $3, hash = $4",
)
.bind(tag)
.bind(platform)
.bind(url)
.bind(hash)
.execute(&mut *conn)
.await
.inspect_err(|e| tracing::error!("{:?}", e))?;

Ok(())
}

#[tracing::instrument(skip_all, fields(tag = %tag, url = %url, hash = %hash))]
pub async fn update_resources_download(
tag: &str,
url: &str,
hash: &str,
conn: &mut PgConnection,
) -> Result<(), DatabaseError> {
sqlx::query("UPDATE geode_versions SET resources_url = $2, resources_hash = $3 WHERE tag = $1")
.bind(tag)
.bind(url)
.bind(hash)
.execute(&mut *conn)
.await
.inspect_err(|e| tracing::error!("{:?}", e))?;

Ok(())
}
1 change: 1 addition & 0 deletions src/database/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod auth_tokens;
pub mod dependencies;
pub mod deprecations;
pub mod developers;
pub mod geode_versions;
pub mod github_login_attempts;
pub mod github_web_logins;
pub mod incompatibilities;
Expand Down
7 changes: 6 additions & 1 deletion src/endpoints/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use utoipa::{IntoParams, ToSchema};
use sqlx::Acquire;

use crate::endpoints::ApiError;
use crate::s3_worker::S3WorkerTask;
use crate::{
config::AppData,
extractors::auth::Auth,
Expand Down Expand Up @@ -122,10 +123,12 @@ pub async fn create_version(
return Err(ApiError::Authorization);
}

let tag = payload.tag.trim_start_matches('v').to_string();

let mut tx = pool.begin().await?;
LoaderVersion::create_version(
LoaderVersionCreate {
tag: payload.tag.trim_start_matches('v').to_string(),
tag: tag.clone(),
prerelease: payload.prerelease,
commit_hash: payload.commit_hash.clone(),
win: payload.gd.win,
Expand All @@ -139,6 +142,8 @@ pub async fn create_version(

tx.commit().await?;

data.send_s3_task(S3WorkerTask::UploadLoader { tag });

Ok(HttpResponse::NoContent())
}

Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/mod_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pub async fn download_version(
let url = mod_version
.managed_download_link
.as_deref()
.take_if(|_| data.mod_storage().is_some())
.take_if(|_| data.cdn_storage().is_some())
.unwrap_or(&mod_version.download_link);

if data.disable_downloads() || mod_version.status != ModVersionStatusEnum::Accepted {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ async fn main() -> anyhow::Result<()> {
let app_data = config::build_config().await?;
app_data.static_storage().init().await?;
app_data.private_storage().init().await?;
if let Some(mod_storage) = app_data.mod_storage() {
mod_storage.init().await?;
if let Some(cdn_storage) = app_data.cdn_storage() {
cdn_storage.init().await?;
}

if cli::maybe_cli(&app_data).await? {
Expand Down
Loading
Loading