From 62f62a967f86e3bd94f06763b40615ccf7623109 Mon Sep 17 00:00:00 2001 From: Felisp Date: Tue, 10 Sep 2024 16:34:31 +0200 Subject: [PATCH] Finish making config URLs more flexible --- project.clj | 2 +- src/rss_thread_watch/core.clj | 25 ++++++++++++++----------- src/rss_thread_watch/feed_generator.clj | 5 +++-- src/rss_thread_watch/watcher.clj | 3 ++- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/project.clj b/project.clj index 5924e1f..c8701a2 100644 --- a/project.clj +++ b/project.clj @@ -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" :url "http://example.com/FIXME" :license {:name "AGPL-3.0-only" diff --git a/src/rss_thread_watch/core.clj b/src/rss_thread_watch/core.clj index ec959dd..338eab5 100644 --- a/src/rss_thread_watch/core.clj +++ b/src/rss_thread_watch/core.clj @@ -24,7 +24,7 @@ [rss-thread-watch.utils :as u]) (:gen-class)) -(def VERSION "0.4.4") +(def VERSION "0.4.5") ;; Internal default config (def CONFIG-DEFAULT @@ -83,25 +83,28 @@ (let [boards (get filled-config :boards-enabled) selecting '(:target :host) pattern "{board}"] - (u/fmap (fn [board confs] + (assoc filled-config + :boards-enabled + (u/fmap (fn [board confs] (->> (select-keys confs selecting) (u/fmap (fn [k v] (s/replace v pattern (s/replace board "/" "")))) (merge confs))) - boards))) + boards)))) (defn config-fill-board-defaults "Fills every enabled board with default config values" [config] (let [defaults (:boards-defaults config)] - (-> config - (update-in '(:boards-enabled) - (fn [mp] - (u/fmap (fn [k v] - (assoc (u/map-apply-defaults v defaults) :name k)) - mp))) - (dissoc :boards-defaults) - (config-url-expand)))) + (as-> config conf + (update-in conf + '(:boards-enabled) + (fn [mp] + (u/fmap (fn [k v] + (assoc (u/map-apply-defaults v defaults) :name k)) + mp))) + (dissoc conf :boards-defaults) + (config-url-expand conf)))) (defn get-some-config "Attempts to get config somehow, diff --git a/src/rss_thread_watch/feed_generator.clj b/src/rss_thread_watch/feed_generator.clj index 0360602..e0dcb6c 100644 --- a/src/rss_thread_watch/feed_generator.clj +++ b/src/rss_thread_watch/feed_generator.clj @@ -86,7 +86,7 @@ (defn thread-to-rss-item "Converts cached thread item to feed item which can be serialized into RSS" [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 ;; :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)) @@ -97,7 +97,7 @@ "Generates feed from matching items" [query-vec chod-treshold repeat? cache board-config] (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" :feed-url "https://tools.treebrary.org/thread-watcher/feed.xml" :description "RSS based thread watcher"} @@ -128,6 +128,7 @@ chod)] (try ;If we can't parse number from chod, use default 94 (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 60 (Integer/parseInt chod)) (catch Exception e diff --git a/src/rss_thread_watch/watcher.clj b/src/rss_thread_watch/watcher.clj index 3588168..689e18c 100644 --- a/src/rss_thread_watch/watcher.clj +++ b/src/rss_thread_watch/watcher.clj @@ -109,6 +109,7 @@ MAY CAUSE WRITE TO chod-thread-cache IF NECCESARRY" [board config] (let [refresh-rate (* 1000 (get-in config `(:boards-enabled ~board :refresh-rate))) + board-catalog-url (get-in config `(:boards-enabled ~board :target)) {data :data time-downloaded :time :or {time-downloaded 0} @@ -117,5 +118,5 @@ time-to-update? (or (nil? board-atom) (> (System/currentTimeMillis) (+ refresh-rate time-downloaded)))] (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))))