44 lines
1.3 KiB
Clojure
44 lines
1.3 KiB
Clojure
(ns micro-blog.api
|
|
(:require [io.pedestal.connector :as conn]
|
|
[io.pedestal.http.http-kit :as hk]
|
|
[micro-blog.config :refer [config]]
|
|
micro-blog.mastodon
|
|
micro-blog.blue-sky
|
|
micro-blog.nostr
|
|
[taoensso.telemere :as tel]))
|
|
|
|
(defn mastodon-proc-handler [_request]
|
|
(let [msg "Procding Mastodon Scrape"]
|
|
(tel/log! :info msg)
|
|
(micro-blog.mastodon/run)
|
|
{:status 200
|
|
:body msg}))
|
|
|
|
(defn blue-sky-proc-handler [_request]
|
|
(let [msg "Procing BlueSky Scrape"]
|
|
(tel/log! :info msg)
|
|
(micro-blog.blue-sky/run)
|
|
{:status 200
|
|
:body msg}))
|
|
|
|
(defn nostr-proc-handler [_request]
|
|
(let [msg "Restarting Nostr scraper"]
|
|
(tel/log! :info msg)
|
|
(micro-blog.nostr/close)
|
|
(micro-blog.nostr/start)
|
|
{:status 200
|
|
:body msg}))
|
|
|
|
(def routes
|
|
#{["/bluesky" :get blue-sky-proc-handler :route-name :blue-sky]
|
|
["/mastodon" :get mastodon-proc-handler :route-name :mastodon]
|
|
["/nostr" :get nostr-proc-handler :route-name :nostr]})
|
|
|
|
(defn create-connector []
|
|
(-> (conn/default-connector-map (:api-host @config) (Integer/parseInt (str (:api-port @config))))
|
|
(conn/with-default-interceptors)
|
|
(conn/with-routes routes)
|
|
(hk/create-connector nil)))
|
|
|
|
(defn start []
|
|
(conn/start! (create-connector)))
|