fix: opensearch.xml route

This commit is contained in:
Matthew Esposito 2025-03-07 17:08:27 -05:00
parent 357e7c2e09
commit 526c0d0797
2 changed files with 15 additions and 3 deletions

View file

@ -64,6 +64,17 @@ async fn font() -> Result<Response<Body>, String> {
)
}
async fn opensearch() -> Result<Response<Body>, String> {
Ok(
Response::builder()
.status(200)
.header("content-type", "application/opensearchdescription+xml")
.header("Cache-Control", "public, max-age=1209600, s-maxage=86400")
.body(include_bytes!("../static/opensearch.xml").as_ref().into())
.unwrap_or_default(),
)
}
async fn resource(body: &str, content_type: &str, cache: bool) -> Result<Response<Body>, String> {
let mut res = Response::builder()
.status(200)
@ -234,6 +245,7 @@ async fn main() {
app.at("/Inter.var.woff2").get(|_| font().boxed());
app.at("/touch-icon-iphone.png").get(|_| iphone_logo().boxed());
app.at("/apple-touch-icon.png").get(|_| iphone_logo().boxed());
app.at("/opensearch.xml").get(|_| opensearch().boxed());
app
.at("/playHLSVideo.js")
.get(|_| resource(include_str!("../static/playHLSVideo.js"), "text/javascript", false).boxed());

View file

@ -3,9 +3,9 @@
<ShortName>Search Redlib</ShortName>
<Description>Search for whatever you want on Redlib, awesome Reddit frontend</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="32" height="32" type="image/x-icon">/favicon.ico</Image>
<Url type="text/html" template="/search">
<Image width="32" height="32" type="image/x-icon">https://localhost:8080/favicon.ico</Image>
<Url type="text/html" template="https://localhost:8080/search">
<Param name="q" value="{searchTerms}"/>
</Url>
<moz:SearchForm>/search</moz:SearchForm>
<moz:SearchForm>https://localhost:8080/search</moz:SearchForm>
</OpenSearchDescription>