You've already forked pages
forked from didirus/AstralRinth
This reverts commit 609e3896eb.
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -4503,7 +4503,6 @@ dependencies = [
|
|||||||
"actix-http",
|
"actix-http",
|
||||||
"actix-multipart",
|
"actix-multipart",
|
||||||
"actix-rt",
|
"actix-rt",
|
||||||
"actix-utils",
|
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"actix-web-prom",
|
"actix-web-prom",
|
||||||
"actix-ws",
|
"actix-ws",
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ actix-files = "0.6.8"
|
|||||||
actix-http = "3.11.2"
|
actix-http = "3.11.2"
|
||||||
actix-multipart = "0.7.2"
|
actix-multipart = "0.7.2"
|
||||||
actix-rt = "2.11.0"
|
actix-rt = "2.11.0"
|
||||||
actix-utils = "3.0.1"
|
|
||||||
actix-web = "4.11.0"
|
actix-web = "4.11.0"
|
||||||
actix-web-prom = "0.10.0"
|
actix-web-prom = "0.10.0"
|
||||||
actix-ws = "0.3.0"
|
actix-ws = "0.3.0"
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ SENTRY_DSN=none
|
|||||||
SITE_URL=http://localhost:3000
|
SITE_URL=http://localhost:3000
|
||||||
# This CDN URL matches the local storage backend set below, which uses MOCK_FILE_PATH
|
# This CDN URL matches the local storage backend set below, which uses MOCK_FILE_PATH
|
||||||
CDN_URL=file:///tmp/modrinth
|
CDN_URL=file:///tmp/modrinth
|
||||||
CDN_ALT_URL=file:///tmp/modrinth
|
|
||||||
LABRINTH_ADMIN_KEY=feedbeef
|
LABRINTH_ADMIN_KEY=feedbeef
|
||||||
RATE_LIMIT_IGNORE_KEY=feedbeef
|
RATE_LIMIT_IGNORE_KEY=feedbeef
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ SENTRY_DSN=none
|
|||||||
SITE_URL=http://localhost:3000
|
SITE_URL=http://localhost:3000
|
||||||
# This CDN URL matches the local storage backend set below, which uses MOCK_FILE_PATH
|
# This CDN URL matches the local storage backend set below, which uses MOCK_FILE_PATH
|
||||||
CDN_URL=file:///tmp/modrinth
|
CDN_URL=file:///tmp/modrinth
|
||||||
CDN_ALT_URL=file:///tmp/modrinth
|
|
||||||
LABRINTH_ADMIN_KEY=feedbeef
|
LABRINTH_ADMIN_KEY=feedbeef
|
||||||
LABRINTH_EXTERNAL_NOTIFICATION_KEY=beeffeed
|
LABRINTH_EXTERNAL_NOTIFICATION_KEY=beeffeed
|
||||||
RATE_LIMIT_IGNORE_KEY=feedbeef
|
RATE_LIMIT_IGNORE_KEY=feedbeef
|
||||||
|
|||||||
@@ -12,10 +12,9 @@ path = "src/main.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
actix-cors = { workspace = true }
|
actix-cors = { workspace = true }
|
||||||
actix-files = { workspace = true }
|
actix-files = { workspace = true }
|
||||||
actix-http = { workspace = true }
|
actix-http = { workspace = true, optional = true }
|
||||||
actix-multipart = { workspace = true }
|
actix-multipart = { workspace = true }
|
||||||
actix-rt = { workspace = true }
|
actix-rt = { workspace = true }
|
||||||
actix-utils = { workspace = true }
|
|
||||||
actix-web = { workspace = true }
|
actix-web = { workspace = true }
|
||||||
actix-web-prom = { workspace = true, features = ["process"] }
|
actix-web-prom = { workspace = true, features = ["process"] }
|
||||||
actix-ws = { workspace = true }
|
actix-ws = { workspace = true }
|
||||||
@@ -151,7 +150,7 @@ tikv-jemallocator = { workspace = true, features = [
|
|||||||
] }
|
] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
test = []
|
test = ["dep:actix-http"]
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use crate::database::models::version_item::VersionQueryResult;
|
|||||||
use crate::database::models::{DBCollection, DBOrganization, DBTeamMember};
|
use crate::database::models::{DBCollection, DBOrganization, DBTeamMember};
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::database::{DBProject, DBVersion, models};
|
use crate::database::{DBProject, DBVersion, models};
|
||||||
use crate::file_hosting::CdnChoice;
|
|
||||||
use crate::models::users::User;
|
use crate::models::users::User;
|
||||||
use crate::routes::ApiError;
|
use crate::routes::ApiError;
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
@@ -196,7 +195,6 @@ pub async fn filter_visible_versions(
|
|||||||
user_option: &Option<User>,
|
user_option: &Option<User>,
|
||||||
pool: &PgPool,
|
pool: &PgPool,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
cdn_choice: &CdnChoice,
|
|
||||||
) -> Result<Vec<crate::models::projects::Version>, ApiError> {
|
) -> Result<Vec<crate::models::projects::Version>, ApiError> {
|
||||||
let filtered_version_ids = filter_visible_version_ids(
|
let filtered_version_ids = filter_visible_version_ids(
|
||||||
versions.iter().map(|x| &x.inner).collect_vec(),
|
versions.iter().map(|x| &x.inner).collect_vec(),
|
||||||
@@ -206,10 +204,7 @@ pub async fn filter_visible_versions(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
versions.retain(|x| filtered_version_ids.contains(&x.inner.id));
|
versions.retain(|x| filtered_version_ids.contains(&x.inner.id));
|
||||||
Ok(versions
|
Ok(versions.into_iter().map(|x| x.into()).collect())
|
||||||
.into_iter()
|
|
||||||
.map(|v| crate::models::projects::Version::from(v, cdn_choice))
|
|
||||||
.collect())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ValidateAuthorized for models::DBOAuthClient {
|
impl ValidateAuthorized for models::DBOAuthClient {
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
use std::{convert::Infallible, sync::Arc};
|
|
||||||
|
|
||||||
use actix_http::header::HeaderName;
|
|
||||||
use actix_utils::future::{Ready, ready};
|
|
||||||
use actix_web::FromRequest;
|
|
||||||
use eyre::Result;
|
|
||||||
|
|
||||||
use crate::util::env::env_var;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub struct UseAltCdn(pub bool);
|
|
||||||
|
|
||||||
const HEADER_NAME: HeaderName = HeaderName::from_static("labrinth-alt-cdn");
|
|
||||||
|
|
||||||
impl FromRequest for UseAltCdn {
|
|
||||||
type Error = Infallible;
|
|
||||||
type Future = Ready<Result<Self, Self::Error>>;
|
|
||||||
|
|
||||||
fn from_request(
|
|
||||||
req: &actix_web::HttpRequest,
|
|
||||||
_payload: &mut actix_http::Payload,
|
|
||||||
) -> Self::Future {
|
|
||||||
ready(Ok(Self(use_alt_cdn(req))))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn use_alt_cdn(req: &actix_web::HttpRequest) -> bool {
|
|
||||||
let Some(use_alt_cdn) = req.headers().get(HEADER_NAME) else {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
use_alt_cdn.as_bytes() == b"true"
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum CdnChoice {
|
|
||||||
Default,
|
|
||||||
Alt {
|
|
||||||
base_url: Arc<str>,
|
|
||||||
alt_url: Arc<str>,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CdnChoice {
|
|
||||||
pub fn transform_file_url(&self, file_url: impl Into<String>) -> String {
|
|
||||||
let file_url = file_url.into();
|
|
||||||
match self {
|
|
||||||
Self::Default => file_url,
|
|
||||||
Self::Alt { base_url, alt_url } => {
|
|
||||||
file_url.replace(&**base_url, alt_url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct CdnConfig {
|
|
||||||
pub url: Arc<str>,
|
|
||||||
pub alt_url: Arc<str>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CdnConfig {
|
|
||||||
pub fn from_env() -> Result<Self> {
|
|
||||||
Ok(Self {
|
|
||||||
url: Arc::from(env_var("CDN_URL")?),
|
|
||||||
alt_url: Arc::from(env_var("CDN_ALT_URL")?),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn make_choice(&self, use_alt_cdn: bool) -> CdnChoice {
|
|
||||||
if use_alt_cdn {
|
|
||||||
CdnChoice::Alt {
|
|
||||||
base_url: self.url.clone(),
|
|
||||||
alt_url: self.alt_url.clone(),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
CdnChoice::Default
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
mod cdn;
|
|
||||||
mod mock;
|
mod mock;
|
||||||
mod s3_host;
|
mod s3_host;
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
pub use cdn::*;
|
|
||||||
pub use mock::MockHost;
|
pub use mock::MockHost;
|
||||||
pub use s3_host::{S3BucketConfig, S3Host};
|
pub use s3_host::{S3BucketConfig, S3Host};
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ use util::gotenberg::GotenbergClient;
|
|||||||
|
|
||||||
use crate::background_task::update_versions;
|
use crate::background_task::update_versions;
|
||||||
use crate::database::ReadOnlyPgPool;
|
use crate::database::ReadOnlyPgPool;
|
||||||
use crate::file_hosting::CdnConfig;
|
|
||||||
use crate::queue::billing::{index_billing, index_subscriptions};
|
use crate::queue::billing::{index_billing, index_subscriptions};
|
||||||
use crate::queue::moderation::AutomatedModerationQueue;
|
use crate::queue::moderation::AutomatedModerationQueue;
|
||||||
use crate::util::anrok;
|
use crate::util::anrok;
|
||||||
@@ -56,7 +55,6 @@ pub struct LabrinthConfig {
|
|||||||
pub redis_pool: RedisPool,
|
pub redis_pool: RedisPool,
|
||||||
pub clickhouse: Client,
|
pub clickhouse: Client,
|
||||||
pub file_host: Arc<dyn file_hosting::FileHost + Send + Sync>,
|
pub file_host: Arc<dyn file_hosting::FileHost + Send + Sync>,
|
||||||
pub cdn_config: web::Data<CdnConfig>,
|
|
||||||
pub maxmind: web::Data<MaxMind>,
|
pub maxmind: web::Data<MaxMind>,
|
||||||
pub scheduler: Arc<scheduler::Scheduler>,
|
pub scheduler: Arc<scheduler::Scheduler>,
|
||||||
pub ip_salt: Pepper,
|
pub ip_salt: Pepper,
|
||||||
@@ -277,7 +275,6 @@ pub fn app_setup(
|
|||||||
redis_pool,
|
redis_pool,
|
||||||
clickhouse: clickhouse.clone(),
|
clickhouse: clickhouse.clone(),
|
||||||
file_host,
|
file_host,
|
||||||
cdn_config: web::Data::new(CdnConfig::from_env().unwrap()),
|
|
||||||
maxmind: web::Data::new(maxmind),
|
maxmind: web::Data::new(maxmind),
|
||||||
scheduler: Arc::new(scheduler),
|
scheduler: Arc::new(scheduler),
|
||||||
ip_salt,
|
ip_salt,
|
||||||
@@ -319,7 +316,6 @@ pub fn app_config(
|
|||||||
.app_data(web::Data::new(labrinth_config.pool.clone()))
|
.app_data(web::Data::new(labrinth_config.pool.clone()))
|
||||||
.app_data(web::Data::new(labrinth_config.ro_pool.clone()))
|
.app_data(web::Data::new(labrinth_config.ro_pool.clone()))
|
||||||
.app_data(web::Data::new(labrinth_config.file_host.clone()))
|
.app_data(web::Data::new(labrinth_config.file_host.clone()))
|
||||||
.app_data(labrinth_config.cdn_config.clone())
|
|
||||||
.app_data(web::Data::new(labrinth_config.search_config.clone()))
|
.app_data(web::Data::new(labrinth_config.search_config.clone()))
|
||||||
.app_data(web::Data::new(labrinth_config.gotenberg_client.clone()))
|
.app_data(web::Data::new(labrinth_config.gotenberg_client.clone()))
|
||||||
.app_data(labrinth_config.session_queue.clone())
|
.app_data(labrinth_config.session_queue.clone())
|
||||||
@@ -378,7 +374,6 @@ pub fn check_env_vars() -> bool {
|
|||||||
|
|
||||||
failed |= check_var::<String>("SITE_URL");
|
failed |= check_var::<String>("SITE_URL");
|
||||||
failed |= check_var::<String>("CDN_URL");
|
failed |= check_var::<String>("CDN_URL");
|
||||||
failed |= check_var::<String>("CDN_ALT_URL");
|
|
||||||
failed |= check_var::<String>("LABRINTH_ADMIN_KEY");
|
failed |= check_var::<String>("LABRINTH_ADMIN_KEY");
|
||||||
failed |= check_var::<String>("LABRINTH_EXTERNAL_NOTIFICATION_KEY");
|
failed |= check_var::<String>("LABRINTH_EXTERNAL_NOTIFICATION_KEY");
|
||||||
failed |= check_var::<String>("RATE_LIMIT_IGNORE_KEY");
|
failed |= check_var::<String>("RATE_LIMIT_IGNORE_KEY");
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use std::mem;
|
|||||||
use crate::database::models::loader_fields::VersionField;
|
use crate::database::models::loader_fields::VersionField;
|
||||||
use crate::database::models::project_item::{LinkUrl, ProjectQueryResult};
|
use crate::database::models::project_item::{LinkUrl, ProjectQueryResult};
|
||||||
use crate::database::models::version_item::VersionQueryResult;
|
use crate::database::models::version_item::VersionQueryResult;
|
||||||
use crate::file_hosting::CdnChoice;
|
|
||||||
use crate::models::ids::{
|
use crate::models::ids::{
|
||||||
OrganizationId, ProjectId, TeamId, ThreadId, VersionId,
|
OrganizationId, ProjectId, TeamId, ThreadId, VersionId,
|
||||||
};
|
};
|
||||||
@@ -703,8 +702,8 @@ where
|
|||||||
Ok(map)
|
Ok(map)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Version {
|
impl From<VersionQueryResult> for Version {
|
||||||
pub fn from(data: VersionQueryResult, cdn_choice: &CdnChoice) -> Self {
|
fn from(data: VersionQueryResult) -> Version {
|
||||||
let v = data.inner;
|
let v = data.inner;
|
||||||
Version {
|
Version {
|
||||||
id: v.id.into(),
|
id: v.id.into(),
|
||||||
@@ -732,7 +731,7 @@ impl Version {
|
|||||||
.files
|
.files
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|f| VersionFile {
|
.map(|f| VersionFile {
|
||||||
url: cdn_choice.transform_file_url(f.url),
|
url: f.url,
|
||||||
filename: f.filename,
|
filename: f.filename,
|
||||||
hashes: f.hashes,
|
hashes: f.hashes,
|
||||||
primary: f.primary,
|
primary: f.primary,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ use crate::database;
|
|||||||
use crate::database::models::notification_item::NotificationBuilder;
|
use crate::database::models::notification_item::NotificationBuilder;
|
||||||
use crate::database::models::thread_item::ThreadMessageBuilder;
|
use crate::database::models::thread_item::ThreadMessageBuilder;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::file_hosting::CdnChoice;
|
|
||||||
use crate::models::ids::ProjectId;
|
use crate::models::ids::ProjectId;
|
||||||
use crate::models::notifications::NotificationBody;
|
use crate::models::notifications::NotificationBody;
|
||||||
use crate::models::pack::{PackFile, PackFileHash, PackFormat};
|
use crate::models::pack::{PackFile, PackFileHash, PackFormat};
|
||||||
@@ -363,7 +362,6 @@ impl AutomatedModerationQueue {
|
|||||||
&None,
|
&None,
|
||||||
&pool,
|
&pool,
|
||||||
&redis,
|
&redis,
|
||||||
&CdnChoice::Default,
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use crate::auth::get_user_from_headers;
|
|||||||
use crate::database;
|
use crate::database;
|
||||||
use crate::database::models::legacy_loader_fields::MinecraftGameVersion;
|
use crate::database::models::legacy_loader_fields::MinecraftGameVersion;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::file_hosting::{CdnConfig, UseAltCdn};
|
|
||||||
use crate::models::pats::Scopes;
|
use crate::models::pats::Scopes;
|
||||||
use crate::models::projects::VersionType;
|
use crate::models::projects::VersionType;
|
||||||
use crate::queue::session::AuthQueue;
|
use crate::queue::session::AuthQueue;
|
||||||
@@ -38,8 +37,6 @@ pub async fn forge_updates(
|
|||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
const ERROR: &str = "The specified project does not exist!";
|
const ERROR: &str = "The specified project does not exist!";
|
||||||
|
|
||||||
@@ -85,7 +82,6 @@ pub async fn forge_updates(
|
|||||||
&user_option,
|
&user_option,
|
||||||
&pool,
|
&pool,
|
||||||
&redis,
|
&redis,
|
||||||
&cdn_config.make_choice(use_alt_cdn),
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
use crate::database::models::categories::LinkPlatform;
|
use crate::database::models::categories::LinkPlatform;
|
||||||
use crate::database::models::{project_item, version_item};
|
use crate::database::models::{project_item, version_item};
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::file_hosting::{CdnChoice, CdnConfig};
|
use crate::file_hosting::FileHost;
|
||||||
use crate::file_hosting::{FileHost, UseAltCdn};
|
|
||||||
use crate::models::projects::{
|
use crate::models::projects::{
|
||||||
Link, MonetizationStatus, Project, ProjectStatus, SearchRequest, Version,
|
Link, MonetizationStatus, Project, ProjectStatus, SearchRequest, Version,
|
||||||
};
|
};
|
||||||
@@ -268,8 +267,6 @@ pub async fn dependency_list(
|
|||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
// TODO: tests, probably
|
// TODO: tests, probably
|
||||||
let response = v3::projects::dependency_list(
|
let response = v3::projects::dependency_list(
|
||||||
@@ -278,8 +275,6 @@ pub async fn dependency_list(
|
|||||||
pool.clone(),
|
pool.clone(),
|
||||||
redis.clone(),
|
redis.clone(),
|
||||||
session_queue,
|
session_queue,
|
||||||
cdn_config,
|
|
||||||
use_alt_cdn,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.or_else(v2_reroute::flatten_404_error)?;
|
.or_else(v2_reroute::flatten_404_error)?;
|
||||||
@@ -551,7 +546,7 @@ pub async fn project_edit(
|
|||||||
version_item::DBVersion::get_many(&version_ids, &**pool, &redis)
|
version_item::DBVersion::get_many(&version_ids, &**pool, &redis)
|
||||||
.await?;
|
.await?;
|
||||||
for version in versions {
|
for version in versions {
|
||||||
let version = Version::from(version, &CdnChoice::Default);
|
let version = Version::from(version);
|
||||||
let mut fields = version.fields;
|
let mut fields = version.fields;
|
||||||
let (current_client_side, current_server_side) =
|
let (current_client_side, current_server_side) =
|
||||||
v2_reroute::convert_v3_side_types_to_v2_side_types(
|
v2_reroute::convert_v3_side_types_to_v2_side_types(
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use super::ApiError;
|
use super::ApiError;
|
||||||
use crate::database::ReadOnlyPgPool;
|
use crate::database::ReadOnlyPgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::file_hosting::{CdnConfig, UseAltCdn};
|
|
||||||
use crate::models::projects::{Project, Version, VersionType};
|
use crate::models::projects::{Project, Version, VersionType};
|
||||||
use crate::models::v2::projects::{LegacyProject, LegacyVersion};
|
use crate::models::v2::projects::{LegacyProject, LegacyVersion};
|
||||||
use crate::queue::session::AuthQueue;
|
use crate::queue::session::AuthQueue;
|
||||||
@@ -39,8 +38,6 @@ pub async fn get_version_from_hash(
|
|||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
hash_query: web::Query<HashQuery>,
|
hash_query: web::Query<HashQuery>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let response = v3::version_file::get_version_from_hash(
|
let response = v3::version_file::get_version_from_hash(
|
||||||
req,
|
req,
|
||||||
@@ -49,8 +46,6 @@ pub async fn get_version_from_hash(
|
|||||||
redis,
|
redis,
|
||||||
hash_query,
|
hash_query,
|
||||||
session_queue,
|
session_queue,
|
||||||
cdn_config,
|
|
||||||
use_alt_cdn,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.or_else(v2_reroute::flatten_404_error)?;
|
.or_else(v2_reroute::flatten_404_error)?;
|
||||||
@@ -74,7 +69,6 @@ pub async fn download_version(
|
|||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
hash_query: web::Query<HashQuery>,
|
hash_query: web::Query<HashQuery>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
// Returns TemporaryRedirect, so no need to convert to V2
|
// Returns TemporaryRedirect, so no need to convert to V2
|
||||||
v3::version_file::download_version(
|
v3::version_file::download_version(
|
||||||
@@ -84,7 +78,6 @@ pub async fn download_version(
|
|||||||
redis,
|
redis,
|
||||||
hash_query,
|
hash_query,
|
||||||
session_queue,
|
session_queue,
|
||||||
use_alt_cdn,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.or_else(v2_reroute::flatten_404_error)
|
.or_else(v2_reroute::flatten_404_error)
|
||||||
@@ -129,8 +122,6 @@ pub async fn get_update_from_hash(
|
|||||||
hash_query: web::Query<HashQuery>,
|
hash_query: web::Query<HashQuery>,
|
||||||
update_data: web::Json<UpdateData>,
|
update_data: web::Json<UpdateData>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let update_data = update_data.into_inner();
|
let update_data = update_data.into_inner();
|
||||||
let mut loader_fields = HashMap::new();
|
let mut loader_fields = HashMap::new();
|
||||||
@@ -155,8 +146,6 @@ pub async fn get_update_from_hash(
|
|||||||
hash_query,
|
hash_query,
|
||||||
web::Json(update_data),
|
web::Json(update_data),
|
||||||
session_queue,
|
session_queue,
|
||||||
cdn_config,
|
|
||||||
use_alt_cdn,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.or_else(v2_reroute::flatten_404_error)?;
|
.or_else(v2_reroute::flatten_404_error)?;
|
||||||
@@ -186,8 +175,6 @@ pub async fn get_versions_from_hashes(
|
|||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
file_data: web::Json<FileHashes>,
|
file_data: web::Json<FileHashes>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let file_data = file_data.into_inner();
|
let file_data = file_data.into_inner();
|
||||||
let file_data = v3::version_file::FileHashes {
|
let file_data = v3::version_file::FileHashes {
|
||||||
@@ -200,8 +187,6 @@ pub async fn get_versions_from_hashes(
|
|||||||
redis,
|
redis,
|
||||||
web::Json(file_data),
|
web::Json(file_data),
|
||||||
session_queue,
|
session_queue,
|
||||||
cdn_config,
|
|
||||||
use_alt_cdn,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.or_else(v2_reroute::flatten_404_error)?;
|
.or_else(v2_reroute::flatten_404_error)?;
|
||||||
@@ -296,8 +281,6 @@ pub async fn update_files(
|
|||||||
pool: web::Data<ReadOnlyPgPool>,
|
pool: web::Data<ReadOnlyPgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
update_data: web::Json<ManyUpdateData>,
|
update_data: web::Json<ManyUpdateData>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let update_data = update_data.into_inner();
|
let update_data = update_data.into_inner();
|
||||||
let update_data = v3::version_file::ManyUpdateData {
|
let update_data = v3::version_file::ManyUpdateData {
|
||||||
@@ -308,13 +291,8 @@ pub async fn update_files(
|
|||||||
hashes: update_data.hashes,
|
hashes: update_data.hashes,
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = v3::version_file::update_files(
|
let response =
|
||||||
pool,
|
v3::version_file::update_files(pool, redis, web::Json(update_data))
|
||||||
redis,
|
|
||||||
web::Json(update_data),
|
|
||||||
cdn_config,
|
|
||||||
use_alt_cdn,
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.or_else(v2_reroute::flatten_404_error)?;
|
.or_else(v2_reroute::flatten_404_error)?;
|
||||||
|
|
||||||
@@ -357,8 +335,6 @@ pub async fn update_individual_files(
|
|||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
update_data: web::Json<ManyFileUpdateData>,
|
update_data: web::Json<ManyFileUpdateData>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let update_data = update_data.into_inner();
|
let update_data = update_data.into_inner();
|
||||||
let update_data = v3::version_file::ManyFileUpdateData {
|
let update_data = v3::version_file::ManyFileUpdateData {
|
||||||
@@ -392,8 +368,6 @@ pub async fn update_individual_files(
|
|||||||
redis,
|
redis,
|
||||||
web::Json(update_data),
|
web::Json(update_data),
|
||||||
session_queue,
|
session_queue,
|
||||||
cdn_config,
|
|
||||||
use_alt_cdn,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.or_else(v2_reroute::flatten_404_error)?;
|
.or_else(v2_reroute::flatten_404_error)?;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use super::ApiError;
|
use super::ApiError;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::file_hosting::{CdnConfig, UseAltCdn};
|
|
||||||
use crate::models;
|
use crate::models;
|
||||||
use crate::models::ids::VersionId;
|
use crate::models::ids::VersionId;
|
||||||
use crate::models::projects::{
|
use crate::models::projects::{
|
||||||
@@ -48,8 +47,6 @@ pub async fn version_list(
|
|||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let loaders = if let Some(loaders) = filters.loaders {
|
let loaders = if let Some(loaders) = filters.loaders {
|
||||||
if let Ok(mut loaders) = serde_json::from_str::<Vec<String>>(&loaders) {
|
if let Ok(mut loaders) = serde_json::from_str::<Vec<String>>(&loaders) {
|
||||||
@@ -107,8 +104,6 @@ pub async fn version_list(
|
|||||||
pool,
|
pool,
|
||||||
redis,
|
redis,
|
||||||
session_queue,
|
session_queue,
|
||||||
cdn_config,
|
|
||||||
use_alt_cdn,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.or_else(v2_reroute::flatten_404_error)?;
|
.or_else(v2_reroute::flatten_404_error)?;
|
||||||
@@ -134,8 +129,6 @@ pub async fn version_project_get(
|
|||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let id = info.into_inner();
|
let id = info.into_inner();
|
||||||
let response = v3::versions::version_project_get_helper(
|
let response = v3::versions::version_project_get_helper(
|
||||||
@@ -144,8 +137,6 @@ pub async fn version_project_get(
|
|||||||
pool,
|
pool,
|
||||||
redis,
|
redis,
|
||||||
session_queue,
|
session_queue,
|
||||||
cdn_config,
|
|
||||||
use_alt_cdn,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.or_else(v2_reroute::flatten_404_error)?;
|
.or_else(v2_reroute::flatten_404_error)?;
|
||||||
@@ -171,8 +162,6 @@ pub async fn versions_get(
|
|||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let ids = v3::versions::VersionIds { ids: ids.ids };
|
let ids = v3::versions::VersionIds { ids: ids.ids };
|
||||||
let response = v3::versions::versions_get(
|
let response = v3::versions::versions_get(
|
||||||
@@ -181,8 +170,6 @@ pub async fn versions_get(
|
|||||||
pool,
|
pool,
|
||||||
redis,
|
redis,
|
||||||
session_queue,
|
session_queue,
|
||||||
cdn_config,
|
|
||||||
use_alt_cdn,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.or_else(v2_reroute::flatten_404_error)?;
|
.or_else(v2_reroute::flatten_404_error)?;
|
||||||
@@ -207,19 +194,10 @@ pub async fn version_get(
|
|||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let id = info.into_inner().0;
|
let id = info.into_inner().0;
|
||||||
let response = v3::versions::version_get_helper(
|
let response =
|
||||||
req,
|
v3::versions::version_get_helper(req, id, pool, redis, session_queue)
|
||||||
id,
|
|
||||||
pool,
|
|
||||||
redis,
|
|
||||||
session_queue,
|
|
||||||
cdn_config,
|
|
||||||
use_alt_cdn,
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.or_else(v2_reroute::flatten_404_error)?;
|
.or_else(v2_reroute::flatten_404_error)?;
|
||||||
// Convert response to V2 format
|
// Convert response to V2 format
|
||||||
@@ -275,8 +253,6 @@ pub async fn version_edit(
|
|||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
new_version: web::Json<EditVersion>,
|
new_version: web::Json<EditVersion>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let new_version = new_version.into_inner();
|
let new_version = new_version.into_inner();
|
||||||
|
|
||||||
@@ -295,8 +271,6 @@ pub async fn version_edit(
|
|||||||
pool.clone(),
|
pool.clone(),
|
||||||
redis.clone(),
|
redis.clone(),
|
||||||
session_queue.clone(),
|
session_queue.clone(),
|
||||||
cdn_config,
|
|
||||||
use_alt_cdn,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.or_else(v2_reroute::flatten_404_error)?;
|
.or_else(v2_reroute::flatten_404_error)?;
|
||||||
|
|||||||
@@ -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::models::{DBTeamMember, ids as db_ids, image_item};
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::database::{self, models as db_models};
|
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;
|
||||||
use crate::models::ids::{ProjectId, VersionId};
|
use crate::models::ids::{ProjectId, VersionId};
|
||||||
use crate::models::images::ImageContext;
|
use crate::models::images::ImageContext;
|
||||||
@@ -1068,8 +1068,6 @@ pub async fn dependency_list(
|
|||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let string = info.into_inner().0;
|
let string = info.into_inner().0;
|
||||||
|
|
||||||
@@ -1138,7 +1136,6 @@ pub async fn dependency_list(
|
|||||||
&user_option,
|
&user_option,
|
||||||
&pool,
|
&pool,
|
||||||
&redis,
|
&redis,
|
||||||
&cdn_config.make_choice(use_alt_cdn),
|
|
||||||
)
|
)
|
||||||
.await?;
|
.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::auth::{filter_visible_projects, get_user_from_headers};
|
||||||
use crate::database::ReadOnlyPgPool;
|
use crate::database::ReadOnlyPgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::file_hosting::{CdnConfig, UseAltCdn};
|
|
||||||
use crate::models::ids::VersionId;
|
use crate::models::ids::VersionId;
|
||||||
use crate::models::pats::Scopes;
|
use crate::models::pats::Scopes;
|
||||||
use crate::models::projects::VersionType;
|
use crate::models::projects::VersionType;
|
||||||
@@ -42,8 +41,6 @@ pub async fn get_version_from_hash(
|
|||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
hash_query: web::Query<HashQuery>,
|
hash_query: web::Query<HashQuery>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let user_option = get_user_from_headers(
|
let user_option = get_user_from_headers(
|
||||||
&req,
|
&req,
|
||||||
@@ -78,10 +75,8 @@ pub async fn get_version_from_hash(
|
|||||||
return Err(ApiError::NotFound);
|
return Err(ApiError::NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(models::projects::Version::from(
|
Ok(HttpResponse::Ok()
|
||||||
version,
|
.json(models::projects::Version::from(version)))
|
||||||
&cdn_config.make_choice(use_alt_cdn),
|
|
||||||
)))
|
|
||||||
} else {
|
} else {
|
||||||
Err(ApiError::NotFound)
|
Err(ApiError::NotFound)
|
||||||
}
|
}
|
||||||
@@ -132,8 +127,6 @@ pub async fn get_update_from_hash(
|
|||||||
hash_query: web::Query<HashQuery>,
|
hash_query: web::Query<HashQuery>,
|
||||||
update_data: web::Json<UpdateData>,
|
update_data: web::Json<UpdateData>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let user_option = get_user_from_headers(
|
let user_option = get_user_from_headers(
|
||||||
&req,
|
&req,
|
||||||
@@ -202,12 +195,9 @@ pub async fn get_update_from_hash(
|
|||||||
return Err(ApiError::NotFound);
|
return Err(ApiError::NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(HttpResponse::Ok().json(
|
return Ok(
|
||||||
models::projects::Version::from(
|
HttpResponse::Ok().json(models::projects::Version::from(first))
|
||||||
first,
|
);
|
||||||
&cdn_config.make_choice(use_alt_cdn),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(ApiError::NotFound)
|
Err(ApiError::NotFound)
|
||||||
@@ -226,8 +216,6 @@ pub async fn get_versions_from_hashes(
|
|||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
file_data: web::Json<FileHashes>,
|
file_data: web::Json<FileHashes>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let user_option = get_user_from_headers(
|
let user_option = get_user_from_headers(
|
||||||
&req,
|
&req,
|
||||||
@@ -260,7 +248,6 @@ pub async fn get_versions_from_hashes(
|
|||||||
&user_option,
|
&user_option,
|
||||||
&pool,
|
&pool,
|
||||||
&redis,
|
&redis,
|
||||||
&cdn_config.make_choice(use_alt_cdn),
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -348,8 +335,6 @@ pub async fn update_files(
|
|||||||
pool: web::Data<ReadOnlyPgPool>,
|
pool: web::Data<ReadOnlyPgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
update_data: web::Json<ManyUpdateData>,
|
update_data: web::Json<ManyUpdateData>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let algorithm = update_data
|
let algorithm = update_data
|
||||||
.algorithm
|
.algorithm
|
||||||
@@ -407,11 +392,10 @@ pub async fn update_files(
|
|||||||
.find(|x| x.inner.project_id == file.project_id)
|
.find(|x| x.inner.project_id == file.project_id)
|
||||||
&& let Some(hash) = file.hashes.get(&algorithm)
|
&& let Some(hash) = file.hashes.get(&algorithm)
|
||||||
{
|
{
|
||||||
let version = models::projects::Version::from(
|
response.insert(
|
||||||
version.clone(),
|
hash.clone(),
|
||||||
&cdn_config.make_choice(use_alt_cdn),
|
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>,
|
redis: web::Data<RedisPool>,
|
||||||
update_data: web::Json<ManyFileUpdateData>,
|
update_data: web::Json<ManyFileUpdateData>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let user_option = get_user_from_headers(
|
let user_option = get_user_from_headers(
|
||||||
&req,
|
&req,
|
||||||
@@ -542,11 +524,10 @@ pub async fn update_individual_files(
|
|||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
let version = models::projects::Version::from(
|
response.insert(
|
||||||
version.clone(),
|
hash.clone(),
|
||||||
&cdn_config.make_choice(use_alt_cdn),
|
models::projects::Version::from(version.clone()),
|
||||||
);
|
);
|
||||||
response.insert(hash.clone(), version);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -693,7 +674,6 @@ pub async fn download_version(
|
|||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
hash_query: web::Query<HashQuery>,
|
hash_query: web::Query<HashQuery>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let user_option = get_user_from_headers(
|
let user_option = get_user_from_headers(
|
||||||
&req,
|
&req,
|
||||||
@@ -724,15 +704,6 @@ pub async fn download_version(
|
|||||||
database::models::DBVersion::get(file.version_id, &**pool, &redis)
|
database::models::DBVersion::get(file.version_id, &**pool, &redis)
|
||||||
.await?;
|
.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 let Some(version) = version {
|
||||||
if !is_visible_version(&version.inner, &user_option, &pool, &redis)
|
if !is_visible_version(&version.inner, &user_option, &pool, &redis)
|
||||||
.await?
|
.await?
|
||||||
@@ -741,8 +712,8 @@ pub async fn download_version(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(HttpResponse::TemporaryRedirect()
|
Ok(HttpResponse::TemporaryRedirect()
|
||||||
.append_header(("Location", &*url))
|
.append_header(("Location", &*file.url))
|
||||||
.json(DownloadRedirect { url }))
|
.json(DownloadRedirect { url: file.url }))
|
||||||
} else {
|
} else {
|
||||||
Err(ApiError::NotFound)
|
Err(ApiError::NotFound)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ use crate::database::models::version_item::{
|
|||||||
};
|
};
|
||||||
use crate::database::models::{DBOrganization, image_item};
|
use crate::database::models::{DBOrganization, image_item};
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::file_hosting::{CdnConfig, UseAltCdn};
|
|
||||||
use crate::models;
|
use crate::models;
|
||||||
use crate::models::ids::VersionId;
|
use crate::models::ids::VersionId;
|
||||||
use crate::models::images::ImageContext;
|
use crate::models::images::ImageContext;
|
||||||
@@ -62,30 +61,16 @@ pub async fn version_project_get(
|
|||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let info = info.into_inner();
|
let info = info.into_inner();
|
||||||
version_project_get_helper(
|
version_project_get_helper(req, info, pool, redis, session_queue).await
|
||||||
req,
|
|
||||||
info,
|
|
||||||
pool,
|
|
||||||
redis,
|
|
||||||
session_queue,
|
|
||||||
cdn_config,
|
|
||||||
use_alt_cdn,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn version_project_get_helper(
|
pub async fn version_project_get_helper(
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
id: (String, String),
|
id: (String, String),
|
||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let result =
|
let result =
|
||||||
database::models::DBProject::get(&id.0, &**pool, &redis).await?;
|
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)
|
&& is_visible_version(&version.inner, &user_option, &pool, &redis)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
return Ok(HttpResponse::Ok().json(
|
return Ok(HttpResponse::Ok()
|
||||||
models::projects::Version::from(
|
.json(models::projects::Version::from(version)));
|
||||||
version,
|
|
||||||
&cdn_config.make_choice(use_alt_cdn),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,8 +129,6 @@ pub async fn versions_get(
|
|||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let version_ids =
|
let version_ids =
|
||||||
serde_json::from_str::<Vec<models::ids::VersionId>>(&ids.ids)?
|
serde_json::from_str::<Vec<models::ids::VersionId>>(&ids.ids)?
|
||||||
@@ -171,13 +150,8 @@ pub async fn versions_get(
|
|||||||
.map(|x| x.1)
|
.map(|x| x.1)
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
let versions = filter_visible_versions(
|
let versions =
|
||||||
versions_data,
|
filter_visible_versions(versions_data, &user_option, &pool, &redis)
|
||||||
&user_option,
|
|
||||||
&pool,
|
|
||||||
&redis,
|
|
||||||
&cdn_config.make_choice(use_alt_cdn),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(versions))
|
Ok(HttpResponse::Ok().json(versions))
|
||||||
@@ -189,20 +163,9 @@ pub async fn version_get(
|
|||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
use_alt_cdn: UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let id = info.into_inner().0;
|
let id = info.into_inner().0;
|
||||||
version_get_helper(
|
version_get_helper(req, id, pool, redis, session_queue).await
|
||||||
req,
|
|
||||||
id,
|
|
||||||
pool,
|
|
||||||
redis,
|
|
||||||
session_queue,
|
|
||||||
cdn_config,
|
|
||||||
use_alt_cdn,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn version_get_helper(
|
pub async fn version_get_helper(
|
||||||
@@ -211,8 +174,6 @@ pub async fn version_get_helper(
|
|||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let version_data =
|
let version_data =
|
||||||
database::models::DBVersion::get(id.into(), &**pool, &redis).await?;
|
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
|
if let Some(data) = version_data
|
||||||
&& is_visible_version(&data.inner, &user_option, &pool, &redis).await?
|
&& is_visible_version(&data.inner, &user_option, &pool, &redis).await?
|
||||||
{
|
{
|
||||||
return Ok(HttpResponse::Ok().json(models::projects::Version::from(
|
return Ok(
|
||||||
data,
|
HttpResponse::Ok().json(models::projects::Version::from(data))
|
||||||
&cdn_config.make_choice(use_alt_cdn),
|
);
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(ApiError::NotFound)
|
Err(ApiError::NotFound)
|
||||||
@@ -764,8 +724,6 @@ pub async fn version_list(
|
|||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
redis: web::Data<RedisPool>,
|
redis: web::Data<RedisPool>,
|
||||||
session_queue: web::Data<AuthQueue>,
|
session_queue: web::Data<AuthQueue>,
|
||||||
cdn_config: web::Data<CdnConfig>,
|
|
||||||
UseAltCdn(use_alt_cdn): UseAltCdn,
|
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let string = info.into_inner().0;
|
let string = info.into_inner().0;
|
||||||
|
|
||||||
@@ -898,13 +856,8 @@ pub async fn version_list(
|
|||||||
});
|
});
|
||||||
response.dedup_by(|a, b| a.inner.id == b.inner.id);
|
response.dedup_by(|a, b| a.inner.id == b.inner.id);
|
||||||
|
|
||||||
let response = filter_visible_versions(
|
let response =
|
||||||
response,
|
filter_visible_versions(response, &user_option, &pool, &redis)
|
||||||
&user_option,
|
|
||||||
&pool,
|
|
||||||
&redis,
|
|
||||||
&cdn_config.make_choice(use_alt_cdn),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(response))
|
Ok(HttpResponse::Ok().json(response))
|
||||||
|
|||||||
Reference in New Issue
Block a user