Remove url field from shared instance routes
This commit is contained in:
parent
9e1f613aae
commit
b76d0fdcc3
@ -25,15 +25,13 @@ impl SharedInstance {
|
||||
instance: DBSharedInstance,
|
||||
users: Option<Vec<DBSharedInstanceUser>>,
|
||||
current_version: Option<DBSharedInstanceVersion>,
|
||||
cdn_url: &str,
|
||||
) -> Self {
|
||||
SharedInstance {
|
||||
id: instance.id.into(),
|
||||
title: instance.title,
|
||||
owner: instance.owner_id.into(),
|
||||
public: instance.public,
|
||||
current_version: current_version
|
||||
.map(|x| SharedInstanceVersion::from_db(x, cdn_url)),
|
||||
current_version: current_version.map(Into::into),
|
||||
additional_users: users
|
||||
.map(|x| x.into_iter().map(Into::into).collect()),
|
||||
}
|
||||
@ -46,23 +44,19 @@ pub struct SharedInstanceVersion {
|
||||
pub shared_instance: SharedInstanceId,
|
||||
pub size: u64,
|
||||
pub sha512: String,
|
||||
pub url: String,
|
||||
pub created: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl SharedInstanceVersion {
|
||||
pub fn from_db(version: DBSharedInstanceVersion, cdn_url: &str) -> Self {
|
||||
let version_id = version.id.into();
|
||||
let shared_instance_id = version.shared_instance_id.into();
|
||||
impl From<DBSharedInstanceVersion> for SharedInstanceVersion {
|
||||
fn from(value: DBSharedInstanceVersion) -> Self {
|
||||
let version_id = value.id.into();
|
||||
let shared_instance_id = value.shared_instance_id.into();
|
||||
SharedInstanceVersion {
|
||||
id: version_id,
|
||||
shared_instance: shared_instance_id,
|
||||
size: version.size,
|
||||
sha512: version.sha512.encode_hex(),
|
||||
created: version.created,
|
||||
url: format!(
|
||||
"{cdn_url}/shared_instance/{shared_instance_id}/{version_id}.mrpack"
|
||||
),
|
||||
size: value.size,
|
||||
sha512: value.sha512.encode_hex(),
|
||||
created: value.created,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,23 +3,21 @@ use crate::database::models::shared_instance_item::{
|
||||
DBSharedInstance, DBSharedInstanceUser, DBSharedInstanceVersion,
|
||||
};
|
||||
use crate::database::models::{
|
||||
DBSharedInstanceId, DBSharedInstanceVersionId,
|
||||
generate_shared_instance_version_id,
|
||||
generate_shared_instance_version_id, DBSharedInstanceId,
|
||||
DBSharedInstanceVersionId,
|
||||
};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::file_hosting::{FileHost, FileHostPublicity};
|
||||
use crate::models::ids::{SharedInstanceId, SharedInstanceVersionId};
|
||||
use crate::models::pats::Scopes;
|
||||
use crate::models::shared_instances::{
|
||||
SharedInstanceUserPermissions, SharedInstanceVersion,
|
||||
};
|
||||
use crate::models::shared_instances::{SharedInstanceUserPermissions, SharedInstanceVersion};
|
||||
use crate::queue::session::AuthQueue;
|
||||
use crate::routes::ApiError;
|
||||
use crate::routes::v3::project_creation::UploadedFile;
|
||||
use crate::routes::ApiError;
|
||||
use crate::util::ext::MRPACK_MIME_TYPE;
|
||||
use actix_web::http::header::ContentLength;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::{HttpRequest, HttpResponse, web};
|
||||
use actix_web::{web, HttpRequest, HttpResponse};
|
||||
use bytes::BytesMut;
|
||||
use chrono::Utc;
|
||||
use futures_util::StreamExt;
|
||||
@ -45,7 +43,7 @@ pub async fn shared_instance_version_create(
|
||||
web::Header(ContentLength(content_length)): web::Header<ContentLength>,
|
||||
redis: Data<RedisPool>,
|
||||
file_host: Data<Arc<dyn FileHost + Send + Sync>>,
|
||||
info: web::Path<(crate::models::ids::SharedInstanceId,)>,
|
||||
info: web::Path<(SharedInstanceId,)>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
if content_length > MAX_FILE_SIZE {
|
||||
@ -103,8 +101,6 @@ async fn shared_instance_version_create_inner(
|
||||
transaction: &mut Transaction<'_, Postgres>,
|
||||
uploaded_files: &mut Vec<UploadedFile>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let cdn_url = dotenvy::var("CDN_URL")?;
|
||||
|
||||
let user = get_user_from_headers(
|
||||
&req,
|
||||
pool,
|
||||
@ -198,6 +194,6 @@ async fn shared_instance_version_create_inner(
|
||||
.execute(&mut **transaction)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::Created()
|
||||
.json(SharedInstanceVersion::from_db(new_version, &cdn_url)))
|
||||
let version: SharedInstanceVersion = new_version.into();
|
||||
Ok(HttpResponse::Created().json(version))
|
||||
}
|
||||
|
@ -102,8 +102,6 @@ pub async fn shared_instance_list(
|
||||
redis: Data<RedisPool>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let cdn_url = dotenvy::var("CDN_URL")?;
|
||||
|
||||
let user = get_user_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
@ -137,7 +135,6 @@ pub async fn shared_instance_list(
|
||||
.await?,
|
||||
),
|
||||
version,
|
||||
&cdn_url,
|
||||
))
|
||||
},
|
||||
))
|
||||
@ -185,12 +182,10 @@ pub async fn shared_instance_get(
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let cdn_url = dotenvy::var("CDN_URL")?;
|
||||
let shared_instance = SharedInstance::from_db(
|
||||
shared_instance,
|
||||
privately_accessible.then_some(users),
|
||||
current_version,
|
||||
&cdn_url,
|
||||
);
|
||||
|
||||
Ok(HttpResponse::Ok().json(shared_instance))
|
||||
@ -362,7 +357,6 @@ pub async fn shared_instance_version_list(
|
||||
info: web::Path<(SharedInstanceId,)>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let cdn_url = dotenvy::var("CDN_URL")?;
|
||||
let id = info.into_inner().0.into();
|
||||
|
||||
let user = get_maybe_user_from_headers(
|
||||
@ -393,8 +387,8 @@ pub async fn shared_instance_version_list(
|
||||
DBSharedInstanceVersion::get_for_instance(id, &**pool).await?;
|
||||
let versions = versions
|
||||
.into_iter()
|
||||
.map(|version| SharedInstanceVersion::from_db(version, &cdn_url))
|
||||
.collect::<Vec<_>>();
|
||||
.map(Into::into)
|
||||
.collect::<Vec<SharedInstanceVersion>>();
|
||||
|
||||
Ok(HttpResponse::Ok().json(versions))
|
||||
} else {
|
||||
@ -409,7 +403,6 @@ pub async fn shared_instance_version_get(
|
||||
info: web::Path<(SharedInstanceVersionId,)>,
|
||||
session_queue: Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let cdn_url = dotenvy::var("CDN_URL")?;
|
||||
let version_id = info.into_inner().0.into();
|
||||
|
||||
let user = get_maybe_user_from_headers(
|
||||
@ -422,20 +415,20 @@ pub async fn shared_instance_version_get(
|
||||
.await?
|
||||
.map(|(_, user)| user);
|
||||
|
||||
let shared_instance_version =
|
||||
let version =
|
||||
DBSharedInstanceVersion::get(version_id, &**pool).await?;
|
||||
|
||||
if let Some(shared_instance_version) = shared_instance_version {
|
||||
let shared_instance = DBSharedInstance::get(
|
||||
shared_instance_version.shared_instance_id,
|
||||
if let Some(version) = version {
|
||||
let instance = DBSharedInstance::get(
|
||||
version.shared_instance_id,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
if let Some(shared_instance) = shared_instance {
|
||||
if let Some(instance) = instance {
|
||||
if !can_access_instance_as_maybe_user(
|
||||
&pool,
|
||||
&redis,
|
||||
&shared_instance,
|
||||
&instance,
|
||||
user,
|
||||
)
|
||||
.await?
|
||||
@ -443,10 +436,7 @@ pub async fn shared_instance_version_get(
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
|
||||
let version = SharedInstanceVersion::from_db(
|
||||
shared_instance_version,
|
||||
&cdn_url,
|
||||
);
|
||||
let version: SharedInstanceVersion = version.into();
|
||||
Ok(HttpResponse::Ok().json(version))
|
||||
} else {
|
||||
Err(ApiError::NotFound)
|
||||
|
Loading…
x
Reference in New Issue
Block a user