Remove old/redundant code from attachment.rs
This commit is contained in:
parent
fcd405939f
commit
24cec523e0
|
@ -36,7 +36,7 @@ impl Message {
|
||||||
chorus_request.deserialize_response::<Message>(user).await
|
chorus_request.deserialize_response::<Message>(user).await
|
||||||
} else {
|
} else {
|
||||||
for (index, attachment) in message.attachments.iter_mut().enumerate() {
|
for (index, attachment) in message.attachments.iter_mut().enumerate() {
|
||||||
attachment.get_mut(index).unwrap().set_id(index as i16);
|
attachment.get_mut(index).unwrap().id = Some(index as i16);
|
||||||
}
|
}
|
||||||
let mut form = reqwest::multipart::Form::new();
|
let mut form = reqwest::multipart::Form::new();
|
||||||
let payload_json = to_string(&message).unwrap();
|
let payload_json = to_string(&message).unwrap();
|
||||||
|
@ -45,8 +45,8 @@ impl Message {
|
||||||
form = form.part("payload_json", payload_field);
|
form = form.part("payload_json", payload_field);
|
||||||
|
|
||||||
for (index, attachment) in message.attachments.unwrap().into_iter().enumerate() {
|
for (index, attachment) in message.attachments.unwrap().into_iter().enumerate() {
|
||||||
let (attachment_content, current_attachment) = attachment.move_content();
|
let attachment_content = attachment.content;
|
||||||
let (attachment_filename, _) = current_attachment.move_filename();
|
let attachment_filename = attachment.filename;
|
||||||
let part_name = format!("files[{}]", index);
|
let part_name = format!("files[{}]", index);
|
||||||
let content_disposition = format!(
|
let content_disposition = format!(
|
||||||
"form-data; name=\"{}\"'; filename=\"{}\"",
|
"form-data; name=\"{}\"'; filename=\"{}\"",
|
||||||
|
|
|
@ -55,73 +55,3 @@ pub struct PartialDiscordFileAttachment {
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
pub content: Vec<u8>,
|
pub content: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialDiscordFileAttachment {
|
|
||||||
/// Moves `self.content` out of `self` and returns it.
|
|
||||||
pub fn move_content(self) -> (Vec<u8>, PartialDiscordFileAttachment) {
|
|
||||||
let content = self.content;
|
|
||||||
let updated_struct = PartialDiscordFileAttachment {
|
|
||||||
id: self.id,
|
|
||||||
filename: self.filename,
|
|
||||||
description: self.description,
|
|
||||||
content_type: self.content_type,
|
|
||||||
size: self.size,
|
|
||||||
url: self.url,
|
|
||||||
proxy_url: self.proxy_url,
|
|
||||||
height: self.height,
|
|
||||||
width: self.width,
|
|
||||||
ephemeral: self.ephemeral,
|
|
||||||
duration_secs: self.duration_secs,
|
|
||||||
waveform: self.waveform,
|
|
||||||
content: Vec::new(),
|
|
||||||
};
|
|
||||||
(content, updated_struct)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Moves `self.filename` out of `self` and returns it.
|
|
||||||
pub fn move_filename(self) -> (String, PartialDiscordFileAttachment) {
|
|
||||||
let filename = self.filename;
|
|
||||||
let updated_struct = PartialDiscordFileAttachment {
|
|
||||||
id: self.id,
|
|
||||||
filename: String::new(),
|
|
||||||
description: self.description,
|
|
||||||
content_type: self.content_type,
|
|
||||||
size: self.size,
|
|
||||||
url: self.url,
|
|
||||||
proxy_url: self.proxy_url,
|
|
||||||
height: self.height,
|
|
||||||
width: self.width,
|
|
||||||
|
|
||||||
ephemeral: self.ephemeral,
|
|
||||||
duration_secs: self.duration_secs,
|
|
||||||
waveform: self.waveform,
|
|
||||||
content: self.content,
|
|
||||||
};
|
|
||||||
(filename, updated_struct)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Moves `self.content_type` out of `self` and returns it.
|
|
||||||
pub fn move_content_type(self) -> (Option<String>, PartialDiscordFileAttachment) {
|
|
||||||
let content_type = self.content_type;
|
|
||||||
let updated_struct = PartialDiscordFileAttachment {
|
|
||||||
id: self.id,
|
|
||||||
filename: self.filename,
|
|
||||||
description: self.description,
|
|
||||||
content_type: None,
|
|
||||||
size: self.size,
|
|
||||||
url: self.url,
|
|
||||||
proxy_url: self.proxy_url,
|
|
||||||
height: self.height,
|
|
||||||
width: self.width,
|
|
||||||
ephemeral: self.ephemeral,
|
|
||||||
duration_secs: self.duration_secs,
|
|
||||||
waveform: self.waveform,
|
|
||||||
content: self.content,
|
|
||||||
};
|
|
||||||
(content_type, updated_struct)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_id(&mut self, id: i16) {
|
|
||||||
self.id = Some(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue