realize new auth outline

This commit is contained in:
jem 2020-05-30 17:14:49 +02:00
parent 9c525deb9d
commit db728d330f
4 changed files with 27 additions and 32 deletions

View file

@ -27,12 +27,16 @@ If you get a [permission failure](https://github.com/anmonteiro/lumo/issues/206)
with later timestamps to avoid duplicate posts. On the first run the timestamp will default to current time. with later timestamps to avoid duplicate posts. On the first run the timestamp will default to current time.
```clojure ```clojure
{;; add Twitter config to mirror Twitter accounts {:auth {;; add Twitter config to mirror Twitter accounts
:twitter {:access-keys :twitter {:consumer_key "XXXX"
{:consumer_key "XXXX"
:consumer_secret "XXXX" :consumer_secret "XXXX"
:access_token_key "XXXX" :access_token_key "XXXX"
:access_token_secret "XXXX"}} :access_token_secret "XXXX"}
:mastodon {:access_token "XXXX"
;; account number you see when you log in and go to your profile
;; e.g: https://mastodon.social/web/accounts/294795
:account-id "XXXX"
:api_url "https://botsin.space/api/v1/"}}
;; add Tumblr config to mirror Tumblr accounts ;; add Tumblr config to mirror Tumblr accounts
:tumblr {:access-keys :tumblr {:access-keys
{:consumer_key "XXXX" {:consumer_key "XXXX"
@ -45,12 +49,7 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w
;; add RSS config to follow feeds ;; add RSS config to follow feeds
:rss {"Hacker News" "https://hnrss.org/newest" :rss {"Hacker News" "https://hnrss.org/newest"
"r/Clojure" "https://www.reddit.com/r/clojure/.rss"} "r/Clojure" "https://www.reddit.com/r/clojure/.rss"}
:mastodon {:access_token "XXXX"
;; account number you see when you log in and go to your profile
;; e.g: https://mastodon.social/web/accounts/294795
:account-id "XXXX"
:api_url "https://botsin.space/api/v1/"
}
:transform [{:source {:type :twitter-source :transform [{:source {:type :twitter-source
;; optional, defaults to false ;; optional, defaults to false
:include-replies? false :include-replies? false

View file

@ -13,22 +13,22 @@
[mastodon-bot.tumblr-api :as tumblr] [mastodon-bot.tumblr-api :as tumblr]
[cljs.core :refer [*command-line-args*]])) [cljs.core :refer [*command-line-args*]]))
(s/def ::mastodon-auth masto/mastodon-auth?) (s/def ::mastodon masto/mastodon-auth?)
(s/def ::transform transform/transformations?)
(s/def ::twitter twitter/twitter-auth?) (s/def ::twitter twitter/twitter-auth?)
(s/def ::transform transform/transformations?)
(s/def ::tumblr map?) (s/def ::tumblr map?)
(s/def ::rss map?) (s/def ::rss map?)
(s/def ::auth (s/keys :opt-un [::mastodon ::twitter]))
(def config?
(s/keys :req-un [::auth ::transform]))
(def config? (s/keys :req-un [::mastodon-config] (defn-spec mastodon-auth ::mastodon
:opt-un [::twitter ::tumblr ::rss]))
(defn-spec mastodon-auth ::mastodon-auth
[config config?] [config config?]
(:mastodon-config config)) (get-in config [:auth :mastodon]))
(defn-spec twitter-auth ::twitter (defn-spec twitter-auth ::twitter
[config config?] [config config?]
(:twitter config)) (get-in config [:auth :twitter]))
(defn-spec transform ::transform (defn-spec transform ::transform
[config config?] [config config?]

View file

@ -28,10 +28,7 @@
::visibility ::visibility
::append-screen-name? ::append-screen-name?
::sensitive? ::sensitive?
::media-only? ::media-only?]))
]))
(def mastodon-config? (s/merge mastodon-auth? mastodon-target?))
(defn-spec max-post-length ::max-post-length (defn-spec max-post-length ::max-post-length
[target mastodon-target?] [target mastodon-target?]
@ -45,9 +42,9 @@
(infra/exit-with-error "missing Mastodon auth configuration!"))) (infra/exit-with-error "missing Mastodon auth configuration!")))
(defn-spec delete-status any? (defn-spec delete-status any?
[mastodon-config mastodon-config? [mastodon-auth mastodon-auth?
status-id string?] status-id string?]
(.delete (mastodon-client mastodon-config) (str "statuses/" status-id) #js {})) (.delete (mastodon-client mastodon-auth) (str "statuses/" status-id) #js {}))
(defn post-status (defn post-status
([mastodon-auth target status-text] ([mastodon-auth target status-text]

View file

@ -26,12 +26,11 @@
(defn-spec twitter-client any? (defn-spec twitter-client any?
[twitter-auth twitter-auth?] [twitter-auth twitter-auth?]
(let [{:keys [access-keys]} twitter-auth]
(try (try
(twitter. (clj->js access-keys)) (twitter. (clj->js twitter-auth))
(catch js/Error e (catch js/Error e
(infra/exit-with-error (infra/exit-with-error
(str "failed to connect to Twitter: " (.-message e))))))) (str "failed to connect to Twitter: " (.-message e))))))
(defn strip-utm [news-link] (defn strip-utm [news-link]
(first (string/split news-link #"\?utm"))) (first (string/split news-link #"\?utm")))