aboutsummaryrefslogtreecommitdiff
path: root/src/dionysus/web/admin.clj
diff options
context:
space:
mode:
authorTim <contact@bytim.eu>2025-11-01 17:36:48 +0100
committerTim <contact@bytim.eu>2025-11-01 17:36:48 +0100
commit32ee50f0f6f53f8d5dea3bf159be3f65974c4b7b (patch)
treec317610f1a275936baefae2efeab360befbb9950 /src/dionysus/web/admin.clj
Initial commit
Diffstat (limited to 'src/dionysus/web/admin.clj')
-rw-r--r--src/dionysus/web/admin.clj45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/dionysus/web/admin.clj b/src/dionysus/web/admin.clj
new file mode 100644
index 0000000..20c7409
--- /dev/null
+++ b/src/dionysus/web/admin.clj
@@ -0,0 +1,45 @@
+(ns dionysus.web.admin
+ (:require [reitit.ring :as rring]
+ [org.httpkit.server :as http-server]
+ [ring.middleware.oauth2 :as rmoauth2]
+ [dotenv :as env]
+ [ring.middleware.params :as rmparams]
+ [ring.middleware.session :as rmsessions]
+
+ [dionysus.web.admin.home :as dwahome]
+ [dionysus.web.admin.home.blacklist :as dwahblacklist]
+ [dionysus.web.admin.home.server-settings :as dwahserver-settings]))
+
+(def ^:private routes
+ [["/" {:get {:handler dwahome/handle}}]
+ ["/blacklist"
+ ["/" {:get {:handler dwahblacklist/handle}}]
+ ["/add" {:post {:handler dwahblacklist/handle-add}}]
+ ["/change/:index" {:post {:handler dwahblacklist/handle-change}}]
+ ["/delete/:index" {:delete {:handler dwahblacklist/handle-delete}}]]
+ ["/server-settings" {:post {:handler dwahserver-settings/handle}}]
+ ["/assets/*" (rring/create-resource-handler)]])
+
+(def ^:private handler
+ (-> routes
+ rring/router
+ (rring/ring-handler (rring/redirect-trailing-slash-handler))
+ (rmoauth2/wrap-oauth2 {:spotify {:authorize-uri "https://accounts.spotify.com/authorize"
+ :access-token-uri "https://accounts.spotify.com/api/token"
+ :client-id (env/env "SPOTIFY_CLIENT_ID")
+ :client-secret (env/env "SPOTIFY_CLIENT_SECRET")
+ :scopes ["user-read-private"
+ "user-modify-playback-state"
+ "user-read-currently-playing"]
+ :launch-uri "/auth"
+ :redirect-uri "/callback"
+ :landing-uri "/"}})
+ rmsessions/wrap-session
+ rmparams/wrap-params))
+
+(def ^:private stop-fn (atom nil))
+
+(defn start-server! []
+ (when (fn? @stop-fn) (@stop-fn))
+ (reset! stop-fn (http-server/run-server handler {:port (or (env/env "ADMIN_PORT") 8081)})))
+#_(start-server!)