Add search by date
This commit is contained in:
parent
03a513e2b2
commit
0c66f533d1
12
src/main.rs
12
src/main.rs
|
@ -137,7 +137,7 @@ impl PictrsPage {
|
|||
}
|
||||
|
||||
impl PictrsClient {
|
||||
async fn page(&self, slug: Option<String>) -> Result<PageResponse, reqwest_middleware::Error> {
|
||||
async fn page(&self, query: &PageQuery) -> Result<PageResponse, reqwest_middleware::Error> {
|
||||
let mut url = self.pict_rs_endpoint.clone();
|
||||
url.set_path("/internal/hashes");
|
||||
|
||||
|
@ -145,7 +145,7 @@ impl PictrsClient {
|
|||
.client
|
||||
.get(url.as_str())
|
||||
.header("x-api-token", &self.pict_rs_api_key)
|
||||
.query(&PageQuery { slug })
|
||||
.query(query)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
|
@ -190,13 +190,17 @@ impl PictrsClient {
|
|||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
struct PageQuery {
|
||||
slug: Option<String>,
|
||||
timestamp: Option<String>,
|
||||
}
|
||||
|
||||
async fn index(
|
||||
web::Query(PageQuery { slug }): web::Query<PageQuery>,
|
||||
web::Query(query): web::Query<PageQuery>,
|
||||
client: web::Data<PictrsClient>,
|
||||
) -> Result<HttpResponse, actix_web::Error> {
|
||||
let page = client.page(slug).await.map_err(ErrorInternalServerError)?;
|
||||
let page = client
|
||||
.page(&query)
|
||||
.await
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
|
||||
let page = match page {
|
||||
PageResponse::Ok { page, .. } => page,
|
||||
|
|
|
@ -22,6 +22,17 @@ nav a {
|
|||
padding: 8px 16px;
|
||||
}
|
||||
|
||||
nav form {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
nav input {
|
||||
padding: 8px;
|
||||
}
|
||||
nav input[type="submit"] {
|
||||
padding: 8px 16px;
|
||||
}
|
||||
|
||||
section {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
@if page.prev_link().is_some() || page.next_link().is_some() {
|
||||
<nav>
|
||||
@if let Some(prev) = page.prev_link() {
|
||||
<a href="@prev">Previous Page</a>
|
||||
|
@ -22,8 +21,11 @@
|
|||
@if let Some(next) = page.next_link() {
|
||||
<a href="@next">Next Page</a>
|
||||
}
|
||||
<form method="GET" action="/">
|
||||
<input type="text" name="timestamp" placeholder="rfc3339 timestamp" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
</nav>
|
||||
}
|
||||
|
||||
<section>
|
||||
@if page.hashes.is_empty() {
|
||||
|
|
Loading…
Reference in a new issue