Add manifest

This commit is contained in:
2024-12-02 08:36:06 -08:00
parent da36608624
commit dc45b073ab
3 changed files with 31 additions and 12 deletions

BIN
src/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -1,31 +1,30 @@
use std::{ use std::{
env, env,
fs::{File, OpenOptions}, fs::OpenOptions,
io::{BufRead, BufReader, Write}, io::{BufRead, BufReader, Write},
}; };
use maud::{html, Markup, DOCTYPE}; use maud::{html, Markup, DOCTYPE};
use rouille::{input::basic_http_auth, post_input, router, try_or_400, Response}; use rouille::{input::basic_http_auth, post_input, router, try_or_400, Request, Response};
const TASKS: &str = "tasks.txt"; const TASKS: &str = "tasks.txt";
fn main() { fn main() {
let LOGIN: String = env::var("LOGIN").unwrap(); let login: String = env::var("LOGIN").unwrap();
let PASSWORD: String = env::var("PASSWORD").unwrap(); let password: String = env::var("PASSWORD").unwrap();
rouille::start_server("0.0.0.0:8000", move |request| { rouille::start_server("0.0.0.0:8000", move |request| {
// Authenticate if !authenticated(&request, &login, &password) {
let auth = match basic_http_auth(request) {
Some(a) => a,
None => return Response::basic_http_auth_login_required("app"),
};
if auth.login != LOGIN || auth.password != PASSWORD {
return Response::basic_http_auth_login_required("app"); return Response::basic_http_auth_login_required("app");
} }
// Route
router!(request, router!(request,
(GET) ["/"] => { index() }, (GET) ["/"] => { index() },
(GET) ["manifest.json"] => {
Response::from_data("application/manifest+json", include_bytes!("manifest.json"))
},
(GET) ["/icon.png"] => {
Response::from_data("image/png", include_bytes!("icon.png"))
},
(POST) ["/add"] => { (POST) ["/add"] => {
let input = try_or_400!(post_input!(request, { let input = try_or_400!(post_input!(request, {
task: String, task: String,
@@ -38,6 +37,13 @@ fn main() {
}); });
} }
fn authenticated(request: &Request, login: &str, password: &str) -> bool {
match basic_http_auth(request) {
Some(a) => a.login == login && a.password == password,
None => false,
}
}
fn index() -> Response { fn index() -> Response {
Response::html(html!( Response::html(html!(
(DOCTYPE) (DOCTYPE)
@@ -47,6 +53,8 @@ fn index() -> Response {
meta name="viewport" content="width=device-width, initial-scale=1"; meta name="viewport" content="width=device-width, initial-scale=1";
title { "To-do" } title { "To-do" }
link rel="stylesheet" href="https://unpkg.com/mvp.css@1.17.0"; link rel="stylesheet" href="https://unpkg.com/mvp.css@1.17.0";
link rel="manifest" href="manifest.json";
link rel="icon" href="/icon.png";
script src="https://unpkg.com/htmx.org@2.0.3" {} script src="https://unpkg.com/htmx.org@2.0.3" {}
} }
body { body {

11
src/manifest.json Normal file
View File

@@ -0,0 +1,11 @@
{
"short_name": "To-do",
"start_url": "/",
"display": "standalone",
"icons": [
{
"src": "/icon.png",
"sizes": "512x512"
}
]
}