mirror of
https://github.com/Syfaro/fuzzysearch.git
synced 2024-12-24 14:25:35 +00:00
Add API endpoint to check if known handle.
This commit is contained in:
parent
801d63f9d9
commit
ec9baf0c8a
@ -10,7 +10,8 @@ pub fn search(
|
||||
search_image(db.clone(), tree.clone())
|
||||
.or(search_hashes(db.clone(), tree.clone()))
|
||||
.or(stream_search_image(db.clone(), tree))
|
||||
.or(search_file(db))
|
||||
.or(search_file(db.clone()))
|
||||
.or(check_handle(db))
|
||||
}
|
||||
|
||||
pub fn search_file(db: Pool) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
||||
@ -66,6 +67,14 @@ pub fn stream_search_image(
|
||||
.and_then(handlers::stream_image)
|
||||
}
|
||||
|
||||
pub fn check_handle(db: Pool) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
||||
warp::path("handle")
|
||||
.and(warp::get())
|
||||
.and(warp::query::<HandleOpts>())
|
||||
.and(with_pool(db))
|
||||
.and_then(handlers::check_handle)
|
||||
}
|
||||
|
||||
fn with_api_key() -> impl Filter<Extract = (String,), Error = Rejection> + Clone {
|
||||
warp::header::<String>("x-api-key")
|
||||
}
|
||||
|
@ -290,6 +290,24 @@ pub async fn search_file(
|
||||
Ok(warp::reply::json(&matches))
|
||||
}
|
||||
|
||||
pub async fn check_handle(opts: HandleOpts, db: Pool) -> Result<impl Reply, Rejection> {
|
||||
let db = db.get().await.map_err(map_bb8_err)?;
|
||||
|
||||
let exists = if let Some(handle) = opts.twitter {
|
||||
!db.query(
|
||||
"SELECT 1 FROM twitter_user WHERE lower(data->>'screen_name') = lower($1)",
|
||||
&[&handle],
|
||||
)
|
||||
.await
|
||||
.map_err(map_postgres_err)?
|
||||
.is_empty()
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
Ok(warp::reply::json(&exists))
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn handle_rejection(err: Rejection) -> Result<impl Reply, std::convert::Infallible> {
|
||||
warn!("had rejection");
|
||||
|
@ -107,3 +107,8 @@ pub struct HashSearchOpts {
|
||||
pub hashes: String,
|
||||
pub distance: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct HandleOpts {
|
||||
pub twitter: Option<String>,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user