fix: handle more tiktok domains

feat: accept post_short param (default true)
This commit is contained in:
2025-05-31 20:06:54 +01:00
parent c8097d18bb
commit a4ab530ade

View File

@ -49,7 +49,12 @@ impl DVMHandler for TikTokDvm {
bail!("Only URL inputs are accepted") bail!("Only URL inputs are accepted")
}; };
if input.host_str() != Some("www.tiktok.com") { if input
.host_str()
.as_ref()
.map(|h| h.ends_with("tiktok.com"))
.unwrap_or(false)
{
bail!("Only tiktok urls are accepted"); bail!("Only tiktok urls are accepted");
} }
@ -94,17 +99,32 @@ impl DVMHandler for TikTokDvm {
imeta.push(format!("{} {}", k, v)); imeta.push(format!("{} {}", k, v));
} }
let ev = EventBuilder::new(Kind::Custom(22), &info.full_title) let should_post = if let Some(ps) = request.params.get("post_short") {
.tag(Tag::parse(imeta)?) ps.to_ascii_lowercase() == "true"
.tags([ } else {
Tag::parse(["title", &info.full_title])?, true
Tag::parse(["r", input.as_str()])?, };
]);
let event_posted = client.send_event_builder(ev).await?; let job_data = if should_post {
let job_data = NoviaVideoData { let ev = EventBuilder::new(Kind::Custom(22), &info.full_title)
event_id: event_posted.val.to_hex(), .tag(Tag::parse(imeta)?)
video: res.sha256, .tags([
Tag::parse(["title", &info.full_title])?,
Tag::parse(["r", input.as_str()])?,
]);
let event_posted = client.send_event_builder(ev).await?;
NoviaVideoData {
event_id: Some(event_posted.val.to_hex()),
video: Some(res.sha256),
url: None,
}
} else {
NoviaVideoData {
event_id: None,
video: Some(res.sha256),
url: Some(res.url),
}
}; };
let status = build_status_for_job( let status = build_status_for_job(
@ -164,6 +184,10 @@ struct TikTokVideo {
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
struct NoviaVideoData { struct NoviaVideoData {
event_id: String, #[serde(skip_serializing_if = "Option::is_none")]
video: String, event_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
video: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
url: Option<String>,
} }