Fix edge case where multiple attachments
This commit is contained in:
parent
fcb7dda20d
commit
e3d85efe96
1 changed files with 7 additions and 5 deletions
|
@ -91,11 +91,11 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
||||||
};
|
};
|
||||||
let author = ctx.author();
|
let author = ctx.author();
|
||||||
let mut submitted_images = Vec::new();
|
let mut submitted_images = Vec::new();
|
||||||
for (i, submission) in submission_data.iter_mut().enumerate() {
|
for submission in submission_data.iter_mut() {
|
||||||
if is_matching_submission(&submission, author) {
|
if is_matching_submission(&submission, author) {
|
||||||
existing_submitter = true;
|
existing_submitter = true;
|
||||||
let mut images: Vec<String> = submission["images"].as_array_mut().unwrap().clone().iter().map(|value| value.as_str().unwrap().to_owned()).collect();
|
let mut images: Vec<String> = submission["images"].as_array_mut().unwrap().clone().iter().map(|value| value.as_str().unwrap().to_owned()).collect();
|
||||||
for attachment in attachments.iter() {
|
for (i, attachment) in attachments.iter().enumerate() {
|
||||||
let extension;
|
let extension;
|
||||||
if let Some(content_type) = &attachment.content_type {
|
if let Some(content_type) = &attachment.content_type {
|
||||||
if content_type == "image/png" {
|
if content_type == "image/png" {
|
||||||
|
@ -112,11 +112,12 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
||||||
}
|
}
|
||||||
requires_rebuild = true;
|
requires_rebuild = true;
|
||||||
let file_name = format!(
|
let file_name = format!(
|
||||||
"{}-{}-{}-{}.{}",
|
"{}-{}-{}-{}{}.{}",
|
||||||
i + 1,
|
i + 1,
|
||||||
slugify(&author.name),
|
slugify(&author.name),
|
||||||
author.discriminator,
|
author.discriminator,
|
||||||
timestamp,
|
timestamp,
|
||||||
|
if i == 0 { "".to_owned() } else { format!("-{}", i + 1) },
|
||||||
extension
|
extension
|
||||||
);
|
);
|
||||||
images.push(file_name.clone().into());
|
images.push(file_name.clone().into());
|
||||||
|
@ -138,7 +139,7 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
||||||
format!("{}#{}", author.name, author.discriminator).into(),
|
format!("{}#{}", author.name, author.discriminator).into(),
|
||||||
);
|
);
|
||||||
let mut images: Vec<String> = Vec::new();
|
let mut images: Vec<String> = Vec::new();
|
||||||
for attachment in attachments.iter() {
|
for (i, attachment) in attachments.iter().enumerate() {
|
||||||
let extension;
|
let extension;
|
||||||
if let Some(content_type) = &attachment.content_type {
|
if let Some(content_type) = &attachment.content_type {
|
||||||
if content_type == "image/png" {
|
if content_type == "image/png" {
|
||||||
|
@ -155,11 +156,12 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
||||||
}
|
}
|
||||||
requires_rebuild = true;
|
requires_rebuild = true;
|
||||||
let file_name = format!(
|
let file_name = format!(
|
||||||
"{}-{}-{}-{}.{}",
|
"{}-{}-{}-{}{}.{}",
|
||||||
submission_data.len() + 1,
|
submission_data.len() + 1,
|
||||||
slugify(&author.name),
|
slugify(&author.name),
|
||||||
author.discriminator,
|
author.discriminator,
|
||||||
timestamp,
|
timestamp,
|
||||||
|
if i == 0 { "".to_owned() } else { format!("-{}", i + 1) },
|
||||||
extension
|
extension
|
||||||
);
|
);
|
||||||
images.push(file_name.clone().into());
|
images.push(file_name.clone().into());
|
||||||
|
|
Loading…
Add table
Reference in a new issue