You've already forked AstralRinth
forked from didirus/AstralRinth
This reverts commit 609e3896eb.
This commit is contained in:
@@ -9,7 +9,7 @@ use crate::database::models::thread_item::ThreadMessageBuilder;
|
||||
use crate::database::models::{DBTeamMember, ids as db_ids, image_item};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::database::{self, models as db_models};
|
||||
use crate::file_hosting::{CdnConfig, FileHost, FileHostPublicity, UseAltCdn};
|
||||
use crate::file_hosting::{FileHost, FileHostPublicity};
|
||||
use crate::models;
|
||||
use crate::models::ids::{ProjectId, VersionId};
|
||||
use crate::models::images::ImageContext;
|
||||
@@ -1068,8 +1068,6 @@ pub async fn dependency_list(
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
cdn_config: web::Data<CdnConfig>,
|
||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let string = info.into_inner().0;
|
||||
|
||||
@@ -1138,7 +1136,6 @@ pub async fn dependency_list(
|
||||
&user_option,
|
||||
&pool,
|
||||
&redis,
|
||||
&cdn_config.make_choice(use_alt_cdn),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ use crate::auth::checks::{filter_visible_versions, is_visible_version};
|
||||
use crate::auth::{filter_visible_projects, get_user_from_headers};
|
||||
use crate::database::ReadOnlyPgPool;
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::file_hosting::{CdnConfig, UseAltCdn};
|
||||
use crate::models::ids::VersionId;
|
||||
use crate::models::pats::Scopes;
|
||||
use crate::models::projects::VersionType;
|
||||
@@ -42,8 +41,6 @@ pub async fn get_version_from_hash(
|
||||
redis: web::Data<RedisPool>,
|
||||
hash_query: web::Query<HashQuery>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
cdn_config: web::Data<CdnConfig>,
|
||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user_option = get_user_from_headers(
|
||||
&req,
|
||||
@@ -78,10 +75,8 @@ pub async fn get_version_from_hash(
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().json(models::projects::Version::from(
|
||||
version,
|
||||
&cdn_config.make_choice(use_alt_cdn),
|
||||
)))
|
||||
Ok(HttpResponse::Ok()
|
||||
.json(models::projects::Version::from(version)))
|
||||
} else {
|
||||
Err(ApiError::NotFound)
|
||||
}
|
||||
@@ -132,8 +127,6 @@ pub async fn get_update_from_hash(
|
||||
hash_query: web::Query<HashQuery>,
|
||||
update_data: web::Json<UpdateData>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
cdn_config: web::Data<CdnConfig>,
|
||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user_option = get_user_from_headers(
|
||||
&req,
|
||||
@@ -202,12 +195,9 @@ pub async fn get_update_from_hash(
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
|
||||
return Ok(HttpResponse::Ok().json(
|
||||
models::projects::Version::from(
|
||||
first,
|
||||
&cdn_config.make_choice(use_alt_cdn),
|
||||
),
|
||||
));
|
||||
return Ok(
|
||||
HttpResponse::Ok().json(models::projects::Version::from(first))
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(ApiError::NotFound)
|
||||
@@ -226,8 +216,6 @@ pub async fn get_versions_from_hashes(
|
||||
redis: web::Data<RedisPool>,
|
||||
file_data: web::Json<FileHashes>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
cdn_config: web::Data<CdnConfig>,
|
||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user_option = get_user_from_headers(
|
||||
&req,
|
||||
@@ -260,7 +248,6 @@ pub async fn get_versions_from_hashes(
|
||||
&user_option,
|
||||
&pool,
|
||||
&redis,
|
||||
&cdn_config.make_choice(use_alt_cdn),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -348,8 +335,6 @@ pub async fn update_files(
|
||||
pool: web::Data<ReadOnlyPgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
update_data: web::Json<ManyUpdateData>,
|
||||
cdn_config: web::Data<CdnConfig>,
|
||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let algorithm = update_data
|
||||
.algorithm
|
||||
@@ -407,11 +392,10 @@ pub async fn update_files(
|
||||
.find(|x| x.inner.project_id == file.project_id)
|
||||
&& let Some(hash) = file.hashes.get(&algorithm)
|
||||
{
|
||||
let version = models::projects::Version::from(
|
||||
version.clone(),
|
||||
&cdn_config.make_choice(use_alt_cdn),
|
||||
response.insert(
|
||||
hash.clone(),
|
||||
models::projects::Version::from(version.clone()),
|
||||
);
|
||||
response.insert(hash.clone(), version);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,8 +422,6 @@ pub async fn update_individual_files(
|
||||
redis: web::Data<RedisPool>,
|
||||
update_data: web::Json<ManyFileUpdateData>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
cdn_config: web::Data<CdnConfig>,
|
||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user_option = get_user_from_headers(
|
||||
&req,
|
||||
@@ -542,11 +524,10 @@ pub async fn update_individual_files(
|
||||
)
|
||||
.await?
|
||||
{
|
||||
let version = models::projects::Version::from(
|
||||
version.clone(),
|
||||
&cdn_config.make_choice(use_alt_cdn),
|
||||
response.insert(
|
||||
hash.clone(),
|
||||
models::projects::Version::from(version.clone()),
|
||||
);
|
||||
response.insert(hash.clone(), version);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -693,7 +674,6 @@ pub async fn download_version(
|
||||
redis: web::Data<RedisPool>,
|
||||
hash_query: web::Query<HashQuery>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user_option = get_user_from_headers(
|
||||
&req,
|
||||
@@ -724,15 +704,6 @@ pub async fn download_version(
|
||||
database::models::DBVersion::get(file.version_id, &**pool, &redis)
|
||||
.await?;
|
||||
|
||||
let url = if use_alt_cdn {
|
||||
let cdn_url = dotenvy::var("CDN_URL").unwrap();
|
||||
let cdn_alt_url = dotenvy::var("CDN_ALT_URL").unwrap();
|
||||
|
||||
file.url.replace(&cdn_url, &cdn_alt_url)
|
||||
} else {
|
||||
file.url.clone()
|
||||
};
|
||||
|
||||
if let Some(version) = version {
|
||||
if !is_visible_version(&version.inner, &user_option, &pool, &redis)
|
||||
.await?
|
||||
@@ -741,8 +712,8 @@ pub async fn download_version(
|
||||
}
|
||||
|
||||
Ok(HttpResponse::TemporaryRedirect()
|
||||
.append_header(("Location", &*url))
|
||||
.json(DownloadRedirect { url }))
|
||||
.append_header(("Location", &*file.url))
|
||||
.json(DownloadRedirect { url: file.url }))
|
||||
} else {
|
||||
Err(ApiError::NotFound)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ use crate::database::models::version_item::{
|
||||
};
|
||||
use crate::database::models::{DBOrganization, image_item};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::file_hosting::{CdnConfig, UseAltCdn};
|
||||
use crate::models;
|
||||
use crate::models::ids::VersionId;
|
||||
use crate::models::images::ImageContext;
|
||||
@@ -62,30 +61,16 @@ pub async fn version_project_get(
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
cdn_config: web::Data<CdnConfig>,
|
||||
use_alt_cdn: UseAltCdn,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let info = info.into_inner();
|
||||
version_project_get_helper(
|
||||
req,
|
||||
info,
|
||||
pool,
|
||||
redis,
|
||||
session_queue,
|
||||
cdn_config,
|
||||
use_alt_cdn,
|
||||
)
|
||||
.await
|
||||
version_project_get_helper(req, info, pool, redis, session_queue).await
|
||||
}
|
||||
|
||||
pub async fn version_project_get_helper(
|
||||
req: HttpRequest,
|
||||
id: (String, String),
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
cdn_config: web::Data<CdnConfig>,
|
||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let result =
|
||||
database::models::DBProject::get(&id.0, &**pool, &redis).await?;
|
||||
@@ -125,12 +110,8 @@ pub async fn version_project_get_helper(
|
||||
&& is_visible_version(&version.inner, &user_option, &pool, &redis)
|
||||
.await?
|
||||
{
|
||||
return Ok(HttpResponse::Ok().json(
|
||||
models::projects::Version::from(
|
||||
version,
|
||||
&cdn_config.make_choice(use_alt_cdn),
|
||||
),
|
||||
));
|
||||
return Ok(HttpResponse::Ok()
|
||||
.json(models::projects::Version::from(version)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,8 +129,6 @@ pub async fn versions_get(
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
cdn_config: web::Data<CdnConfig>,
|
||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let version_ids =
|
||||
serde_json::from_str::<Vec<models::ids::VersionId>>(&ids.ids)?
|
||||
@@ -171,14 +150,9 @@ pub async fn versions_get(
|
||||
.map(|x| x.1)
|
||||
.ok();
|
||||
|
||||
let versions = filter_visible_versions(
|
||||
versions_data,
|
||||
&user_option,
|
||||
&pool,
|
||||
&redis,
|
||||
&cdn_config.make_choice(use_alt_cdn),
|
||||
)
|
||||
.await?;
|
||||
let versions =
|
||||
filter_visible_versions(versions_data, &user_option, &pool, &redis)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(versions))
|
||||
}
|
||||
@@ -189,20 +163,9 @@ pub async fn version_get(
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
cdn_config: web::Data<CdnConfig>,
|
||||
use_alt_cdn: UseAltCdn,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let id = info.into_inner().0;
|
||||
version_get_helper(
|
||||
req,
|
||||
id,
|
||||
pool,
|
||||
redis,
|
||||
session_queue,
|
||||
cdn_config,
|
||||
use_alt_cdn,
|
||||
)
|
||||
.await
|
||||
version_get_helper(req, id, pool, redis, session_queue).await
|
||||
}
|
||||
|
||||
pub async fn version_get_helper(
|
||||
@@ -211,8 +174,6 @@ pub async fn version_get_helper(
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
cdn_config: web::Data<CdnConfig>,
|
||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let version_data =
|
||||
database::models::DBVersion::get(id.into(), &**pool, &redis).await?;
|
||||
@@ -231,10 +192,9 @@ pub async fn version_get_helper(
|
||||
if let Some(data) = version_data
|
||||
&& is_visible_version(&data.inner, &user_option, &pool, &redis).await?
|
||||
{
|
||||
return Ok(HttpResponse::Ok().json(models::projects::Version::from(
|
||||
data,
|
||||
&cdn_config.make_choice(use_alt_cdn),
|
||||
)));
|
||||
return Ok(
|
||||
HttpResponse::Ok().json(models::projects::Version::from(data))
|
||||
);
|
||||
}
|
||||
|
||||
Err(ApiError::NotFound)
|
||||
@@ -764,8 +724,6 @@ pub async fn version_list(
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
cdn_config: web::Data<CdnConfig>,
|
||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let string = info.into_inner().0;
|
||||
|
||||
@@ -898,14 +856,9 @@ pub async fn version_list(
|
||||
});
|
||||
response.dedup_by(|a, b| a.inner.id == b.inner.id);
|
||||
|
||||
let response = filter_visible_versions(
|
||||
response,
|
||||
&user_option,
|
||||
&pool,
|
||||
&redis,
|
||||
&cdn_config.make_choice(use_alt_cdn),
|
||||
)
|
||||
.await?;
|
||||
let response =
|
||||
filter_visible_versions(response, &user_option, &pool, &redis)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(response))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user