Update push

This commit is contained in:
2023-11-04 11:48:31 +00:00
committed by GitHub
parent 722b6005fe
commit 135b2498e7
2 changed files with 15 additions and 0 deletions

View File

@@ -128,6 +128,10 @@ pub struct PushDeerConfig {
#[serde(default = "default_true")]
/// Whether to add translated tag
pub add_translated_tag: bool,
#[serde(default = "default_true")]
/// Whether to add image link
/// Supported when type is `Text`.
pub add_image_link: bool,
}
#[derive(Debug, Serialize, Deserialize)]

View File

@@ -6,6 +6,7 @@ use crate::parser::description::DescriptionParser;
use crate::pixivapp::illust::PixivAppIllust;
use crate::push::every_push::{EveryPushClient, EveryPushTextType};
use crate::push::pushdeer::PushdeerClient;
use crate::utils::get_file_name_from_url;
use crate::{get_helper, gettext};
use json::JsonValue;
use percent_encoding::{percent_encode, NON_ALPHANUMERIC};
@@ -392,6 +393,16 @@ impl<'a> RunContext<'a> {
text.push_str(&format!("[{}]({}) \n", link, link));
}
}
if cfg.add_image_link {
let len = self.len().unwrap_or(1);
for i in 0..len {
if let Some(url) = self.get_image_url(i).await? {
let name =
get_file_name_from_url(&url).unwrap_or_else(|| format!("{}", i));
text.push_str(&format!("[{}]({}) \n", name, url));
}
}
}
if let Some(desc) = self.desc() {
let mut p = DescriptionParser::builder(true).ensure_link_ascii().build();
p.parse(desc)?;