feat(core): validation for files in reference db

This commit is contained in:
Paul Makles
2023-10-16 09:22:53 +01:00
parent 4d42fb74e7
commit 7132877201

View File

@@ -22,15 +22,25 @@ impl AbstractAttachments for ReferenceDb {
async fn find_and_use_attachment( async fn find_and_use_attachment(
&self, &self,
id: &str, id: &str,
_tag: &str, tag: &str,
_parent_type: &str, parent_type: &str,
_parent_id: &str, parent_id: &str,
) -> Result<File> { ) -> Result<File> {
let mut files = self.files.lock().await; let mut files = self.files.lock().await;
if let Some(file) = files.get_mut(id) { if let Some(file) = files.get_mut(id) {
// TODO: check tag if file.tag == tag {
// TODO: set parent ID match parent_type {
Ok(file.clone()) "message" => file.message_id = Some(parent_id.to_owned()),
"user" => file.user_id = Some(parent_id.to_owned()),
"object" => file.object_id = Some(parent_id.to_owned()),
"server" => file.server_id = Some(parent_id.to_owned()),
_ => unreachable!(),
}
Ok(file.clone())
} else {
Err(create_error!(NotFound))
}
} else { } else {
Err(create_error!(NotFound)) Err(create_error!(NotFound))
} }