now it works
This commit is contained in:
parent
c28d74cc5b
commit
ca16b645bb
3 changed files with 64 additions and 60 deletions
|
@ -16,6 +16,7 @@
|
||||||
(ns dda.masto-embed.api
|
(ns dda.masto-embed.api
|
||||||
(:require
|
(:require
|
||||||
["mastodon-api" :as Mastodon]
|
["mastodon-api" :as Mastodon]
|
||||||
|
[dda.masto-embed.infra :as infra]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[clojure.spec.test.alpha :as st]
|
[clojure.spec.test.alpha :as st]
|
||||||
[orchestra.core :refer-macros [defn-spec]]
|
[orchestra.core :refer-macros [defn-spec]]
|
||||||
|
@ -25,12 +26,8 @@
|
||||||
(s/def ::account-id string?)
|
(s/def ::account-id string?)
|
||||||
(s/def ::host-url string?)
|
(s/def ::host-url string?)
|
||||||
|
|
||||||
(defn exit-with-error [error]
|
(defn masto->edn [response]
|
||||||
(js/console.error error)
|
(-> response .-data infra/js->edn))
|
||||||
(js/process.exit 1))
|
|
||||||
|
|
||||||
(defn js->edn [data]
|
|
||||||
(js->clj data :keywordize-keys true))
|
|
||||||
|
|
||||||
(defn-spec mastodon-client any?
|
(defn-spec mastodon-client any?
|
||||||
[host-url ::host-url]
|
[host-url ::host-url]
|
||||||
|
@ -41,30 +38,13 @@
|
||||||
|
|
||||||
(defn-spec get-account-statuses any?
|
(defn-spec get-account-statuses any?
|
||||||
[host-url ::host-url
|
[host-url ::host-url
|
||||||
account-id ::account-id
|
account-id ::account-id]
|
||||||
callback fn?]
|
(.get (mastodon-client host-url)
|
||||||
(.then (.get (mastodon-client host-url)
|
|
||||||
(str "accounts/" account-id "/statuses")
|
(str "accounts/" account-id "/statuses")
|
||||||
#js {})
|
#js {}))
|
||||||
#(let [response (-> % .-data js->edn)]
|
|
||||||
(if-let [error (:error response)]
|
|
||||||
(exit-with-error error)
|
|
||||||
(callback response)))))
|
|
||||||
|
|
||||||
(defn-spec get-directory-old any?
|
|
||||||
[host-url ::host-url
|
|
||||||
callback fn?]
|
|
||||||
(.then (.get (mastodon-client host-url)
|
|
||||||
(str "directory?local=true")
|
|
||||||
#js {})
|
|
||||||
#(let [response (-> % .-data js->edn)]
|
|
||||||
(callback response))))
|
|
||||||
|
|
||||||
(defn-spec get-directory any?
|
(defn-spec get-directory any?
|
||||||
[host-url ::host-url]
|
[host-url ::host-url]
|
||||||
(go (let [result (<p! (.get (mastodon-client host-url)
|
(.get (mastodon-client host-url)
|
||||||
(str "directory?local=true")
|
(str "directory?local=true")
|
||||||
#js {}))]
|
#js {}))
|
||||||
(-> result
|
|
||||||
.-data
|
|
||||||
js->edn))))
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
(ns dda.masto-embed.app
|
(ns dda.masto-embed.app
|
||||||
(:require
|
(:require
|
||||||
[dda.masto-embed.api :as api]
|
[dda.masto-embed.api :as api]
|
||||||
|
[dda.masto-embed.infra :as infra]
|
||||||
[cljs.core.async :refer [go close! put! take! timeout chan <! >!]]
|
[cljs.core.async :refer [go close! put! take! timeout chan <! >!]]
|
||||||
[cljs.core.async.interop :refer-macros [<p!]]
|
[cljs.core.async.interop :refer-macros [<p!]]
|
||||||
[clojure.pprint :as pprint :refer [pprint]]))
|
[clojure.pprint :as pprint :refer [pprint]]))
|
||||||
|
@ -26,8 +27,8 @@
|
||||||
(-> js/document
|
(-> js/document
|
||||||
(.getElementById masto-embed)
|
(.getElementById masto-embed)
|
||||||
(.getAttribute "host_url")))
|
(.getAttribute "host_url")))
|
||||||
(defn account-name-from-document []
|
|
||||||
|
|
||||||
|
(defn account-name-from-document []
|
||||||
(-> js/document
|
(-> js/document
|
||||||
(.getElementById masto-embed)
|
(.getElementById masto-embed)
|
||||||
(.getAttribute "account_name")))
|
(.getAttribute "account_name")))
|
||||||
|
@ -44,41 +45,34 @@
|
||||||
(.-innerHTML)
|
(.-innerHTML)
|
||||||
(set! input)))
|
(set! input)))
|
||||||
|
|
||||||
(defn debug [elem]
|
|
||||||
(print elem)
|
|
||||||
elem)
|
|
||||||
|
|
||||||
|
|
||||||
(defn find-account-id [host-url account-name]
|
(defn find-account-id [host-url account-name]
|
||||||
(let [in (chan)
|
(let [out (chan)]
|
||||||
out (chan)]
|
|
||||||
(go
|
(go
|
||||||
|
(>! out
|
||||||
(->>
|
(->>
|
||||||
(<! in)
|
(<p! (api/get-directory host-url))
|
||||||
|
api/masto->edn
|
||||||
(filter #(= account-name (:acct %)))
|
(filter #(= account-name (:acct %)))
|
||||||
(map :id)
|
(map :id)
|
||||||
first
|
first
|
||||||
debug
|
;infra/debug
|
||||||
(>! out))
|
)))
|
||||||
(do (close! in)
|
|
||||||
(close! out))
|
|
||||||
)
|
|
||||||
;(api/get-directory host-url #(go (>! in %)))
|
|
||||||
out))
|
out))
|
||||||
|
|
||||||
(defn init []
|
(defn init []
|
||||||
(go
|
(go
|
||||||
(let [account-id (or
|
(let [host-url (host-url-from-document)
|
||||||
|
account-name (account-name-from-document)
|
||||||
|
account-id (or
|
||||||
(account-id-from-document)
|
(account-id-from-document)
|
||||||
(<! (find-account-id "https://social.meissa-gmbh.de" "team")))]
|
(<! (find-account-id host-url account-name)))
|
||||||
(print account-id)
|
status (->
|
||||||
(api/get-account-statuses
|
(<p! (api/get-account-statuses host-url account-id))
|
||||||
(host-url-from-document)
|
api/masto->edn)
|
||||||
account-id
|
]
|
||||||
render-to-document))))
|
(print host-url)
|
||||||
|
(print account-name)
|
||||||
(defn main []
|
|
||||||
(go
|
|
||||||
(let [account-id (<! (find-account-id "https://social.meissa-gmbh.de" "team"))]
|
|
||||||
(print account-id)
|
(print account-id)
|
||||||
|
(print status)
|
||||||
|
(render-to-document status)
|
||||||
)))
|
)))
|
||||||
|
|
30
src/main/dda/masto_embed/infra.cljs
Normal file
30
src/main/dda/masto_embed/infra.cljs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
; Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
; or more contributor license agreements. See the NOTICE file
|
||||||
|
; distributed with this work for additional information
|
||||||
|
; regarding copyright ownership. The ASF licenses this file
|
||||||
|
; to you under the Apache License, Version 2.0 (the
|
||||||
|
; "License"); you may not use this file except in compliance
|
||||||
|
; with the License. You may obtain a copy of the License at
|
||||||
|
;
|
||||||
|
; http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
;
|
||||||
|
; Unless required by applicable law or agreed to in writing, software
|
||||||
|
; distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
; See the License for the specific language governing permissions and
|
||||||
|
; limitations under the License.
|
||||||
|
(ns dda.masto-embed.infra
|
||||||
|
(:require
|
||||||
|
[cljs.core.async :refer [go]]
|
||||||
|
[cljs.core.async.interop :refer-macros [<p!]]))
|
||||||
|
|
||||||
|
(defn exit-with-error [error]
|
||||||
|
(js/console.error error)
|
||||||
|
(js/process.exit 1))
|
||||||
|
|
||||||
|
(defn js->edn [data]
|
||||||
|
(js->clj data :keywordize-keys true))
|
||||||
|
|
||||||
|
(defn debug [elem]
|
||||||
|
(print elem)
|
||||||
|
elem)
|
Loading…
Reference in a new issue