fix: handle more tiktok domains
feat: accept post_short param (default true)
This commit is contained in:
@ -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,6 +99,13 @@ impl DVMHandler for TikTokDvm {
|
||||
imeta.push(format!("{} {}", k, v));
|
||||
}
|
||||
|
||||
let should_post = if let Some(ps) = request.params.get("post_short") {
|
||||
ps.to_ascii_lowercase() == "true"
|
||||
} else {
|
||||
true
|
||||
};
|
||||
|
||||
let job_data = if should_post {
|
||||
let ev = EventBuilder::new(Kind::Custom(22), &info.full_title)
|
||||
.tag(Tag::parse(imeta)?)
|
||||
.tags([
|
||||
@ -102,9 +114,17 @@ impl DVMHandler for TikTokDvm {
|
||||
]);
|
||||
|
||||
let event_posted = client.send_event_builder(ev).await?;
|
||||
let job_data = NoviaVideoData {
|
||||
event_id: event_posted.val.to_hex(),
|
||||
video: res.sha256,
|
||||
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>,
|
||||
}
|
||||
|
Reference in New Issue
Block a user