47 lines
1.6 KiB
Rust
47 lines
1.6 KiB
Rust
use crate::error::GementionError;
|
|
use crate::models::mentions::{Mention, MentionUpload};
|
|
use crate::models::verification::VerificationStatus;
|
|
use crate::{models::mentions::MentionResponse, verification::verify};
|
|
use fluffer::Client;
|
|
|
|
// Receive a mention over Titan.
|
|
// - Make Gemini request to see if target page supports gemention.
|
|
// - If so, store mention in DB.
|
|
pub(crate) async fn receive_mention(client: Client) -> Result<MentionResponse, GementionError> {
|
|
// TODO change to return MentionResponse or something like that.
|
|
let titan = MentionUpload::try_from(&client)?;
|
|
let target = client.parameter("target").unwrap_or("not provided");
|
|
let verified = verify(&target).await;
|
|
|
|
if let VerificationStatus::Verified { .. } = verified {
|
|
let mention = Mention::try_from(titan);
|
|
match mention {
|
|
Ok(mention) => println!("{:?}", mention),
|
|
Err(err) => println!("{}", err),
|
|
}
|
|
}
|
|
|
|
match verified {
|
|
VerificationStatus::Verified { endpoint, source } => {
|
|
Ok(MentionResponse::verified(&endpoint))
|
|
}
|
|
VerificationStatus::NotVerified(failure) => {
|
|
Ok(MentionResponse::failure(&failure.to_string()))
|
|
}
|
|
}
|
|
|
|
// format!(
|
|
// "Target: {}\nVerification status: {}\nSize: {}\nMime: {}\nContent: {}\nToken: {}",
|
|
// target,
|
|
// verified.to_string(),
|
|
// titan.size,
|
|
// titan.mime,
|
|
// std::str::from_utf8(&titan.content).unwrap_or("[not utf8]"),
|
|
// titan.token.as_deref().unwrap_or("[no token]"),
|
|
// )
|
|
}
|
|
|
|
// Render comments gemtext by requesting comments for a page.
|
|
|
|
// Proxy a webmention to Titan endpoint.
|