-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a4e8e1
commit 9d78c3c
Showing
16 changed files
with
652 additions
and
541 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use axum::{ | ||
body::Body, | ||
http::Request, | ||
middleware::{from_fn, Next}, | ||
response::Response, | ||
Router, | ||
}; | ||
use std::path::Path; | ||
use tower_http::services::ServeDir; | ||
|
||
pub async fn content_type_middleware(req: Request<Body>, next: Next) -> Response { | ||
let uri = req.uri().to_owned(); | ||
let path = uri.path(); | ||
let splited = path.split('.').collect::<Vec<_>>(); | ||
if let Some(extension) = splited.last() { | ||
let mut response = next.run(req).await; | ||
let extension = extension.to_owned().to_lowercase(); | ||
let content_type = match extension.as_str() { | ||
"html" => "text/html", | ||
"css" => "text/css", | ||
"js" => "text/javascript", | ||
"ps" => "application/postscript", | ||
_ => "application/octet-stream", | ||
}; | ||
|
||
if let Ok(content_type) = content_type.parse() { | ||
response.headers_mut().insert("Content-Type", content_type); | ||
} | ||
|
||
response | ||
} else { | ||
let mut response = next.run(req).await; | ||
|
||
if let Ok(content_type) = "application/octet-stream".parse() { | ||
response.headers_mut().insert("Content-Type", content_type); | ||
} | ||
|
||
response | ||
} | ||
} | ||
|
||
pub fn router<P: AsRef<Path>>(path: P) -> Router { | ||
let serve_dir = ServeDir::new(path); | ||
|
||
Router::new() | ||
.fallback_service(serve_dir) | ||
.layer(from_fn(content_type_middleware)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { html } from "htm/preact"; | ||
|
||
export function Captcha({ captchaKey, isHidden }) { | ||
if (isHidden) { | ||
return null; | ||
} | ||
return html` | ||
<div class="h-[100px] flex items-center justify-center mt-4"> | ||
${ | ||
captchaKey && | ||
html` | ||
<div class="captcha-container"> | ||
<div class="g-recaptcha" data-sitekey="{{ captcha_key }}"></div> | ||
</div> | ||
` | ||
} | ||
<div class="flex flex-col items-center justify-center gap-2 hidden"> | ||
<div class="loader"></div> | ||
<div>Waiting until more tokens are available</div> | ||
</div> | ||
</div> | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { html } from "htm/preact"; | ||
|
||
export function Checkbox({ id, checked, onChange, children }) { | ||
return html` | ||
<div class=${styles.checkboxRow}> | ||
<input | ||
type="checkbox" | ||
id=${id} | ||
name=${id} | ||
class=${styles.checkbox} | ||
checked=${checked} | ||
onChange=${onChange} | ||
/> | ||
<label for=${id}>${children}</label> | ||
</div> | ||
`; | ||
} | ||
|
||
const styles = { | ||
checkboxRow: "flex items-center gap-2", | ||
checkbox: "w-4 h-4 text-green-600 bg-gray-100 border-gray-300 rounded", | ||
}; |
Oops, something went wrong.