From 13159e5d78c87381e1e2946cba1044b4653887ef Mon Sep 17 00:00:00 2001 From: creations Date: Sun, 1 Jun 2025 08:34:17 -0400 Subject: [PATCH 1/6] move to the proper HTTP methods --- README.md | 11 ++++------- public/js/index.js | 11 +++++++++-- src/routes/mod.rs | 10 +++++----- src/routes/timezone.rs | 4 ++-- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b067b10..2f27d19 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,12 @@ docker compose up --build Returns stored timezone and username for the given user ID. -### `GET /set?timezone=` +### `POST /set` -Stores timezone for the authenticated user. Requires Discord OAuth session. +Stores timezone for the authenticated user. Requires Discord OAuth session. +Body: `application/x-www-form-urlencoded` with `timezone=` -### `GET /delete` +### `DELETE /delete` Deletes the authenticated user's timezone entry. Requires Discord OAuth session. @@ -69,7 +70,3 @@ Starts OAuth2 authentication flow. ### `GET /auth/discord/callback` Handles OAuth2 redirect and sets a session cookie. - -## License - -[BSD-3-Clause](LICENSE) diff --git a/public/js/index.js b/public/js/index.js index a342ffb..244677c 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -52,7 +52,11 @@ async function fetchUserInfo() { deleteBtn.addEventListener("click", async () => { try { - const res = await fetch("/delete", { credentials: "include" }); + const res = await fetch("/delete", { + method: "DELETE", + credentials: "include" + }); + if (!res.ok) throw new Error(); ts.clear(); @@ -74,8 +78,11 @@ setBtn.addEventListener("click", async () => { if (!timezone) return; try { - const res = await fetch(`/set?timezone=${encodeURIComponent(timezone)}`, { + const res = await fetch("/set", { + method: "POST", credentials: "include", + headers: { "Content-Type": "application/x-www-form-urlencoded" }, + body: `timezone=${encodeURIComponent(timezone)}` }); if (!res.ok) throw new Error(); statusMsg.textContent = "Timezone updated!"; diff --git a/src/routes/mod.rs b/src/routes/mod.rs index e90d36f..c7f4fbc 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -2,13 +2,13 @@ use crate::db::AppState; use axum::{ http::{HeaderValue, StatusCode}, response::{Html, Response}, - routing::{get, options}, + routing::{delete, get, options, post}, Router, }; use std::fs; use tower_http::services::ServeDir; -pub mod auth; +mod auth; mod timezone; async fn preflight_handler() -> Response { @@ -18,7 +18,7 @@ async fn preflight_handler() -> Response { headers.insert("access-control-allow-origin", HeaderValue::from_static("*")); headers.insert( "access-control-allow-methods", - HeaderValue::from_static("GET, POST, OPTIONS"), + HeaderValue::from_static("GET, POST, DELETE, OPTIONS"), ); headers.insert( "access-control-allow-headers", @@ -46,9 +46,9 @@ pub fn all() -> Router { Router::new() .route("/", get(index_page)) .route("/get", get(timezone::get_timezone)) - .route("/set", get(timezone::set_timezone)) + .route("/set", post(timezone::set_timezone)) .route("/set", options(preflight_handler)) - .route("/delete", get(timezone::delete_timezone)) + .route("/delete", delete(timezone::delete_timezone)) .route("/list", get(timezone::list_timezones)) .route("/auth/discord", get(auth::start_oauth)) .route("/auth/discord/callback", get(auth::handle_callback)) diff --git a/src/routes/timezone.rs b/src/routes/timezone.rs index 99c2292..e24ce42 100644 --- a/src/routes/timezone.rs +++ b/src/routes/timezone.rs @@ -5,7 +5,7 @@ use axum::{ extract::{Query, State}, http::{HeaderMap, StatusCode}, response::IntoResponse, - Json, + Form, Json, }; use chrono_tz::Tz; use headers::{Cookie, HeaderMapExt}; @@ -182,7 +182,7 @@ pub async fn delete_timezone( pub async fn set_timezone( State(state): State, headers: HeaderMap, - Query(query): Query, + Form(query): Form, ) -> impl IntoResponse { let Some(cookie_header) = headers.typed_get::() else { return ( From 1fa52e74e6a16d5a08de6bf2438420d392d020c3 Mon Sep 17 00:00:00 2001 From: creations Date: Sun, 1 Jun 2025 17:29:45 -0400 Subject: [PATCH 2/6] test --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5a6c5b6..001a476 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ -# Stage 1: Build FROM rustlang/rust:nightly AS builder WORKDIR /app From ad6c9b7095b7970c3f44347e5f2466914723e78c Mon Sep 17 00:00:00 2001 From: creations Date: Mon, 2 Jun 2025 18:22:54 -0400 Subject: [PATCH 3/6] add open source to index page --- public/css/style.css | 19 +++++++++++++++++++ public/forgejo_logo.svg | 36 ++++++++++++++++++++++++++++++++++++ public/index.html | 8 ++++++++ 3 files changed, 63 insertions(+) create mode 100644 public/forgejo_logo.svg diff --git a/public/css/style.css b/public/css/style.css index b116f25..b7c3143 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -164,6 +164,25 @@ button.danger:hover { color: var(--fg); } +.open-source-logo { + width: 2rem; + height: 2rem; + margin: 0; + padding: 0; + cursor: pointer; + + position: fixed; + bottom: 1rem; + right: 0.5rem; + z-index: 1000; + + opacity: 0.5; + transition: opacity 0.3s ease; + + &:hover { + opacity: 1 !important; + } +} .hidden { display: none; diff --git a/public/forgejo_logo.svg b/public/forgejo_logo.svg new file mode 100644 index 0000000..be0b3ce --- /dev/null +++ b/public/forgejo_logo.svg @@ -0,0 +1,36 @@ + + + + + Forgejo logo + Caesar Schinas + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/index.html b/public/index.html index b053d5e..6c33e03 100644 --- a/public/index.html +++ b/public/index.html @@ -14,6 +14,14 @@ +
+ + + +
+