mirror of
https://framagit.org/veretcle/oolatoocs.git
synced 2025-12-06 14:53:15 +01:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b21a0e3a7 | ||
|
|
43aa6dcd99 | ||
|
|
cf5fe11b56 | ||
|
|
7bd0843cf6 | ||
|
|
402fcffc75 | ||
|
|
b295cc5b94 | ||
|
|
a882aaa59d | ||
|
|
259032a7b9 | ||
|
|
e7f0c9c6f5 | ||
|
|
83c8da46e8 | ||
|
|
823f80729f | ||
|
|
5969e3a56a | ||
|
|
3ea2478512 | ||
|
|
5606d00da2 | ||
|
|
4cb80b0607 | ||
|
|
bbe14f1f30 | ||
|
|
6fbc011914 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
.last_tweet
|
.last_tweet
|
||||||
.config.toml
|
.config.toml
|
||||||
.config.json
|
.config.json
|
||||||
|
.bsky.json
|
||||||
|
|||||||
2115
Cargo.lock
generated
2115
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
12
Cargo.toml
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "oolatoocs"
|
name = "oolatoocs"
|
||||||
version = "4.1.3"
|
version = "4.4.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
@@ -8,22 +8,22 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "^0.4"
|
chrono = "^0.4"
|
||||||
clap = "^4"
|
clap = "^4"
|
||||||
env_logger = "^0.10"
|
env_logger = "^0.11"
|
||||||
futures = "^0.3"
|
futures = "^0.3"
|
||||||
html-escape = "^0.2"
|
html-escape = "^0.2"
|
||||||
log = "^0.4"
|
log = "^0.4"
|
||||||
megalodon = "^1.0"
|
|
||||||
oauth1-request = "^0.6"
|
oauth1-request = "^0.6"
|
||||||
regex = "^1.10"
|
regex = "^1.10"
|
||||||
reqwest = { version = "^0.11", features = ["json", "stream", "multipart"] }
|
reqwest = { version = "^0.12", features = ["json", "stream", "multipart"] }
|
||||||
rusqlite = { version = "^0.30", features = ["chrono"] }
|
rusqlite = { version = "^0.33", features = ["chrono"] }
|
||||||
serde = { version = "^1.0", features = ["derive"] }
|
serde = { version = "^1.0", features = ["derive"] }
|
||||||
tokio = { version = "^1.33", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "^1.33", features = ["rt-multi-thread", "macros"] }
|
||||||
toml = "^0.8"
|
toml = "^0.8"
|
||||||
bsky-sdk = "^0.1"
|
bsky-sdk = "^0.1"
|
||||||
atrium-api = "^0.24"
|
atrium-api = { version = "^0.25", features = ["namespace-appbsky"] }
|
||||||
image = "^0.25"
|
image = "^0.25"
|
||||||
webp = "^0.3"
|
webp = "^0.3"
|
||||||
|
megalodon = "1.0.*"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = true
|
strip = true
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ What it can do:
|
|||||||
* Cuts (poorly) the Toot in half in it’s too long for Bluesky and thread it (this is cut using a word count, not the best method, but it gets the job done);
|
* Cuts (poorly) the Toot in half in it’s too long for Bluesky and thread it (this is cut using a word count, not the best method, but it gets the job done);
|
||||||
* Reuploads images/gifs/videos from Mastodon to Bluesky
|
* Reuploads images/gifs/videos from Mastodon to Bluesky
|
||||||
* ⚠️ Bluesky does not support mixing images and videos. You can have up to 4 images on a Bsky record **or** 1 video but not mix around. If you do so, only the video will be posted on Bluesky.
|
* ⚠️ Bluesky does not support mixing images and videos. You can have up to 4 images on a Bsky record **or** 1 video but not mix around. If you do so, only the video will be posted on Bluesky.
|
||||||
* ⚠️ Bluesky does not support images greater than 1Mb (that is 1,000,000,000 bytes or 976.6 KiB). I might incorporate soon a image quality reducer or WebP transcoding to avoid this issue.
|
* ⚠️ Bluesky does not support images greater than 1Mb (that is 1,000,000 bytes or 976.6 KiB), so Oolatoocs converts the image to WebP and progressively reduces the quality to fit that limitation.
|
||||||
* Can reproduce threads from Mastodon to Bluesky
|
* Can reproduce threads from Mastodon to Bluesky
|
||||||
* ⚠️ Bluesky does support polls for now. So the poll itself is just presented as text from Mastodon instead which is not the most elegant.
|
* ⚠️ Bluesky does support polls for now. So the poll itself is just presented as text from Mastodon instead which is not the most elegant.
|
||||||
* Can prevent a Toot from being recorded to Bluesky by using the #NoTweet (case-insensitive) hashtag in Mastodon
|
* Can prevent a Toot from being recorded to Bluesky by using the #NoTweet (case-insensitive) hashtag in Mastodon
|
||||||
@@ -30,6 +30,7 @@ The configuration is relatively easy to follow:
|
|||||||
```toml
|
```toml
|
||||||
[oolatoocs]
|
[oolatoocs]
|
||||||
db_path = "/var/lib/oolatoocs/db.sqlite3" # the path to the DB where toots/tweets/records are stored
|
db_path = "/var/lib/oolatoocs/db.sqlite3" # the path to the DB where toots/tweets/records are stored
|
||||||
|
remove_hashtags = false # optional, default to false
|
||||||
|
|
||||||
[mastodon] # This part can be generated, see below
|
[mastodon] # This part can be generated, see below
|
||||||
base = "https://m.nintendojo.fr"
|
base = "https://m.nintendojo.fr"
|
||||||
|
|||||||
85
src/bsky.rs
85
src/bsky.rs
@@ -1,7 +1,7 @@
|
|||||||
use crate::config::BlueskyConfig;
|
use crate::config::BlueskyConfig;
|
||||||
use atrium_api::{
|
use atrium_api::{
|
||||||
app::bsky::feed::post::RecordData, com::atproto::repo::upload_blob::Output,
|
app::bsky::feed::post::RecordData, com::atproto::repo::upload_blob::Output,
|
||||||
types::string::Datetime, types::string::Language,
|
types::string::Datetime, types::string::Language, types::string::RecordKey,
|
||||||
};
|
};
|
||||||
use bsky_sdk::{
|
use bsky_sdk::{
|
||||||
agent::config::{Config, FileStore},
|
agent::config::{Config, FileStore},
|
||||||
@@ -11,7 +11,10 @@ use bsky_sdk::{
|
|||||||
use futures::{stream, StreamExt};
|
use futures::{stream, StreamExt};
|
||||||
use image::ImageReader;
|
use image::ImageReader;
|
||||||
use log::{debug, error, warn};
|
use log::{debug, error, warn};
|
||||||
use megalodon::entities::attachment::{Attachment, AttachmentType};
|
use megalodon::entities::{
|
||||||
|
attachment::{Attachment, AttachmentType},
|
||||||
|
card::Card,
|
||||||
|
};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::{error::Error, fs::exists, io::Cursor};
|
use std::{error::Error, fs::exists, io::Cursor};
|
||||||
use webp::*;
|
use webp::*;
|
||||||
@@ -136,7 +139,7 @@ async fn get_record(
|
|||||||
cid: None,
|
cid: None,
|
||||||
collection: atrium_api::types::string::Nsid::new("app.bsky.feed.post".to_string())?,
|
collection: atrium_api::types::string::Nsid::new("app.bsky.feed.post".to_string())?,
|
||||||
repo: atrium_api::types::string::Handle::new(config.to_string())?.into(),
|
repo: atrium_api::types::string::Handle::new(config.to_string())?.into(),
|
||||||
rkey: rkey.to_string(),
|
rkey: RecordKey::new(rkey.to_string())?,
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
)
|
)
|
||||||
@@ -145,7 +148,68 @@ async fn get_record(
|
|||||||
Ok(record)
|
Ok(record)
|
||||||
}
|
}
|
||||||
|
|
||||||
// it’s ugly af but it gets the job done for now
|
/// Generate an quote embed record into Bsky
|
||||||
|
pub async fn generate_quote_records(
|
||||||
|
config: &BlueskyConfig,
|
||||||
|
quote_id: &str,
|
||||||
|
) -> Option<atrium_api::types::Union<atrium_api::app::bsky::feed::post::RecordEmbedRefs>> {
|
||||||
|
// if we can’t match the quote_id, simply return None
|
||||||
|
let quote_record = match get_record(&config.handle, &rkey(quote_id)).await {
|
||||||
|
Ok(a) => a,
|
||||||
|
Err(_) => return None,
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(atrium_api::types::Union::Refs(
|
||||||
|
atrium_api::app::bsky::feed::post::RecordEmbedRefs::AppBskyEmbedRecordMain(Box::new(
|
||||||
|
atrium_api::app::bsky::embed::record::MainData {
|
||||||
|
record: atrium_api::com::atproto::repo::strong_ref::MainData {
|
||||||
|
cid: quote_record.data.cid.unwrap(),
|
||||||
|
uri: quote_record.data.uri.to_owned(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generate an embed card record into Bsky
|
||||||
|
/// If the preview image does not exist or fails to upload, it is simply ignored
|
||||||
|
pub async fn generate_embed_records(
|
||||||
|
bsky: &BskyAgent,
|
||||||
|
card: &Card,
|
||||||
|
) -> Option<atrium_api::types::Union<atrium_api::app::bsky::feed::post::RecordEmbedRefs>> {
|
||||||
|
// uploads the image card, if it fails, simply ignore everything
|
||||||
|
let blob = if let Some(url) = &card.image {
|
||||||
|
if let Ok(image_blob) = upload_media(true, bsky, url).await {
|
||||||
|
Some(image_blob.blob.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let record_card = atrium_api::app::bsky::embed::external::ExternalData {
|
||||||
|
description: card.description.clone(),
|
||||||
|
thumb: blob,
|
||||||
|
title: card.title.clone(),
|
||||||
|
uri: card.url.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(atrium_api::types::Union::Refs(
|
||||||
|
atrium_api::app::bsky::feed::post::RecordEmbedRefs::AppBskyEmbedExternalMain(Box::new(
|
||||||
|
atrium_api::app::bsky::embed::external::MainData {
|
||||||
|
external: record_card.into(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generate an array of Bsky media records
|
||||||
|
/// As Bsky does not support multiple video in a record or mix of video and images, video has the
|
||||||
|
/// highest priority
|
||||||
pub async fn generate_media_records(
|
pub async fn generate_media_records(
|
||||||
bsky: &BskyAgent,
|
bsky: &BskyAgent,
|
||||||
media_attach: &[Attachment],
|
media_attach: &[Attachment],
|
||||||
@@ -161,7 +225,7 @@ pub async fn generate_media_records(
|
|||||||
.collect();
|
.collect();
|
||||||
let video_media_attach: Vec<_> = media_attach
|
let video_media_attach: Vec<_> = media_attach
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|x| (x.r#type == AttachmentType::Video || x.r#type == AttachmentType::Gifv))
|
.filter(|x| x.r#type == AttachmentType::Video || x.r#type == AttachmentType::Gifv)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -239,11 +303,20 @@ async fn upload_media(
|
|||||||
} else {
|
} else {
|
||||||
// this is an image and it’s over 1Mb long
|
// this is an image and it’s over 1Mb long
|
||||||
debug!("Img file too large: {}", content_length);
|
debug!("Img file too large: {}", content_length);
|
||||||
|
// defaults to 95% quality for WebP compression
|
||||||
|
let mut default_quality = 95f32;
|
||||||
let img = ImageReader::new(Cursor::new(dl.bytes().await?))
|
let img = ImageReader::new(Cursor::new(dl.bytes().await?))
|
||||||
.with_guessed_format()?
|
.with_guessed_format()?
|
||||||
.decode()?;
|
.decode()?;
|
||||||
let encoder: Encoder = Encoder::from_image(&img)?;
|
let encoder: Encoder = Encoder::from_image(&img)?;
|
||||||
let webp: WebPMemory = encoder.encode(90f32);
|
let mut webp: WebPMemory = encoder.encode(default_quality);
|
||||||
|
|
||||||
|
while webp.len() > 1_000_000 {
|
||||||
|
debug!("Img file too large at {}%, reducing…", default_quality);
|
||||||
|
default_quality -= 5.0;
|
||||||
|
webp = encoder.encode(default_quality);
|
||||||
|
}
|
||||||
|
|
||||||
webp.to_vec()
|
webp.to_vec()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,17 @@ pub struct Config {
|
|||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct OolatoocsConfig {
|
pub struct OolatoocsConfig {
|
||||||
pub db_path: String,
|
pub db_path: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub remove_hashtags: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for OolatoocsConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
OolatoocsConfig {
|
||||||
|
db_path: "/var/lib/oolatoocs/db".to_string(),
|
||||||
|
remove_hashtags: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|||||||
37
src/lib.rs
37
src/lib.rs
@@ -18,7 +18,10 @@ mod utils;
|
|||||||
use utils::{generate_multi_tweets, strip_everything};
|
use utils::{generate_multi_tweets, strip_everything};
|
||||||
|
|
||||||
mod bsky;
|
mod bsky;
|
||||||
use bsky::{build_post_record, generate_media_records, get_session, BskyReply};
|
use bsky::{
|
||||||
|
build_post_record, generate_embed_records, generate_media_records, generate_quote_records,
|
||||||
|
get_session, BskyReply,
|
||||||
|
};
|
||||||
|
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
|
|
||||||
@@ -86,7 +89,14 @@ pub async fn run(config: &Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// form tweet_content and strip everything useless in it
|
// form tweet_content and strip everything useless in it
|
||||||
let Ok(mut tweet_content) = strip_everything(&toot.content, &toot.tags) else {
|
let toot_tags: Vec<megalodon::entities::status::Tag> =
|
||||||
|
match &config.oolatoocs.remove_hashtags {
|
||||||
|
true => toot.tags.clone(),
|
||||||
|
false => vec![],
|
||||||
|
};
|
||||||
|
let Ok(mut tweet_content) =
|
||||||
|
strip_everything(&toot.content, &toot_tags, &config.mastodon.base)
|
||||||
|
else {
|
||||||
continue; // skip in case we can’t strip something
|
continue; // skip in case we can’t strip something
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -151,15 +161,32 @@ pub async fn run(config: &Config) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// treats medias
|
// Don’t know how to union things so…
|
||||||
let record_medias = generate_media_records(&bluesky, &toot.media_attachments).await;
|
// cards have the least priority (you cannot embed card and images anyway)
|
||||||
|
// images have a higher priority
|
||||||
|
// quotes have the highest priority
|
||||||
|
|
||||||
|
let record_embed = if toot.reblog.is_some() {
|
||||||
|
let quote_record =
|
||||||
|
read_state(&conn, Some(toot.reblog.unwrap().id.parse::<u64>().unwrap()));
|
||||||
|
match quote_record {
|
||||||
|
Ok(Some(q)) => generate_quote_records(&config.bluesky, &q.record_uri).await,
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
} else if toot.media_attachments.len() > usize::from(0u8) {
|
||||||
|
generate_media_records(&bluesky, &toot.media_attachments).await
|
||||||
|
} else if toot.card.is_some() {
|
||||||
|
generate_embed_records(&bluesky, &toot.card.unwrap()).await
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
// posts corresponding tweet
|
// posts corresponding tweet
|
||||||
let record = build_post_record(
|
let record = build_post_record(
|
||||||
&config.bluesky,
|
&config.bluesky,
|
||||||
&tweet_content,
|
&tweet_content,
|
||||||
&toot.language,
|
&toot.language,
|
||||||
record_medias,
|
record_embed,
|
||||||
&record_reply_to,
|
&record_reply_to,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -55,9 +55,13 @@ pub async fn get_mastodon_timeline_since(
|
|||||||
.clone()
|
.clone()
|
||||||
.is_some_and(|r| r == t.account.id)
|
.is_some_and(|r| r == t.account.id)
|
||||||
})
|
})
|
||||||
.filter(|t| t.visibility == StatusVisibility::Public) // excludes everything that isn’t
|
.filter(|t| t.visibility == StatusVisibility::Public) // excludes everything that isn’t public
|
||||||
// public
|
.filter(|t| {
|
||||||
.filter(|t| t.reblog.is_none()) // excludes reblogs
|
t.reblog.is_none()
|
||||||
|
|| t.reblog
|
||||||
|
.clone()
|
||||||
|
.is_some_and(|r| r.account.id == t.account.id)
|
||||||
|
}) // excludes reblogs except by self
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|||||||
@@ -82,10 +82,7 @@ pub fn write_state(conn: &Connection, t: TootRecord) -> Result<(), Box<dyn Error
|
|||||||
|
|
||||||
/// Initiates the DB from path
|
/// Initiates the DB from path
|
||||||
pub fn init_db(d: &str) -> Result<(), Box<dyn Error>> {
|
pub fn init_db(d: &str) -> Result<(), Box<dyn Error>> {
|
||||||
debug!(
|
debug!("Initializing DB for {}", env!("CARGO_PKG_NAME"));
|
||||||
"{}",
|
|
||||||
format!("Initializing DB for {}", env!("CARGO_PKG_NAME"))
|
|
||||||
);
|
|
||||||
let conn = Connection::open(d)?;
|
let conn = Connection::open(d)?;
|
||||||
|
|
||||||
conn.execute(
|
conn.execute(
|
||||||
|
|||||||
46
src/utils.rs
46
src/utils.rs
@@ -38,7 +38,13 @@ fn twitter_count(content: &str) -> usize {
|
|||||||
|
|
||||||
for word in split_content {
|
for word in split_content {
|
||||||
if word.starts_with("http://") || word.starts_with("https://") {
|
if word.starts_with("http://") || word.starts_with("https://") {
|
||||||
count += 23;
|
// It’s not that simple. Bsky adapts itself to the URL.
|
||||||
|
// https://github.com -> 10 chars
|
||||||
|
// https://github.com/ -> 10 chars
|
||||||
|
// https://github.com/NVNTLabs -> 19 chars
|
||||||
|
// https://github.com/NVNTLabs/ -> 20 chars
|
||||||
|
// so taking the maximum here to simplify things
|
||||||
|
count += 26;
|
||||||
} else {
|
} else {
|
||||||
count += word.chars().count();
|
count += word.chars().count();
|
||||||
}
|
}
|
||||||
@@ -47,10 +53,16 @@ fn twitter_count(content: &str) -> usize {
|
|||||||
count
|
count
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn strip_everything(content: &str, tags: &Vec<Tag>) -> Result<String, Box<dyn Error>> {
|
pub fn strip_everything(
|
||||||
|
content: &str,
|
||||||
|
tags: &Vec<Tag>,
|
||||||
|
mastodon_base: &str,
|
||||||
|
) -> Result<String, Box<dyn Error>> {
|
||||||
let mut res = strip_html_tags(&content.replace("</p><p>", "\n\n").replace("<br />", "\n"));
|
let mut res = strip_html_tags(&content.replace("</p><p>", "\n\n").replace("<br />", "\n"));
|
||||||
|
|
||||||
strip_mastodon_tags(&mut res, tags).unwrap();
|
strip_quote_header(&mut res, mastodon_base)?;
|
||||||
|
|
||||||
|
strip_mastodon_tags(&mut res, tags)?;
|
||||||
|
|
||||||
res = res.trim_end_matches('\n').trim_end_matches(' ').to_string();
|
res = res.trim_end_matches('\n').trim_end_matches(' ').to_string();
|
||||||
res = decode_html_entities(&res).to_string();
|
res = decode_html_entities(&res).to_string();
|
||||||
@@ -58,6 +70,16 @@ pub fn strip_everything(content: &str, tags: &Vec<Tag>) -> Result<String, Box<dy
|
|||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn strip_quote_header(content: &mut String, mastodon_base: &str) -> Result<(), Box<dyn Error>> {
|
||||||
|
let re = Regex::new(&format!(
|
||||||
|
r"^RE: {}\S+\n\n",
|
||||||
|
mastodon_base.replace(".", r"\.")
|
||||||
|
))?;
|
||||||
|
*content = re.replace(content, "").to_string();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn strip_mastodon_tags(content: &mut String, tags: &Vec<Tag>) -> Result<(), Box<dyn Error>> {
|
fn strip_mastodon_tags(content: &mut String, tags: &Vec<Tag>) -> Result<(), Box<dyn Error>> {
|
||||||
for tag in tags {
|
for tag in tags {
|
||||||
let re = Regex::new(&format!("(?i)(#{} ?)", &tag.name))?;
|
let re = Regex::new(&format!("(?i)(#{} ?)", &tag.name))?;
|
||||||
@@ -100,11 +122,11 @@ mod tests {
|
|||||||
|
|
||||||
let content = "Shoot out to https://y.ml/ !";
|
let content = "Shoot out to https://y.ml/ !";
|
||||||
|
|
||||||
assert_eq!(twitter_count(content), 38);
|
assert_eq!(twitter_count(content), 41);
|
||||||
|
|
||||||
let content = "this is the link https://www.google.com/tamerelol/youpi/tonperemdr/tarace.html if you like! What if I shit a final";
|
let content = "this is the link https://www.google.com/tamerelol/youpi/tonperemdr/tarace.html if you like! What if I shit a final";
|
||||||
|
|
||||||
assert_eq!(twitter_count(content), 76);
|
assert_eq!(twitter_count(content), 79);
|
||||||
|
|
||||||
let content = "multi ple space";
|
let content = "multi ple space";
|
||||||
|
|
||||||
@@ -112,7 +134,7 @@ mod tests {
|
|||||||
|
|
||||||
let content = "This link is LEEEEET\n\nhttps://www.factornews.com/actualites/ca-sent-le-sapin-pour-free-radical-design-49985.html";
|
let content = "This link is LEEEEET\n\nhttps://www.factornews.com/actualites/ca-sent-le-sapin-pour-free-radical-design-49985.html";
|
||||||
|
|
||||||
assert_eq!(twitter_count(content), 45);
|
assert_eq!(twitter_count(content), 48);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -180,9 +202,19 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_strip_everything() {
|
fn test_strip_everything() {
|
||||||
|
// a classic toot
|
||||||
let content = "<p>Ce soir à 21h, c'est le Dojobar ! Au programme ce soir, une rétrospective sur la série Mario & Luigi.<br />Comme d'hab, le Twitch sera ici : <a href=\"https://twitch.tv/nintendojofr\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" translate=\"no\"><span class=\"invisible\">https://</span><span class=\"\">twitch.tv/nintendojofr</span><span class=\"invisible\"></span></a><br />Ou juste l'audio là : <a href=\"https://nintendojo.fr/dojobar\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" translate=\"no\"><span class=\"invisible\">https://</span><span class=\"\">nintendojo.fr/dojobar</span><span class=\"invisible\"></span></a><br />A toute !</p>";
|
let content = "<p>Ce soir à 21h, c'est le Dojobar ! Au programme ce soir, une rétrospective sur la série Mario & Luigi.<br />Comme d'hab, le Twitch sera ici : <a href=\"https://twitch.tv/nintendojofr\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" translate=\"no\"><span class=\"invisible\">https://</span><span class=\"\">twitch.tv/nintendojofr</span><span class=\"invisible\"></span></a><br />Ou juste l'audio là : <a href=\"https://nintendojo.fr/dojobar\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" translate=\"no\"><span class=\"invisible\">https://</span><span class=\"\">nintendojo.fr/dojobar</span><span class=\"invisible\"></span></a><br />A toute !</p>";
|
||||||
let expected_result = "Ce soir à 21h, c'est le Dojobar ! Au programme ce soir, une rétrospective sur la série Mario & Luigi.\nComme d'hab, le Twitch sera ici : https://twitch.tv/nintendojofr\nOu juste l'audio là : https://nintendojo.fr/dojobar\nA toute !".to_string();
|
let expected_result = "Ce soir à 21h, c'est le Dojobar ! Au programme ce soir, une rétrospective sur la série Mario & Luigi.\nComme d'hab, le Twitch sera ici : https://twitch.tv/nintendojofr\nOu juste l'audio là : https://nintendojo.fr/dojobar\nA toute !".to_string();
|
||||||
let result = strip_everything(content, &vec![]).unwrap();
|
let result = strip_everything(content, &vec![], "https://m.nintendojo.fr").unwrap();
|
||||||
|
|
||||||
|
assert_eq!(result, expected_result);
|
||||||
|
|
||||||
|
// a quoted toot
|
||||||
|
let content = "<p class=\"quote-inline\">RE: <a href=\"https://m.nintendojo.fr/@nintendojofr/115446347351491651\" target=\"_blank\" rel=\"nofollow noopener\" translate=\"no\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">m.nintendojo.fr/@nintendojofr/</span><span class=\"invisible\">115446347351491651</span></a></p><p>Assassin’s Creed Shadows pèsera environ 62,8 Go sur Switch 2 (et un peu plus de 100 Go sur les autres supports), soit tout juste pour rentrer sur une cartouche de 64 Go.</p><p>Ou pas, pour rappel…</p><p><a href=\"https://m.nintendojo.fr/tags/AssassinsCreedShadows\" class=\"mention hashtag\" rel=\"tag\">#<span>AssassinsCreedShadows</span></a> <a href=\"https://m.nintendojo.fr/tags/Ubisoft\" class=\"mention hashtag\" rel=\"tag\">#<span>Ubisoft</span></a> <a href=\"https://m.nintendojo.fr/tags/NintendoSwitch2\" class=\"mention hashtag\" rel=\"tag\">#<span>NintendoSwitch2</span></a></p>";
|
||||||
|
|
||||||
|
let expected_result = "Assassin’s Creed Shadows pèsera environ 62,8 Go sur Switch 2 (et un peu plus de 100 Go sur les autres supports), soit tout juste pour rentrer sur une cartouche de 64 Go.\n\nOu pas, pour rappel…\n\n#AssassinsCreedShadows #Ubisoft #NintendoSwitch2";
|
||||||
|
|
||||||
|
let result = strip_everything(content, &vec![], "https://m.nintendojo.fr").unwrap();
|
||||||
|
|
||||||
assert_eq!(result, expected_result);
|
assert_eq!(result, expected_result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user