run cargo fix for rust 2024 changes and rustfmt
Signed-off-by: June Clementine Strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
e97952b7f6
commit
a1e1f40ded
320 changed files with 2212 additions and 2039 deletions
|
@ -1,6 +1,6 @@
|
|||
#[cfg(feature = "blurhashing")]
|
||||
use conduwuit::config::BlurhashConfig as CoreBlurhashConfig;
|
||||
use conduwuit::{implement, Result};
|
||||
use conduwuit::{Result, implement};
|
||||
|
||||
use super::Service;
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use conduwuit::{
|
||||
debug, debug_info, err,
|
||||
utils::{str_from_bytes, stream::TryIgnore, string_from_bytes, ReadyExt},
|
||||
Err, Result,
|
||||
Err, Result, debug, debug_info, err,
|
||||
utils::{ReadyExt, str_from_bytes, stream::TryIgnore, string_from_bytes},
|
||||
};
|
||||
use database::{Database, Interfix, Map};
|
||||
use futures::StreamExt;
|
||||
use ruma::{http_headers::ContentDisposition, Mxc, OwnedMxcUri, UserId};
|
||||
use ruma::{Mxc, OwnedMxcUri, UserId, http_headers::ContentDisposition};
|
||||
|
||||
use super::{preview::UrlPreviewData, thumbnail::Dim};
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ use std::{
|
|||
};
|
||||
|
||||
use conduwuit::{
|
||||
debug, debug_info, debug_warn, error, info,
|
||||
utils::{stream::TryIgnore, ReadyExt},
|
||||
warn, Config, Result,
|
||||
Config, Result, debug, debug_info, debug_warn, error, info,
|
||||
utils::{ReadyExt, stream::TryIgnore},
|
||||
warn,
|
||||
};
|
||||
|
||||
use crate::Services;
|
||||
|
|
|
@ -8,13 +8,13 @@ mod thumbnail;
|
|||
use std::{path::PathBuf, sync::Arc, time::SystemTime};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use base64::{Engine as _, engine::general_purpose};
|
||||
use conduwuit::{
|
||||
debug, debug_error, debug_info, debug_warn, err, error, trace,
|
||||
Err, Result, Server, debug, debug_error, debug_info, debug_warn, err, error, trace,
|
||||
utils::{self, MutexMap},
|
||||
warn, Err, Result, Server,
|
||||
warn,
|
||||
};
|
||||
use ruma::{http_headers::ContentDisposition, Mxc, OwnedMxcUri, UserId};
|
||||
use ruma::{Mxc, OwnedMxcUri, UserId, http_headers::ContentDisposition};
|
||||
use tokio::{
|
||||
fs,
|
||||
io::{AsyncReadExt, AsyncWriteExt, BufReader},
|
||||
|
@ -22,7 +22,7 @@ use tokio::{
|
|||
|
||||
use self::data::{Data, Metadata};
|
||||
pub use self::thumbnail::Dim;
|
||||
use crate::{client, globals, sending, Dep};
|
||||
use crate::{Dep, client, globals, sending};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FileMeta {
|
||||
|
@ -105,22 +105,27 @@ impl Service {
|
|||
|
||||
/// Deletes a file in the database and from the media directory via an MXC
|
||||
pub async fn delete(&self, mxc: &Mxc<'_>) -> Result<()> {
|
||||
if let Ok(keys) = self.db.search_mxc_metadata_prefix(mxc).await {
|
||||
for key in keys {
|
||||
trace!(?mxc, "MXC Key: {key:?}");
|
||||
debug_info!(?mxc, "Deleting from filesystem");
|
||||
match self.db.search_mxc_metadata_prefix(mxc).await {
|
||||
| Ok(keys) => {
|
||||
for key in keys {
|
||||
trace!(?mxc, "MXC Key: {key:?}");
|
||||
debug_info!(?mxc, "Deleting from filesystem");
|
||||
|
||||
if let Err(e) = self.remove_media_file(&key).await {
|
||||
debug_error!(?mxc, "Failed to remove media file: {e}");
|
||||
if let Err(e) = self.remove_media_file(&key).await {
|
||||
debug_error!(?mxc, "Failed to remove media file: {e}");
|
||||
}
|
||||
|
||||
debug_info!(?mxc, "Deleting from database");
|
||||
self.db.delete_file_mxc(mxc).await;
|
||||
}
|
||||
|
||||
debug_info!(?mxc, "Deleting from database");
|
||||
self.db.delete_file_mxc(mxc).await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
Err!(Database(error!("Failed to find any media keys for MXC {mxc} in our database.")))
|
||||
Ok(())
|
||||
},
|
||||
| _ => {
|
||||
Err!(Database(error!(
|
||||
"Failed to find any media keys for MXC {mxc} in our database."
|
||||
)))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,22 +159,21 @@ impl Service {
|
|||
|
||||
/// Downloads a file.
|
||||
pub async fn get(&self, mxc: &Mxc<'_>) -> Result<Option<FileMeta>> {
|
||||
if let Ok(Metadata { content_disposition, content_type, key }) =
|
||||
self.db.search_file_metadata(mxc, &Dim::default()).await
|
||||
{
|
||||
let mut content = Vec::with_capacity(8192);
|
||||
let path = self.get_media_file(&key);
|
||||
BufReader::new(fs::File::open(path).await?)
|
||||
.read_to_end(&mut content)
|
||||
.await?;
|
||||
match self.db.search_file_metadata(mxc, &Dim::default()).await {
|
||||
| Ok(Metadata { content_disposition, content_type, key }) => {
|
||||
let mut content = Vec::with_capacity(8192);
|
||||
let path = self.get_media_file(&key);
|
||||
BufReader::new(fs::File::open(path).await?)
|
||||
.read_to_end(&mut content)
|
||||
.await?;
|
||||
|
||||
Ok(Some(FileMeta {
|
||||
content: Some(content),
|
||||
content_type,
|
||||
content_disposition,
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
Ok(Some(FileMeta {
|
||||
content: Some(content),
|
||||
content_type,
|
||||
content_disposition,
|
||||
}))
|
||||
},
|
||||
| _ => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
use std::time::SystemTime;
|
||||
|
||||
use conduwuit::{debug, Err, Result};
|
||||
use conduwuit::{Err, Result, debug};
|
||||
use conduwuit_core::implement;
|
||||
use ipaddress::IPAddress;
|
||||
use serde::Serialize;
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
use std::{fmt::Debug, time::Duration};
|
||||
|
||||
use conduwuit::{
|
||||
debug_warn, err, implement, utils::content_disposition::make_content_disposition, Err, Error,
|
||||
Result,
|
||||
Err, Error, Result, debug_warn, err, implement,
|
||||
utils::content_disposition::make_content_disposition,
|
||||
};
|
||||
use http::header::{HeaderValue, CONTENT_DISPOSITION, CONTENT_TYPE};
|
||||
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE, HeaderValue};
|
||||
use ruma::{
|
||||
Mxc, ServerName, UserId,
|
||||
api::{
|
||||
OutgoingRequest,
|
||||
client::{
|
||||
error::ErrorKind::{NotFound, Unrecognized},
|
||||
media,
|
||||
},
|
||||
federation,
|
||||
federation::authenticated_media::{Content, FileOrLocation},
|
||||
OutgoingRequest,
|
||||
},
|
||||
Mxc, ServerName, UserId,
|
||||
};
|
||||
|
||||
use super::{Dim, FileMeta};
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
async fn long_file_names_works() {
|
||||
use std::path::PathBuf;
|
||||
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use base64::{Engine as _, engine::general_purpose};
|
||||
|
||||
use super::*;
|
||||
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
|
||||
use std::{cmp, num::Saturating as Sat};
|
||||
|
||||
use conduwuit::{checked, err, implement, Result};
|
||||
use ruma::{http_headers::ContentDisposition, media::Method, Mxc, UInt, UserId};
|
||||
use conduwuit::{Result, checked, err, implement};
|
||||
use ruma::{Mxc, UInt, UserId, http_headers::ContentDisposition, media::Method};
|
||||
use tokio::{
|
||||
fs,
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
};
|
||||
|
||||
use super::{data::Metadata, FileMeta};
|
||||
use super::{FileMeta, data::Metadata};
|
||||
|
||||
/// Dimension specification for a thumbnail.
|
||||
#[derive(Debug)]
|
||||
|
@ -65,12 +65,12 @@ impl super::Service {
|
|||
// 0, 0 because that's the original file
|
||||
let dim = dim.normalized();
|
||||
|
||||
if let Ok(metadata) = self.db.search_file_metadata(mxc, &dim).await {
|
||||
self.get_thumbnail_saved(metadata).await
|
||||
} else if let Ok(metadata) = self.db.search_file_metadata(mxc, &Dim::default()).await {
|
||||
self.get_thumbnail_generate(mxc, &dim, metadata).await
|
||||
} else {
|
||||
Ok(None)
|
||||
match self.db.search_file_metadata(mxc, &dim).await {
|
||||
| Ok(metadata) => self.get_thumbnail_saved(metadata).await,
|
||||
| _ => match self.db.search_file_metadata(mxc, &Dim::default()).await {
|
||||
| Ok(metadata) => self.get_thumbnail_generate(mxc, &dim, metadata).await,
|
||||
| _ => Ok(None),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue