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")
};
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");
}
@ -94,17 +99,32 @@ impl DVMHandler for TikTokDvm {
imeta.push(format!("{} {}", k, v));
}
let ev = EventBuilder::new(Kind::Custom(22), &info.full_title)
.tag(Tag::parse(imeta)?)
.tags([
Tag::parse(["title", &info.full_title])?,
Tag::parse(["r", input.as_str()])?,
]);
let should_post = if let Some(ps) = request.params.get("post_short") {
ps.to_ascii_lowercase() == "true"
} else {
true
};
let event_posted = client.send_event_builder(ev).await?;
let job_data = NoviaVideoData {
event_id: event_posted.val.to_hex(),
video: res.sha256,
let job_data = if should_post {
let ev = EventBuilder::new(Kind::Custom(22), &info.full_title)
.tag(Tag::parse(imeta)?)
.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(
@ -164,6 +184,10 @@ struct TikTokVideo {
#[derive(Deserialize, Serialize)]
struct NoviaVideoData {
event_id: String,
video: String,
#[serde(skip_serializing_if = "Option::is_none")]
event_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
video: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
url: Option<String>,
}