mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-20 17:11:19 +02:00
refactor: conforms to clippy 1.67 recommandations
This commit is contained in:
@@ -43,10 +43,10 @@ pub struct ScootalooConfig {
|
|||||||
/// Parses the TOML file into a Config Struct
|
/// Parses the TOML file into a Config Struct
|
||||||
pub fn parse_toml(toml_file: &str) -> Config {
|
pub fn parse_toml(toml_file: &str) -> Config {
|
||||||
let toml_config = read_to_string(toml_file)
|
let toml_config = read_to_string(toml_file)
|
||||||
.unwrap_or_else(|e| panic!("Cannot open config file {}: {}", toml_file, e));
|
.unwrap_or_else(|e| panic!("Cannot open config file {toml_file}: {e}"));
|
||||||
|
|
||||||
let config: Config = toml::from_str(&toml_config)
|
let config: Config = toml::from_str(&toml_config)
|
||||||
.unwrap_or_else(|e| panic!("Cannot parse TOML file {}: {}", toml_file, e));
|
.unwrap_or_else(|e| panic!("Cannot parse TOML file {toml_file}: {e}"));
|
||||||
|
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
@@ -30,12 +30,12 @@ impl Display for ScootalooError {
|
|||||||
|
|
||||||
impl From<Box<dyn Error>> for ScootalooError {
|
impl From<Box<dyn Error>> for ScootalooError {
|
||||||
fn from(error: Box<dyn Error>) -> Self {
|
fn from(error: Box<dyn Error>) -> Self {
|
||||||
ScootalooError::new(&format!("Error in a subset crate: {}", error))
|
ScootalooError::new(&format!("Error in a subset crate: {error}"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<megalodonError> for ScootalooError {
|
impl From<megalodonError> for ScootalooError {
|
||||||
fn from(error: megalodonError) -> Self {
|
fn from(error: megalodonError) -> Self {
|
||||||
ScootalooError::new(&format!("Error in megalodon crate: {}", error))
|
ScootalooError::new(&format!("Error in megalodon crate: {error}"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -235,8 +235,8 @@ pub async fn run(config: Config) {
|
|||||||
// launch and wait for every handle
|
// launch and wait for every handle
|
||||||
while let Some(result) = stream.next().await {
|
while let Some(result) = stream.next().await {
|
||||||
match result {
|
match result {
|
||||||
Ok(Err(e)) => eprintln!("Error within thread: {}", e),
|
Ok(Err(e)) => eprintln!("Error within thread: {e}"),
|
||||||
Err(e) => eprintln!("Error with thread: {}", e),
|
Err(e) => eprintln!("Error with thread: {e}"),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -304,8 +304,8 @@ pub async fn profile(config: Config, bot: Option<bool>) {
|
|||||||
|
|
||||||
while let Some(result) = stream.next().await {
|
while let Some(result) = stream.next().await {
|
||||||
match result {
|
match result {
|
||||||
Ok(Err(e)) => eprintln!("Error within thread: {}", e),
|
Ok(Err(e)) => eprintln!("Error within thread: {e}"),
|
||||||
Err(e) => eprintln!("Error with thread: {}", e),
|
Err(e) => eprintln!("Error with thread: {e}"),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -83,7 +83,7 @@ pub fn associate_urls(urls: &[UrlEntity], re: &Option<Regex>) -> HashMap<String,
|
|||||||
pub fn replace_alt_services(urls: &mut HashMap<String, String>, alts: &HashMap<String, String>) {
|
pub fn replace_alt_services(urls: &mut HashMap<String, String>, alts: &HashMap<String, String>) {
|
||||||
for val in urls.values_mut() {
|
for val in urls.values_mut() {
|
||||||
for (k, v) in alts {
|
for (k, v) in alts {
|
||||||
*val = val.replace(&format!("/{}/", k), &format!("/{}/", v));
|
*val = val.replace(&format!("/{k}/"), &format!("/{v}/"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ pub fn replace_tweet_by_toot(
|
|||||||
twitter_screen_name.to_lowercase(),
|
twitter_screen_name.to_lowercase(),
|
||||||
tweet_id
|
tweet_id
|
||||||
)) {
|
)) {
|
||||||
*val = format!("{}/@{}/{}", base_url, mastodon_screen_name, toot_id);
|
*val = format!("{base_url}/@{mastodon_screen_name}/{toot_id}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,7 +184,7 @@ pub async fn register(host: &str, screen_name: &str) {
|
|||||||
|
|
||||||
let url = app_data.url.expect("Cannot generate registration URI!");
|
let url = app_data.url.expect("Cannot generate registration URI!");
|
||||||
|
|
||||||
println!("Click this link to authorize on Mastodon: {}", url);
|
println!("Click this link to authorize on Mastodon: {url}");
|
||||||
println!("Paste the returned authorization code: ");
|
println!("Paste the returned authorization code: ");
|
||||||
|
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
|
@@ -21,8 +21,8 @@ pub fn read_state(
|
|||||||
) -> Result<Option<TweetToToot>, Box<dyn Error>> {
|
) -> Result<Option<TweetToToot>, Box<dyn Error>> {
|
||||||
debug!("Reading tweet_id {:?}", s);
|
debug!("Reading tweet_id {:?}", s);
|
||||||
let query: String = match s {
|
let query: String = match s {
|
||||||
Some(i) => format!("SELECT * FROM tweet_to_toot WHERE tweet_id = {} and twitter_screen_name = \"{}\"", i, n),
|
Some(i) => format!("SELECT * FROM tweet_to_toot WHERE tweet_id = {i} and twitter_screen_name = \"{n}\""),
|
||||||
None => format!("SELECT * FROM tweet_to_toot WHERE twitter_screen_name = \"{}\" ORDER BY tweet_id DESC LIMIT 1", n),
|
None => format!("SELECT * FROM tweet_to_toot WHERE twitter_screen_name = \"{n}\" ORDER BY tweet_id DESC LIMIT 1"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut stmt = conn.prepare(&query)?;
|
let mut stmt = conn.prepare(&query)?;
|
||||||
@@ -78,8 +78,7 @@ pub fn migrate_db(d: &str, s: &str) -> Result<(), Box<dyn Error>> {
|
|||||||
&format!(
|
&format!(
|
||||||
"ALTER TABLE tweet_to_toot
|
"ALTER TABLE tweet_to_toot
|
||||||
ADD COLUMN twitter_screen_name TEXT NOT NULL
|
ADD COLUMN twitter_screen_name TEXT NOT NULL
|
||||||
DEFAULT \"{}\"",
|
DEFAULT \"{s}\""
|
||||||
s
|
|
||||||
),
|
),
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
12
src/util.rs
12
src/util.rs
@@ -112,12 +112,12 @@ pub async fn base64_media(u: &str) -> Result<String, Box<dyn Error>> {
|
|||||||
let content_type = response
|
let content_type = response
|
||||||
.headers()
|
.headers()
|
||||||
.get("content-type")
|
.get("content-type")
|
||||||
.ok_or_else(|| ScootalooError::new(&format!("Cannot get media content type for {}", u)))?
|
.ok_or_else(|| ScootalooError::new(&format!("Cannot get media content type for {u}")))?
|
||||||
.to_str()?;
|
.to_str()?;
|
||||||
|
|
||||||
let encoded_f = encode(buffer);
|
let encoded_f = encode(buffer);
|
||||||
|
|
||||||
Ok(format!("data:{};base64,{}", content_type, encoded_f))
|
Ok(format!("data:{content_type};base64,{encoded_f}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets and caches Twitter Media inside the determined temp dir
|
/// Gets and caches Twitter Media inside the determined temp dir
|
||||||
@@ -134,19 +134,17 @@ pub async fn cache_media(u: &str, t: &str) -> Result<String, Box<dyn Error>> {
|
|||||||
.path_segments()
|
.path_segments()
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
ScootalooError::new(&format!(
|
ScootalooError::new(&format!(
|
||||||
"Cannot determine the destination filename for {}",
|
"Cannot determine the destination filename for {u}"
|
||||||
u
|
|
||||||
))
|
))
|
||||||
})?
|
})?
|
||||||
.last()
|
.last()
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
ScootalooError::new(&format!(
|
ScootalooError::new(&format!(
|
||||||
"Cannot determine the destination filename for {}",
|
"Cannot determine the destination filename for {u}"
|
||||||
u
|
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let dest_filepath = format!("{}/{}", t, dest_filename);
|
let dest_filepath = format!("{t}/{dest_filename}");
|
||||||
|
|
||||||
let mut dest_file = File::create(&dest_filepath).await?;
|
let mut dest_file = File::create(&dest_filepath).await?;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user