Finish making config URLs more flexible

This commit is contained in:
Felisp 2024-09-10 16:34:31 +02:00
parent 4c5ad1e923
commit 62f62a967f
4 changed files with 20 additions and 15 deletions

View file

@ -1,4 +1,4 @@
(defproject rss-thread-watch "0.4.4-SNAPSHOT" (defproject rss-thread-watch "0.4.5-SNAPSHOT"
:description "RSS based thread watcher" :description "RSS based thread watcher"
:url "http://example.com/FIXME" :url "http://example.com/FIXME"
:license {:name "AGPL-3.0-only" :license {:name "AGPL-3.0-only"

View file

@ -24,7 +24,7 @@
[rss-thread-watch.utils :as u]) [rss-thread-watch.utils :as u])
(:gen-class)) (:gen-class))
(def VERSION "0.4.4") (def VERSION "0.4.5")
;; Internal default config ;; Internal default config
(def CONFIG-DEFAULT (def CONFIG-DEFAULT
@ -83,25 +83,28 @@
(let [boards (get filled-config :boards-enabled) (let [boards (get filled-config :boards-enabled)
selecting '(:target :host) selecting '(:target :host)
pattern "{board}"] pattern "{board}"]
(u/fmap (fn [board confs] (assoc filled-config
:boards-enabled
(u/fmap (fn [board confs]
(->> (select-keys confs selecting) (->> (select-keys confs selecting)
(u/fmap (fn [k v] (u/fmap (fn [k v]
(s/replace v pattern (s/replace board "/" "")))) (s/replace v pattern (s/replace board "/" ""))))
(merge confs))) (merge confs)))
boards))) boards))))
(defn config-fill-board-defaults (defn config-fill-board-defaults
"Fills every enabled board with default config values" "Fills every enabled board with default config values"
[config] [config]
(let [defaults (:boards-defaults config)] (let [defaults (:boards-defaults config)]
(-> config (as-> config conf
(update-in '(:boards-enabled) (update-in conf
(fn [mp] '(:boards-enabled)
(u/fmap (fn [k v] (fn [mp]
(assoc (u/map-apply-defaults v defaults) :name k)) (u/fmap (fn [k v]
mp))) (assoc (u/map-apply-defaults v defaults) :name k))
(dissoc :boards-defaults) mp)))
(config-url-expand)))) (dissoc conf :boards-defaults)
(config-url-expand conf))))
(defn get-some-config (defn get-some-config
"Attempts to get config somehow, "Attempts to get config somehow,

View file

@ -86,7 +86,7 @@
(defn thread-to-rss-item (defn thread-to-rss-item
"Converts cached thread item to feed item which can be serialized into RSS" "Converts cached thread item to feed item which can be serialized into RSS"
[t host board] [t host board]
(let [link-url (str host board "thread/" (:no t))] ;Hardcode emergency bugfix (let [link-url (s/replace host "{threadnum}" (str (:no t)))] ;Hardcode emergency bugfix
{:title (format "%.2f%% - %s" (:chod t) (:title t)) ;TODO: Generate link from the target somehow, or just include it from API response {:title (format "%.2f%% - %s" (:chod t) (:title t)) ;TODO: Generate link from the target somehow, or just include it from API response
;; :url link-url <- this is supposed to be for images according to: https://cyber.harvard.edu/rss/rss.html ;; :url link-url <- this is supposed to be for images according to: https://cyber.harvard.edu/rss/rss.html
:description (format "The thread: '%s' has %.2f%% chance of dying" (:title t) (:chod t)) :description (format "The thread: '%s' has %.2f%% chance of dying" (:title t) (:chod t))
@ -97,7 +97,7 @@
"Generates feed from matching items" "Generates feed from matching items"
[query-vec chod-treshold repeat? cache board-config] [query-vec chod-treshold repeat? cache board-config]
(let [items (filter-chod-posts query-vec chod-treshold repeat? cache) (let [items (filter-chod-posts query-vec chod-treshold repeat? cache)
head {:title "RSS Thread watcher v0.4.4" ;TODO: hardcoded string here, remake to reference to config.clj head {:title "RSS Thread watcher v0.4.5" ;TODO: hardcoded string here, remake to reference to config.clj
:link "https://tools.treebrary.org/thread-watcher/feed.xml" :link "https://tools.treebrary.org/thread-watcher/feed.xml"
:feed-url "https://tools.treebrary.org/thread-watcher/feed.xml" :feed-url "https://tools.treebrary.org/thread-watcher/feed.xml"
:description "RSS based thread watcher"} :description "RSS based thread watcher"}
@ -128,6 +128,7 @@
chod)] chod)]
(try ;If we can't parse number from chod, use default 94 (try ;If we can't parse number from chod, use default 94
(if (or (vector? chod) (if (or (vector? chod)
;; TODO: Do we seriously parse this twice?
(<= (Integer/parseInt chod) 60)) ; Never accept chod lower than 60 TODO: don't hardcode this (<= (Integer/parseInt chod) 60)) ; Never accept chod lower than 60 TODO: don't hardcode this
60 (Integer/parseInt chod)) 60 (Integer/parseInt chod))
(catch Exception e (catch Exception e

View file

@ -109,6 +109,7 @@
MAY CAUSE WRITE TO chod-thread-cache IF NECCESARRY" MAY CAUSE WRITE TO chod-thread-cache IF NECCESARRY"
[board config] [board config]
(let [refresh-rate (* 1000 (get-in config `(:boards-enabled ~board :refresh-rate))) (let [refresh-rate (* 1000 (get-in config `(:boards-enabled ~board :refresh-rate)))
board-catalog-url (get-in config `(:boards-enabled ~board :target))
{data :data {data :data
time-downloaded :time time-downloaded :time
:or {time-downloaded 0} :or {time-downloaded 0}
@ -117,5 +118,5 @@
time-to-update? (or (nil? board-atom) time-to-update? (or (nil? board-atom)
(> (System/currentTimeMillis) (+ refresh-rate time-downloaded)))] (> (System/currentTimeMillis) (+ refresh-rate time-downloaded)))]
(if time-to-update? (if time-to-update?
(update-board-cache! (get-board-url board config) board (get-in config [:boards-enabled board :starting-page])) (update-board-cache! board-catalog-url board (get-in config [:boards-enabled board :starting-page]))
@(get @chod-threads-cache board)))) @(get @chod-threads-cache board))))