You've already forked AstralRinth
forked from didirus/AstralRinth
Add gallery item deletion + making them optional (#224)
This commit is contained in:
@@ -846,6 +846,18 @@
|
|||||||
"nullable": []
|
"nullable": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"2162043897db26d0b55a0652c1a6db66c555f1d148ce69bd0bd0d2122de1bd6a": {
|
||||||
|
"query": "\n DELETE FROM mods_gallery\n WHERE mod_id = $1\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
}
|
||||||
|
},
|
||||||
"22185b4e3826d5ff4907b66b53ad3d0b64fb0904967c7e4d8d6aa5105b1486f5": {
|
"22185b4e3826d5ff4907b66b53ad3d0b64fb0904967c7e4d8d6aa5105b1486f5": {
|
||||||
"query": "\n SELECT n.id, n.user_id, n.title, n.text, n.link, n.created, n.read, n.type notification_type,\n STRING_AGG(DISTINCT na.id || ', ' || na.title || ', ' || na.action_route || ', ' || na.action_route_method, ' ,') actions\n FROM notifications n\n LEFT OUTER JOIN notifications_actions na on n.id = na.notification_id\n WHERE n.user_id = $1\n GROUP BY n.id, n.user_id;\n ",
|
"query": "\n SELECT n.id, n.user_id, n.title, n.text, n.link, n.created, n.read, n.type notification_type,\n STRING_AGG(DISTINCT na.id || ', ' || na.title || ', ' || na.action_route || ', ' || na.action_route_method, ' ,') actions\n FROM notifications n\n LEFT OUTER JOIN notifications_actions na on n.id = na.notification_id\n WHERE n.user_id = $1\n GROUP BY n.id, n.user_id;\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
|
|||||||
@@ -370,6 +370,16 @@ impl Project {
|
|||||||
.execute(&mut *transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
sqlx::query!(
|
||||||
|
"
|
||||||
|
DELETE FROM mods_gallery
|
||||||
|
WHERE mod_id = $1
|
||||||
|
",
|
||||||
|
id as ProjectId
|
||||||
|
)
|
||||||
|
.execute(&mut *transaction)
|
||||||
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
DELETE FROM mod_follows
|
DELETE FROM mod_follows
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ struct ProjectCreateData {
|
|||||||
|
|
||||||
#[validate(length(max = 64))]
|
#[validate(length(max = 64))]
|
||||||
/// The multipart names of the gallery items to upload
|
/// The multipart names of the gallery items to upload
|
||||||
pub gallery_items: Vec<String>,
|
pub gallery_items: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UploadedFile {
|
pub struct UploadedFile {
|
||||||
@@ -426,43 +426,45 @@ pub async fn project_create_inner(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if project_create_data
|
if let Some(gallery_items) = &project_create_data.gallery_items {
|
||||||
.gallery_items
|
if
|
||||||
.iter()
|
gallery_items
|
||||||
.find(|x| *x == name)
|
.iter()
|
||||||
.is_some()
|
.find(|x| *x == name)
|
||||||
{
|
.is_some()
|
||||||
let mut data = Vec::new();
|
{
|
||||||
while let Some(chunk) = field.next().await {
|
let mut data = Vec::new();
|
||||||
data.extend_from_slice(&chunk.map_err(CreateError::MultipartError)?);
|
while let Some(chunk) = field.next().await {
|
||||||
|
data.extend_from_slice(&chunk.map_err(CreateError::MultipartError)?);
|
||||||
|
}
|
||||||
|
|
||||||
|
const FILE_SIZE_CAP: usize = 5 * (1 << 20);
|
||||||
|
|
||||||
|
if data.len() >= FILE_SIZE_CAP {
|
||||||
|
return Err(CreateError::InvalidInput(String::from(
|
||||||
|
"Gallery image exceeds the maximum of 5MiB.",
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
let hash = sha1::Sha1::from(&data).hexdigest();
|
||||||
|
let (_, file_extension) = super::version_creation::get_name_ext(&content_disposition)?;
|
||||||
|
let content_type = crate::util::ext::get_image_content_type(file_extension)
|
||||||
|
.ok_or_else(|| CreateError::InvalidIconFormat(file_extension.to_string()))?;
|
||||||
|
|
||||||
|
let url = format!("data/{}/images/{}.{}", project_id, hash, file_extension);
|
||||||
|
let upload_data = file_host
|
||||||
|
.upload_file(content_type, &url, data.to_vec())
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
uploaded_files.push(UploadedFile {
|
||||||
|
file_id: upload_data.file_id,
|
||||||
|
file_name: upload_data.file_name.clone(),
|
||||||
|
});
|
||||||
|
|
||||||
|
gallery_urls.push(format!("{}/{}", cdn_url, url));
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FILE_SIZE_CAP: usize = 5 * (1 << 20);
|
|
||||||
|
|
||||||
if data.len() >= FILE_SIZE_CAP {
|
|
||||||
return Err(CreateError::InvalidInput(String::from(
|
|
||||||
"Gallery image exceeds the maximum of 5MiB.",
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
let hash = sha1::Sha1::from(&data).hexdigest();
|
|
||||||
let (_, file_extension) = super::version_creation::get_name_ext(&content_disposition)?;
|
|
||||||
let content_type = crate::util::ext::get_image_content_type(file_extension)
|
|
||||||
.ok_or_else(|| CreateError::InvalidIconFormat(file_extension.to_string()))?;
|
|
||||||
|
|
||||||
let url = format!("data/{}/images/{}.{}", project_id, hash, file_extension);
|
|
||||||
let upload_data = file_host
|
|
||||||
.upload_file(content_type, &url, data.to_vec())
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
uploaded_files.push(UploadedFile {
|
|
||||||
file_id: upload_data.file_id,
|
|
||||||
file_name: upload_data.file_name.clone(),
|
|
||||||
});
|
|
||||||
|
|
||||||
gallery_urls.push(format!("{}/{}", cdn_url, url));
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let index = if let Some(i) = versions_map.get(name) {
|
let index = if let Some(i) = versions_map.get(name) {
|
||||||
|
|||||||
Reference in New Issue
Block a user