mirror of
https://github.com/penpot/penpot.git
synced 2025-05-29 00:47:21 +02:00
🔥 Remove old repo code.
And make closure-defnes parametrizable.
This commit is contained in:
parent
1724f55cb2
commit
b6f6ab490f
24 changed files with 173 additions and 715 deletions
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
(ns uxbox.config)
|
(ns uxbox.config)
|
||||||
|
|
||||||
(goog-define url "http://127.0.0.1:6060/api")
|
(goog-define url "http://127.0.0.1:6060")
|
||||||
(goog-define viewurl "/view/index.html")
|
|
||||||
(goog-define demo-warning false)
|
(goog-define demo-warning false)
|
||||||
(goog-define default-language "en")
|
(goog-define default-language "en")
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[potok.core :as ptk]
|
[potok.core :as ptk]
|
||||||
[uxbox.common.spec :as us]
|
[uxbox.common.spec :as us]
|
||||||
[uxbox.main.repo.core :as rp]
|
[uxbox.main.repo :as rp]
|
||||||
[uxbox.main.store :refer [initial-state]]
|
[uxbox.main.store :refer [initial-state]]
|
||||||
[uxbox.main.data.users :as du]
|
[uxbox.main.data.users :as du]
|
||||||
[uxbox.util.messages :as um]
|
[uxbox.util.messages :as um]
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
[potok.core :as ptk]
|
[potok.core :as ptk]
|
||||||
[uxbox.main.repo.core :as rp]
|
[uxbox.main.repo :as rp]
|
||||||
[uxbox.main.store :as st]
|
[uxbox.main.store :as st]
|
||||||
[uxbox.util.color :as color]
|
[uxbox.util.color :as color]
|
||||||
[uxbox.util.i18n :refer [tr]]
|
[uxbox.util.i18n :refer [tr]]
|
||||||
|
|
|
@ -109,7 +109,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state s]
|
(watch [_ state s]
|
||||||
(let [params {:page id :pinned true}]
|
(let [params {:page id :pinned true}]
|
||||||
(->> (rp/req :fetch/page-history params)
|
#_(->> (rp/req :fetch/page-history params)
|
||||||
(rx/map :payload)
|
(rx/map :payload)
|
||||||
(rx/map pinned-history-fetched))))))
|
(rx/map pinned-history-fetched))))))
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@
|
||||||
:max (or max 20)}
|
:max (or max 20)}
|
||||||
(when since
|
(when since
|
||||||
{:since since}))]
|
{:since since}))]
|
||||||
(->> (rp/req :fetch/page-history params)
|
#_(->> (rp/req :fetch/page-history params)
|
||||||
(rx/map :payload)
|
(rx/map :payload)
|
||||||
(rx/map history-fetched)))))))
|
(rx/map history-fetched)))))))
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(->> (rp/req :update/page-history item)
|
#_(->> (rp/req :update/page-history item)
|
||||||
(rx/map :payload)
|
(rx/map :payload)
|
||||||
(rx/map history-updated))
|
(rx/map history-updated))
|
||||||
(->> (rx/filter history-updated? stream)
|
(->> (rx/filter history-updated? stream)
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[potok.core :as ptk]
|
[potok.core :as ptk]
|
||||||
[uxbox.main.repo.core :as rp]
|
[uxbox.main.repo :as rp]
|
||||||
[uxbox.main.store :as st]
|
[uxbox.main.store :as st]
|
||||||
[uxbox.util.data :refer (jscoll->vec)]
|
[uxbox.util.data :refer (jscoll->vec)]
|
||||||
[uxbox.util.dom :as dom]
|
[uxbox.util.dom :as dom]
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
[potok.core :as ptk]
|
[potok.core :as ptk]
|
||||||
[uxbox.common.spec :as us]
|
[uxbox.common.spec :as us]
|
||||||
[uxbox.main.store :as st]
|
[uxbox.main.store :as st]
|
||||||
[uxbox.main.repo.core :as rp]
|
[uxbox.main.repo :as rp]
|
||||||
[uxbox.util.i18n :refer [tr]]
|
[uxbox.util.i18n :refer [tr]]
|
||||||
[uxbox.util.router :as rt]
|
[uxbox.util.router :as rt]
|
||||||
[uxbox.util.data :refer (jscoll->vec)]
|
[uxbox.util.data :refer (jscoll->vec)]
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
[potok.core :as ptk]
|
[potok.core :as ptk]
|
||||||
[uxbox.common.pages :as cp]
|
[uxbox.common.pages :as cp]
|
||||||
[uxbox.common.spec :as us]
|
[uxbox.common.spec :as us]
|
||||||
[uxbox.main.repo.core :as rp]
|
[uxbox.main.repo :as rp]
|
||||||
[uxbox.util.router :as rt]
|
[uxbox.util.router :as rt]
|
||||||
[uxbox.util.time :as dt]
|
[uxbox.util.time :as dt]
|
||||||
[uxbox.util.timers :as ts]
|
[uxbox.util.timers :as ts]
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[potok.core :as ptk]
|
[potok.core :as ptk]
|
||||||
[uxbox.common.spec :as us]
|
[uxbox.common.spec :as us]
|
||||||
[uxbox.main.repo.core :as rp]
|
[uxbox.main.repo :as rp]
|
||||||
[uxbox.util.i18n :as i18n :refer [tr]]
|
[uxbox.util.i18n :as i18n :refer [tr]]
|
||||||
[uxbox.util.messages :as uum]
|
[uxbox.util.messages :as uum]
|
||||||
[uxbox.util.storage :refer [storage]]))
|
[uxbox.util.storage :refer [storage]]))
|
||||||
|
@ -87,7 +87,7 @@
|
||||||
(assoc :email (:email data))
|
(assoc :email (:email data))
|
||||||
(assoc :username (:username data))
|
(assoc :username (:username data))
|
||||||
(assoc-in [:metadata :language] (:language data)))]
|
(assoc-in [:metadata :language] (:language data)))]
|
||||||
(->> (rp/req :update/profile data)
|
#_(->> (rp/req :update/profile data)
|
||||||
(rx/map :payload)
|
(rx/map :payload)
|
||||||
(rx/do on-success)
|
(rx/do on-success)
|
||||||
(rx/map profile-fetched)
|
(rx/map profile-fetched)
|
||||||
|
@ -110,7 +110,7 @@
|
||||||
(watch [_ state s]
|
(watch [_ state s]
|
||||||
(let [params {:old-password (:password-old data)
|
(let [params {:old-password (:password-old data)
|
||||||
:password (:password-1 data)}]
|
:password (:password-1 data)}]
|
||||||
(->> (rp/req :update/profile-password params)
|
#_(->> (rp/req :update/profile-password params)
|
||||||
(rx/catch rp/client-error? (fn [e]
|
(rx/catch rp/client-error? (fn [e]
|
||||||
(on-error (:payload e))
|
(on-error (:payload e))
|
||||||
(rx/empty)))
|
(rx/empty)))
|
||||||
|
@ -123,7 +123,7 @@
|
||||||
(deftype UpdatePhoto [file done]
|
(deftype UpdatePhoto [file done]
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(->> (rp/req :update/profile-photo {:file file})
|
#_(->> (rp/req :update/profile-photo {:file file})
|
||||||
(rx/do done)
|
(rx/do done)
|
||||||
(rx/map (constantly fetch-profile)))))
|
(rx/map (constantly fetch-profile)))))
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
[uxbox.main.data.projects :as dp]
|
[uxbox.main.data.projects :as dp]
|
||||||
[uxbox.main.geom :as geom]
|
[uxbox.main.geom :as geom]
|
||||||
[uxbox.main.refs :as refs]
|
[uxbox.main.refs :as refs]
|
||||||
[uxbox.main.repo.core :as rp]
|
[uxbox.main.repo :as rp]
|
||||||
[uxbox.main.store :as st]
|
[uxbox.main.store :as st]
|
||||||
[uxbox.main.streams :as ms]
|
[uxbox.main.streams :as ms]
|
||||||
[uxbox.main.websockets :as ws]
|
[uxbox.main.websockets :as ws]
|
||||||
|
@ -77,8 +77,8 @@
|
||||||
(ptk/reify ::initialize
|
(ptk/reify ::initialize
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [uri (str "ws://localhost:6060/sub/" file-id)]
|
(let [url (ws/url (str "/sub/" file-id))]
|
||||||
(assoc-in state [:ws file-id] (ws/open uri))))
|
(assoc-in state [:ws file-id] (ws/open url))))
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
|
|
@ -2,27 +2,137 @@
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
||||||
|
|
||||||
(ns uxbox.main.repo
|
(ns uxbox.main.repo
|
||||||
"A main interface for access to remote resources."
|
(:require
|
||||||
(:require [uxbox.util.http :as http]
|
[beicon.core :as rx]
|
||||||
[uxbox.main.repo.auth]
|
[cuerdas.core :as str]
|
||||||
[uxbox.main.repo.users]
|
[uxbox.config :refer [url]]
|
||||||
[uxbox.main.repo.projects]
|
[uxbox.util.http :as http]
|
||||||
[uxbox.main.repo.pages]
|
[uxbox.util.storage :refer [storage]]
|
||||||
[uxbox.main.repo.images]
|
[uxbox.util.transit :as t])
|
||||||
[uxbox.main.repo.icons]
|
(:import [goog.Uri QueryData]))
|
||||||
[uxbox.main.repo.kvstore]
|
|
||||||
[uxbox.main.repo.impl :as impl]))
|
|
||||||
|
|
||||||
(defn req
|
;; --- Low Level API
|
||||||
"Perform a side effectfull action accesing
|
|
||||||
remote resources."
|
(defn- conditional-decode
|
||||||
([type]
|
[{:keys [body headers] :as response}]
|
||||||
(impl/request type nil))
|
(let [contentype (get headers "content-type")]
|
||||||
([type data]
|
(if (str/starts-with? contentype "application/transit+json")
|
||||||
(impl/request type data)))
|
(assoc response :body (t/decode body))
|
||||||
|
response)))
|
||||||
|
|
||||||
|
(defn- handle-http-status
|
||||||
|
[{:keys [body status] :as response}]
|
||||||
|
(if (http/success? response)
|
||||||
|
(rx/of {:status status :payload body})
|
||||||
|
(rx/throw {:status status :payload body})))
|
||||||
|
|
||||||
|
(def ^:private +headers+
|
||||||
|
{"content-type" "application/transit+json"})
|
||||||
|
|
||||||
|
(defn- encode-query
|
||||||
|
[params]
|
||||||
|
(let [data (QueryData.)]
|
||||||
|
(.extend data (clj->js params))
|
||||||
|
(.toString data)))
|
||||||
|
|
||||||
|
(defn impl-send
|
||||||
|
[{:keys [body headers auth method query url response-type]
|
||||||
|
:or {auth true response-type :text}}]
|
||||||
|
(let [headers (merge {"Accept" "application/transit+json,*/*"}
|
||||||
|
(when (map? body) +headers+)
|
||||||
|
headers)
|
||||||
|
request {:method method
|
||||||
|
:url url
|
||||||
|
:headers headers
|
||||||
|
:query-string (when query (encode-query query))
|
||||||
|
:body (if (map? body) (t/encode body) body)}
|
||||||
|
options {:response-type response-type
|
||||||
|
:credentials? true}]
|
||||||
|
(http/send! request options)))
|
||||||
|
|
||||||
|
(defn send!
|
||||||
|
[request]
|
||||||
|
(->> (impl-send request)
|
||||||
|
(rx/map conditional-decode)
|
||||||
|
(rx/mapcat handle-http-status)))
|
||||||
|
|
||||||
|
;; --- High Level API
|
||||||
|
|
||||||
|
(defn- handle-response
|
||||||
|
[response]
|
||||||
|
;; (prn "handle-response1" response)
|
||||||
|
(cond
|
||||||
|
(http/success? response)
|
||||||
|
(rx/of (:body response))
|
||||||
|
|
||||||
|
(http/client-error? response)
|
||||||
|
(rx/throw (:body response))
|
||||||
|
|
||||||
|
:else
|
||||||
|
(rx/throw {:type :unexpected
|
||||||
|
:code (:error response)})))
|
||||||
|
|
||||||
|
(defn send-query!
|
||||||
|
[id params]
|
||||||
|
(let [url (str url "/api/w/query/" (name id))]
|
||||||
|
(->> (impl-send {:method :get :url url :query params})
|
||||||
|
(rx/map conditional-decode)
|
||||||
|
(rx/mapcat handle-response))))
|
||||||
|
|
||||||
|
(defn send-mutation!
|
||||||
|
[id params]
|
||||||
|
(let [url (str url "/api/w/mutation/" (name id))]
|
||||||
|
(->> (impl-send {:method :post :url url :body params})
|
||||||
|
(rx/map conditional-decode)
|
||||||
|
(rx/mapcat handle-response))))
|
||||||
|
|
||||||
|
(defn- dispatch
|
||||||
|
[& args]
|
||||||
|
(first args))
|
||||||
|
|
||||||
|
(defmulti query dispatch)
|
||||||
|
(defmulti mutation dispatch)
|
||||||
|
|
||||||
|
(defmethod query :default
|
||||||
|
[id params]
|
||||||
|
(send-query! id params))
|
||||||
|
|
||||||
|
(defmethod mutation :default
|
||||||
|
[id params]
|
||||||
|
(send-mutation! id params))
|
||||||
|
|
||||||
|
(defn query!
|
||||||
|
([id] (query id {}))
|
||||||
|
([id params] (query id params)))
|
||||||
|
|
||||||
|
(defn mutation!
|
||||||
|
([id] (mutation id {}))
|
||||||
|
([id params] (mutation id params)))
|
||||||
|
|
||||||
|
(defmethod mutation :create-image
|
||||||
|
[id params]
|
||||||
|
(let [form (js/FormData.)]
|
||||||
|
(run! (fn [[key val]]
|
||||||
|
(.append form (name key) val))
|
||||||
|
(seq params))
|
||||||
|
(send-mutation! id form)))
|
||||||
|
|
||||||
|
(defmethod mutation :login
|
||||||
|
[id params]
|
||||||
|
(let [url (str url "/login")]
|
||||||
|
(->> (impl-send {:method :post :url url :body params})
|
||||||
|
(rx/map conditional-decode)
|
||||||
|
(rx/mapcat handle-response))))
|
||||||
|
|
||||||
|
(defmethod mutation :logout
|
||||||
|
[id params]
|
||||||
|
(let [url (str url "/logout")]
|
||||||
|
(->> (impl-send {:method :post :url url :body params :auth false})
|
||||||
|
(rx/map conditional-decode)
|
||||||
|
(rx/mapcat handle-response))))
|
||||||
|
|
||||||
(def client-error? http/client-error?)
|
(def client-error? http/client-error?)
|
||||||
(def server-error? http/server-error?)
|
(def server-error? http/server-error?)
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns uxbox.main.repo.auth
|
|
||||||
"A main interface for access to remote resources."
|
|
||||||
(:require [beicon.core :as rx]
|
|
||||||
[uxbox.config :refer (url)]
|
|
||||||
[uxbox.main.repo.impl :refer (request send!)]))
|
|
||||||
|
|
||||||
(defmethod request :fetch/profile
|
|
||||||
[type _]
|
|
||||||
(let [url (str url "/w/query/profile")]
|
|
||||||
(send! {:method :get :url url})))
|
|
||||||
|
|
||||||
(defmethod request :auth/login
|
|
||||||
[type data]
|
|
||||||
(let [url (str url "/login")]
|
|
||||||
(send! {:url url
|
|
||||||
:method :post
|
|
||||||
:auth false
|
|
||||||
:body data})))
|
|
||||||
|
|
||||||
(defmethod request :auth/logout
|
|
||||||
[type data]
|
|
||||||
(let [url (str url "/logout")]
|
|
||||||
(send! {:url url :method :post :auth false})))
|
|
||||||
|
|
||||||
(defmethod request :update/profile
|
|
||||||
[type data]
|
|
||||||
(let [params {:url (str url "/profile/me")
|
|
||||||
:method :put
|
|
||||||
:body data}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :auth/register
|
|
||||||
[_ data]
|
|
||||||
(let [params {:url (str url "/auth/register")
|
|
||||||
:method :post
|
|
||||||
:body data}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :auth/recovery-request
|
|
||||||
[_ data]
|
|
||||||
(let [params {:url (str url "/auth/recovery")
|
|
||||||
:method :post
|
|
||||||
:body data}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :auth/validate-recovery-token
|
|
||||||
[_ token]
|
|
||||||
(let [params {:url (str url "/auth/recovery/" token)
|
|
||||||
:method :get}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :auth/recovery
|
|
||||||
[_ data]
|
|
||||||
(let [params {:url (str url "/auth/recovery")
|
|
||||||
:method :put
|
|
||||||
:body data}]
|
|
||||||
(send! params)))
|
|
|
@ -1,60 +0,0 @@
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns uxbox.main.repo.colors
|
|
||||||
"A main interface for access to remote resources."
|
|
||||||
(:require [beicon.core :as rx]
|
|
||||||
[uxbox.config :refer (url)]
|
|
||||||
[uxbox.main.repo.impl :refer (request send!)]
|
|
||||||
[uxbox.util.transit :as t]))
|
|
||||||
|
|
||||||
(defn- decode-color-collection
|
|
||||||
[{:keys [data] :as coll}]
|
|
||||||
(merge coll
|
|
||||||
(when data {:data (t/decode data)})))
|
|
||||||
|
|
||||||
(defn- decode-payload
|
|
||||||
[{:keys [payload] :as rsp}]
|
|
||||||
(if (sequential? payload)
|
|
||||||
(assoc rsp :payload (mapv decode-color-collection payload))
|
|
||||||
(assoc rsp :payload (decode-color-collection payload))))
|
|
||||||
|
|
||||||
(defmethod request :fetch/color-collection
|
|
||||||
[_ id]
|
|
||||||
(let [params {:url (str url "/library/color-collections/" id)
|
|
||||||
:method :get}]
|
|
||||||
(->> (send! params)
|
|
||||||
(rx/map decode-payload))))
|
|
||||||
|
|
||||||
(defmethod request :fetch/color-collections
|
|
||||||
[_]
|
|
||||||
(let [params {:url (str url "/library/color-collections")
|
|
||||||
:method :get}]
|
|
||||||
(->> (send! params)
|
|
||||||
(rx/map decode-payload))))
|
|
||||||
|
|
||||||
(defmethod request :delete/color-collection
|
|
||||||
[_ id]
|
|
||||||
(let [url (str url "/library/color-collections/" id)]
|
|
||||||
(send! {:url url :method :delete})))
|
|
||||||
|
|
||||||
(defmethod request :create/color-collection
|
|
||||||
[_ {:keys [data] :as body}]
|
|
||||||
(let [body (assoc body :data (t/encode data))
|
|
||||||
params {:url (str url "/library/color-collections")
|
|
||||||
:method :post
|
|
||||||
:body body}]
|
|
||||||
(->> (send! params)
|
|
||||||
(rx/map decode-payload))))
|
|
||||||
|
|
||||||
(defmethod request :update/color-collection
|
|
||||||
[_ {:keys [id data] :as body}]
|
|
||||||
(let [body (assoc body :data (t/encode data))
|
|
||||||
params {:url (str url "/library/color-collections/" id)
|
|
||||||
:method :put
|
|
||||||
:body body}]
|
|
||||||
(->> (send! params)
|
|
||||||
(rx/map decode-payload))))
|
|
|
@ -1,156 +0,0 @@
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns uxbox.main.repo.core
|
|
||||||
(:require
|
|
||||||
[beicon.core :as rx]
|
|
||||||
[cuerdas.core :as str]
|
|
||||||
[uxbox.main.repo.impl :as impl]
|
|
||||||
[uxbox.config :refer [url]]
|
|
||||||
[uxbox.util.http :as http]
|
|
||||||
[uxbox.util.storage :refer [storage]]
|
|
||||||
[uxbox.util.transit :as t])
|
|
||||||
(:import [goog.Uri QueryData]))
|
|
||||||
|
|
||||||
;; --- Low Level API
|
|
||||||
|
|
||||||
(defn- conditional-decode
|
|
||||||
[{:keys [body headers] :as response}]
|
|
||||||
(let [contentype (get headers "content-type")]
|
|
||||||
(if (str/starts-with? contentype "application/transit+json")
|
|
||||||
(assoc response :body (t/decode body))
|
|
||||||
response)))
|
|
||||||
|
|
||||||
(defn- handle-http-status
|
|
||||||
[{:keys [body status] :as response}]
|
|
||||||
(if (http/success? response)
|
|
||||||
(rx/of {:status status :payload body})
|
|
||||||
(rx/throw {:status status :payload body})))
|
|
||||||
|
|
||||||
(def ^:private +headers+
|
|
||||||
{"content-type" "application/transit+json"})
|
|
||||||
|
|
||||||
(defn- encode-query
|
|
||||||
[params]
|
|
||||||
(let [data (QueryData.)]
|
|
||||||
(.extend data (clj->js params))
|
|
||||||
(.toString data)))
|
|
||||||
|
|
||||||
(defn impl-send
|
|
||||||
[{:keys [body headers auth method query url response-type]
|
|
||||||
:or {auth true response-type :text}}]
|
|
||||||
(let [headers (merge {"Accept" "application/transit+json,*/*"}
|
|
||||||
(when (map? body) +headers+)
|
|
||||||
headers)
|
|
||||||
request {:method method
|
|
||||||
:url url
|
|
||||||
:headers headers
|
|
||||||
:query-string (when query (encode-query query))
|
|
||||||
:body (if (map? body) (t/encode body) body)}
|
|
||||||
options {:response-type response-type
|
|
||||||
:credentials? true}]
|
|
||||||
(http/send! request options)))
|
|
||||||
|
|
||||||
(defn send!
|
|
||||||
[request]
|
|
||||||
(->> (impl-send request)
|
|
||||||
(rx/map conditional-decode)
|
|
||||||
(rx/mapcat handle-http-status)))
|
|
||||||
|
|
||||||
;; --- High Level API
|
|
||||||
|
|
||||||
(defn- handle-response
|
|
||||||
[response]
|
|
||||||
;; (prn "handle-response1" response)
|
|
||||||
(cond
|
|
||||||
(http/success? response)
|
|
||||||
(rx/of (:body response))
|
|
||||||
|
|
||||||
(http/client-error? response)
|
|
||||||
(rx/throw (:body response))
|
|
||||||
|
|
||||||
:else
|
|
||||||
(rx/throw {:type :unexpected
|
|
||||||
:code (:error response)})))
|
|
||||||
|
|
||||||
(defn send-query!
|
|
||||||
[id params]
|
|
||||||
(let [url (str url "/w/query/" (name id))]
|
|
||||||
(->> (impl-send {:method :get :url url :query params})
|
|
||||||
(rx/map conditional-decode)
|
|
||||||
(rx/mapcat handle-response))))
|
|
||||||
|
|
||||||
(defn send-mutation!
|
|
||||||
[id params]
|
|
||||||
(let [url (str url "/w/mutation/" (name id))]
|
|
||||||
(->> (impl-send {:method :post :url url :body params})
|
|
||||||
(rx/map conditional-decode)
|
|
||||||
(rx/mapcat handle-response))))
|
|
||||||
|
|
||||||
(defn- dispatch
|
|
||||||
[& args]
|
|
||||||
(first args))
|
|
||||||
|
|
||||||
(defmulti query dispatch)
|
|
||||||
(defmulti mutation dispatch)
|
|
||||||
|
|
||||||
(defmethod query :default
|
|
||||||
[id params]
|
|
||||||
(send-query! id params))
|
|
||||||
|
|
||||||
(defmethod mutation :default
|
|
||||||
[id params]
|
|
||||||
(send-mutation! id params))
|
|
||||||
|
|
||||||
(defn query!
|
|
||||||
([id] (query id {}))
|
|
||||||
([id params] (query id params)))
|
|
||||||
|
|
||||||
(defn mutation!
|
|
||||||
([id] (mutation id {}))
|
|
||||||
([id params] (mutation id params)))
|
|
||||||
|
|
||||||
;; --- Legacy Api
|
|
||||||
|
|
||||||
(defn req
|
|
||||||
"Perform a side effectfull action accesing
|
|
||||||
remote resources."
|
|
||||||
([type]
|
|
||||||
(impl/request type nil))
|
|
||||||
([type data]
|
|
||||||
(impl/request type data)))
|
|
||||||
|
|
||||||
(def client-error? http/client-error?)
|
|
||||||
(def server-error? http/server-error?)
|
|
||||||
|
|
||||||
(defmethod mutation :create-image
|
|
||||||
[id params]
|
|
||||||
(let [form (js/FormData.)]
|
|
||||||
(run! (fn [[key val]]
|
|
||||||
(.append form (name key) val))
|
|
||||||
(seq params))
|
|
||||||
(send-mutation! id form)))
|
|
||||||
|
|
||||||
(defmethod mutation :login
|
|
||||||
[id params]
|
|
||||||
(let [url (str url "/login")]
|
|
||||||
(->> (impl-send {:method :post :url url :body params})
|
|
||||||
(rx/map conditional-decode)
|
|
||||||
(rx/mapcat handle-response))))
|
|
||||||
|
|
||||||
(defmethod mutation :logout
|
|
||||||
[id params]
|
|
||||||
(let [url (str url "/logout")]
|
|
||||||
(->> (impl-send {:method :post :url url :body params :auth false})
|
|
||||||
(rx/map conditional-decode)
|
|
||||||
(rx/mapcat handle-response))))
|
|
||||||
|
|
||||||
;; (defmethod mutation :register-profile
|
|
||||||
;; [id params]
|
|
||||||
;; (let [url (str url "/register")]
|
|
||||||
;; (->> (impl-send {:method :post :url url :body params :auth false})
|
|
||||||
;; (rx/map conditional-decode)
|
|
||||||
;; (rx/mapcat handle-response))))
|
|
|
@ -1,71 +0,0 @@
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns uxbox.main.repo.icons
|
|
||||||
"A main interface for access to remote resources."
|
|
||||||
(:require [beicon.core :as rx]
|
|
||||||
[uxbox.config :refer (url)]
|
|
||||||
[uxbox.main.repo.impl :refer (request send!)]
|
|
||||||
[uxbox.util.transit :as t]))
|
|
||||||
|
|
||||||
(defmethod request :fetch/icon-collections
|
|
||||||
[_]
|
|
||||||
(let [params {:url (str url "/library/icon-collections")
|
|
||||||
:method :get}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :delete/icon-collection
|
|
||||||
[_ id]
|
|
||||||
(let [url (str url "/library/icon-collections/" id)]
|
|
||||||
(send! {:url url :method :delete})))
|
|
||||||
|
|
||||||
(defmethod request :create/icon-collection
|
|
||||||
[_ {:keys [data] :as body}]
|
|
||||||
(let [body (assoc body :data (t/encode data))
|
|
||||||
params {:url (str url "/library/icon-collections")
|
|
||||||
:method :post
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :update/icon-collection
|
|
||||||
[_ {:keys [id data] :as body}]
|
|
||||||
(let [body (assoc body :data (t/encode data))
|
|
||||||
params {:url (str url "/library/icon-collections/" id)
|
|
||||||
:method :put
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :fetch/icons
|
|
||||||
[_ {:keys [coll]}]
|
|
||||||
(let [url (str url "/library/icons")
|
|
||||||
qp (if coll {:collection coll} nil)
|
|
||||||
params {:url url :method :get :query qp}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :fetch/icon
|
|
||||||
[_ {:keys [id]}]
|
|
||||||
(let [params {:url (str url "/library/icons/" id)
|
|
||||||
:method :get}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :create/icon
|
|
||||||
[_ body]
|
|
||||||
(let [params {:url (str url "/library/icons")
|
|
||||||
:method :post
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :delete/icon
|
|
||||||
[_ id]
|
|
||||||
(let [url (str url "/library/icons/" id)]
|
|
||||||
(send! {:url url :method :delete})))
|
|
||||||
|
|
||||||
(defmethod request :update/icon
|
|
||||||
[_ {:keys [id collection] :as body}]
|
|
||||||
(let [params {:url (str url "/library/icons/" id)
|
|
||||||
:method :put
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
|
@ -1,87 +0,0 @@
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns uxbox.main.repo.images
|
|
||||||
"A main interface for access to remote resources."
|
|
||||||
(:require [beicon.core :as rx]
|
|
||||||
[uxbox.config :refer (url)]
|
|
||||||
[uxbox.main.repo.impl :refer (request send!)]
|
|
||||||
[uxbox.util.transit :as t]))
|
|
||||||
|
|
||||||
(defmethod request :fetch/image-collections
|
|
||||||
[_]
|
|
||||||
(let [params {:url (str url "/library/image-collections")
|
|
||||||
:method :get}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :delete/image-collection
|
|
||||||
[_ id]
|
|
||||||
(let [url (str url "/library/image-collections/" id)]
|
|
||||||
(send! {:url url :method :delete})))
|
|
||||||
|
|
||||||
(defmethod request :create/image-collection
|
|
||||||
[_ {:keys [data] :as body}]
|
|
||||||
(let [body (assoc body :data (t/encode data))
|
|
||||||
params {:url (str url "/library/image-collections")
|
|
||||||
:method :post
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :update/image-collection
|
|
||||||
[_ {:keys [id data] :as body}]
|
|
||||||
(let [body (assoc body :data (t/encode data))
|
|
||||||
params {:url (str url "/library/image-collections/" id)
|
|
||||||
:method :put
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :fetch/images
|
|
||||||
[_ {:keys [coll]}]
|
|
||||||
(let [url (str url "/library/images")
|
|
||||||
qp (when coll {:collection coll})
|
|
||||||
params {:url url :method :get :query qp}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :fetch/image
|
|
||||||
[_ {:keys [id]}]
|
|
||||||
(let [params {:url (str url "/library/images/" id)
|
|
||||||
:method :get}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :create/image
|
|
||||||
[_ {:keys [collection id file width height mimetype] :as body}]
|
|
||||||
(let [body (doto (js/FormData.)
|
|
||||||
(.append "mimetype" mimetype)
|
|
||||||
(.append "file" file)
|
|
||||||
(.append "width" width)
|
|
||||||
(.append "height" height)
|
|
||||||
(.append "id" id))
|
|
||||||
_ (when collection
|
|
||||||
(.append body "collection" (str collection)))
|
|
||||||
|
|
||||||
params {:url (str url "/library/images")
|
|
||||||
:method :post
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :delete/image
|
|
||||||
[_ id]
|
|
||||||
(let [url (str url "/library/images/" id)]
|
|
||||||
(send! {:url url :method :delete})))
|
|
||||||
|
|
||||||
(defmethod request :update/image
|
|
||||||
[_ {:keys [id collection] :as body}]
|
|
||||||
(let [params {:url (str url "/library/images/" id)
|
|
||||||
:method :put
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :copy/image
|
|
||||||
[_ {:keys [id collection] :as body}]
|
|
||||||
(let [params {:url (str url "/library/images/" id "/copy")
|
|
||||||
:method :put
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
|
@ -1,61 +0,0 @@
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns uxbox.main.repo.impl
|
|
||||||
(:require [clojure.walk :as walk]
|
|
||||||
[beicon.core :as rx]
|
|
||||||
[cuerdas.core :as str]
|
|
||||||
[uxbox.config :refer (url)]
|
|
||||||
[uxbox.util.http :as http]
|
|
||||||
[uxbox.util.storage :refer (storage)]
|
|
||||||
[uxbox.util.transit :as t])
|
|
||||||
(:import [goog.Uri QueryData]))
|
|
||||||
|
|
||||||
(defn- conditional-decode
|
|
||||||
[{:keys [body headers] :as response}]
|
|
||||||
(let [contentype (get headers "content-type")]
|
|
||||||
(if (str/starts-with? contentype "application/transit+json")
|
|
||||||
(assoc response :body (t/decode body))
|
|
||||||
response)))
|
|
||||||
|
|
||||||
(defn- handle-http-status
|
|
||||||
[{:keys [body status] :as response}]
|
|
||||||
(if (http/success? response)
|
|
||||||
(rx/of {:status status :payload body})
|
|
||||||
(rx/throw {:status status :payload body})))
|
|
||||||
|
|
||||||
(def ^:private +headers+
|
|
||||||
{"content-type" "application/transit+json"})
|
|
||||||
|
|
||||||
(defn- encode-query
|
|
||||||
[params]
|
|
||||||
(let [data (QueryData.)]
|
|
||||||
(.extend data (clj->js params))
|
|
||||||
(.toString data)))
|
|
||||||
|
|
||||||
(defn send!
|
|
||||||
[{:keys [body headers auth method query url response-type]
|
|
||||||
:or {auth true response-type :text}}]
|
|
||||||
(let [headers (merge {"Accept" "application/transit+json,*/*"}
|
|
||||||
(when (map? body) +headers+)
|
|
||||||
headers)
|
|
||||||
request {:method method
|
|
||||||
:url url
|
|
||||||
:headers headers
|
|
||||||
:query-string (when query (encode-query query))
|
|
||||||
:body (if (map? body) (t/encode body) body)}
|
|
||||||
options {:response-type response-type
|
|
||||||
:credentials? true}]
|
|
||||||
(->> (http/send! request options)
|
|
||||||
(rx/map conditional-decode)
|
|
||||||
(rx/mapcat handle-http-status))))
|
|
||||||
|
|
||||||
(defmulti request
|
|
||||||
(fn [type data] type))
|
|
||||||
|
|
||||||
(defmethod request :default
|
|
||||||
[type data]
|
|
||||||
(throw (ex-info (str "No implementation found for " type) {:data data})))
|
|
|
@ -1,29 +0,0 @@
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns uxbox.main.repo.kvstore
|
|
||||||
"A main interface for access to remote resources."
|
|
||||||
(:require [beicon.core :as rx]
|
|
||||||
[cuerdas.core :as str]
|
|
||||||
[uxbox.config :refer (url)]
|
|
||||||
[uxbox.main.repo.impl :refer (request send!)]
|
|
||||||
[uxbox.util.transit :as t]))
|
|
||||||
|
|
||||||
(defmethod request :fetch/kvstore
|
|
||||||
[_ id]
|
|
||||||
(let [url (str url "/kvstore/" id)
|
|
||||||
params {:url url :method :get}]
|
|
||||||
(->> (send! params)
|
|
||||||
(rx/map (fn [{:keys [payload] :as response}]
|
|
||||||
(if (or (nil? payload) (str/empty? payload))
|
|
||||||
(assoc response :payload {:key id :value nil :version nil})
|
|
||||||
response))))))
|
|
||||||
|
|
||||||
(defmethod request :update/kvstore
|
|
||||||
[_ {:keys [id] :as data}]
|
|
||||||
(let [url (str url "/kvstore/" id)
|
|
||||||
params {:url url :method :put :body data}]
|
|
||||||
(send! params)))
|
|
|
@ -1,60 +0,0 @@
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) 2016-2019 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns uxbox.main.repo.pages
|
|
||||||
"A main interface for access to remote resources."
|
|
||||||
(:require
|
|
||||||
[uxbox.config :refer [url]]
|
|
||||||
[uxbox.main.repo.impl :as rp :refer [request send!]]))
|
|
||||||
|
|
||||||
(defmethod request :fetch/pages-by-project
|
|
||||||
[type {:keys [project] :as params}]
|
|
||||||
(let [url (str url "/w/query/pages-by-project")
|
|
||||||
params {:project-id project}]
|
|
||||||
(send! {:method :get :url url :query params})))
|
|
||||||
|
|
||||||
(defmethod request :fetch/page-history
|
|
||||||
[type {:keys [page] :as params}]
|
|
||||||
(let [url (str url "/w/query/page-history")
|
|
||||||
query (-> (select-keys params [:max :since :pinned])
|
|
||||||
(assoc :id page))
|
|
||||||
params {:method :get :url url :query query}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :delete/page
|
|
||||||
[_ id]
|
|
||||||
(let [url (str url "/pages/" id)]
|
|
||||||
(send! {:url url
|
|
||||||
:method :delete})))
|
|
||||||
|
|
||||||
(defmethod request :create/page
|
|
||||||
[type body]
|
|
||||||
(let [params {:url (str url "/pages")
|
|
||||||
:method :post
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :update/page
|
|
||||||
[type {:keys [id] :as body}]
|
|
||||||
(let [params {:url (str url "/w/mutation/update-page")
|
|
||||||
:method :post
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :update/page-metadata
|
|
||||||
[type {:keys [id] :as body}]
|
|
||||||
(let [params {:url (str url "/w/mutation/update-page-metadata")
|
|
||||||
:method :post
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
|
|
||||||
(defmethod request :update/page-history
|
|
||||||
[type {:keys [id page] :as data}]
|
|
||||||
(let [params {:url (str url "/pages/" page "/history/" id)
|
|
||||||
:method :put
|
|
||||||
:body data}]
|
|
||||||
(send! params)))
|
|
|
@ -1,42 +0,0 @@
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns uxbox.main.repo.projects
|
|
||||||
"A main interface for access to remote resources."
|
|
||||||
(:require [beicon.core :as rx]
|
|
||||||
[uxbox.config :refer (url)]
|
|
||||||
[uxbox.main.repo.pages :as pages]
|
|
||||||
[uxbox.main.repo.impl :refer (request send!)]
|
|
||||||
[uxbox.util.transit :as t]))
|
|
||||||
|
|
||||||
(defmethod request :fetch/projects
|
|
||||||
[type data]
|
|
||||||
;; Obtain the list of projects and decode the embedded
|
|
||||||
;; page data in order to have it usable.
|
|
||||||
(send! {:url (str url "/w/query/projects")
|
|
||||||
:method :get}))
|
|
||||||
|
|
||||||
(defmethod request :fetch/project-by-token
|
|
||||||
[_ token]
|
|
||||||
(send! {:url (str url "/projects/by-token/" token)
|
|
||||||
:method :get}))
|
|
||||||
|
|
||||||
(defmethod request :create/project
|
|
||||||
[_ data]
|
|
||||||
(send! {:url (str url "/projects")
|
|
||||||
:method :post
|
|
||||||
:body data}))
|
|
||||||
|
|
||||||
(defmethod request :update/project
|
|
||||||
[_ {:keys [id] :as data}]
|
|
||||||
(send! {:url (str url "/projects/" id)
|
|
||||||
:method :put
|
|
||||||
:body data}))
|
|
||||||
|
|
||||||
(defmethod request :delete/project
|
|
||||||
[_ id]
|
|
||||||
(send! {:url (str url "/projects/" id)
|
|
||||||
:method :delete}))
|
|
|
@ -1,41 +0,0 @@
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
|
||||||
|
|
||||||
(ns uxbox.main.repo.users
|
|
||||||
"A main interface for access to remote resources."
|
|
||||||
(:require [beicon.core :as rx]
|
|
||||||
[uxbox.config :refer (url)]
|
|
||||||
[uxbox.main.repo.impl :refer (request send!)]
|
|
||||||
[uxbox.util.transit :as t]))
|
|
||||||
|
|
||||||
(defmethod request :fetch/profile
|
|
||||||
[type _]
|
|
||||||
(let [url (str url "/profile/me")
|
|
||||||
params {:method :get :url url}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :update/profile
|
|
||||||
[type body]
|
|
||||||
(let [params {:url (str url "/profile/me")
|
|
||||||
:method :put
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :update/profile-password
|
|
||||||
[type data]
|
|
||||||
(let [params {:url (str url "/profile/me/password")
|
|
||||||
:method :put
|
|
||||||
:body data}]
|
|
||||||
(send! params)))
|
|
||||||
|
|
||||||
(defmethod request :update/profile-photo
|
|
||||||
[_ {:keys [file] :as body}]
|
|
||||||
(let [body (doto (js/FormData.)
|
|
||||||
(.append "file" file))
|
|
||||||
params {:url (str url "/profile/me/photo")
|
|
||||||
:method :post
|
|
||||||
:body body}]
|
|
||||||
(send! params)))
|
|
|
@ -8,9 +8,11 @@
|
||||||
"A interface to webworkers exposed functionality."
|
"A interface to webworkers exposed functionality."
|
||||||
(:require
|
(:require
|
||||||
[goog.events :as ev]
|
[goog.events :as ev]
|
||||||
|
[uxbox.config :as cfg]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[potok.core :as ptk])
|
[potok.core :as ptk])
|
||||||
(:import
|
(:import
|
||||||
|
goog.Uri
|
||||||
goog.net.WebSocket
|
goog.net.WebSocket
|
||||||
goog.net.WebSocket.EventType))
|
goog.net.WebSocket.EventType))
|
||||||
|
|
||||||
|
@ -19,6 +21,14 @@
|
||||||
(-send [_ message] "send a message")
|
(-send [_ message] "send a message")
|
||||||
(-close [_] "close websocket"))
|
(-close [_] "close websocket"))
|
||||||
|
|
||||||
|
(defn url
|
||||||
|
[path]
|
||||||
|
(let [url (.parse Uri cfg/url)]
|
||||||
|
(.setPath url path)
|
||||||
|
(if (= (.getScheme url) "http")
|
||||||
|
(.setScheme url "ws")
|
||||||
|
(.setScheme url "wss"))
|
||||||
|
(.toString url)))
|
||||||
|
|
||||||
(defn open
|
(defn open
|
||||||
[uri]
|
[uri]
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
(defrecord LoadData [token]
|
(defrecord LoadData [token]
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(->> (rp/req :fetch/project-by-token token)
|
#_(->> (rp/req :fetch/project-by-token token)
|
||||||
(rx/map :payload)
|
(rx/map :payload)
|
||||||
(rx/map data-loaded))))
|
(rx/map data-loaded))))
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@
|
||||||
(let [existing (get-in state [:images id])]
|
(let [existing (get-in state [:images id])]
|
||||||
(if existing
|
(if existing
|
||||||
(rx/empty)
|
(rx/empty)
|
||||||
(->> (rp/req :fetch/image {:id id})
|
#_(->> (rp/req :fetch/image {:id id})
|
||||||
(rx/map :payload)
|
(rx/map :payload)
|
||||||
(rx/map image-fetched))))))
|
(rx/map image-fetched))))))
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
'[clojure.java.shell :as shell]
|
'[clojure.java.shell :as shell]
|
||||||
'[clojure.java.io :as io]
|
'[clojure.java.io :as io]
|
||||||
'[clojure.edn :as edn]
|
'[clojure.edn :as edn]
|
||||||
|
'[clojure.string :as str]
|
||||||
'[figwheel.main.api :as figwheel]
|
'[figwheel.main.api :as figwheel]
|
||||||
'[environ.core :refer [env]])
|
'[environ.core :refer [env]])
|
||||||
(require '[cljs.build.api :as api]
|
(require '[cljs.build.api :as api]
|
||||||
|
@ -27,12 +28,21 @@
|
||||||
|
|
||||||
;; --- Generic Build Options
|
;; --- Generic Build Options
|
||||||
|
|
||||||
(def demo? (edn/read-string (:uxbox-demo-warning env "true")))
|
|
||||||
|
|
||||||
(def closure-defines
|
(def closure-defines
|
||||||
{'uxbox.config.url (:uxbox-api-url env "http://localhost:6060/api")
|
(let [url (-> (:uxbox-api-url env "")
|
||||||
'uxbox.config.viewurl (:uxbox-view-url env "/view/index.html")
|
(str/trim))
|
||||||
'uxbox.config.demo-warning demo?})
|
demo-warn (-> (:uxbox-demo-warning env "")
|
||||||
|
(str/trim))]
|
||||||
|
{'uxbox.config.url
|
||||||
|
(cond
|
||||||
|
(empty? url) "http://localhost:6060"
|
||||||
|
(str/starts-with? url "http") url
|
||||||
|
(str/starts-with? url "\"") (edn/read-string url))
|
||||||
|
'uxbox.config.demo-warning
|
||||||
|
(cond
|
||||||
|
(empty? demo-warn) false
|
||||||
|
(= "true" demo-warn) true
|
||||||
|
:else false)}))
|
||||||
|
|
||||||
(def default-build-options
|
(def default-build-options
|
||||||
{:cache-analysis true
|
{:cache-analysis true
|
||||||
|
|
|
@ -112,9 +112,8 @@ function build-frontend {
|
||||||
--mount source=`pwd`,type=bind,target=/root/uxbox \
|
--mount source=`pwd`,type=bind,target=/root/uxbox \
|
||||||
--mount source=${BUILDENV_IMGNAME}-m2,target=/root/.m2 \
|
--mount source=${BUILDENV_IMGNAME}-m2,target=/root/.m2 \
|
||||||
-w /root/uxbox/frontend \
|
-w /root/uxbox/frontend \
|
||||||
-e UXBOX_API_URL="/api" \
|
-e UXBOX_API_URL=${UXBOX_API_URL} \
|
||||||
-e UXBOX_VIEW_URL="/view" \
|
-e UXBOX_DEMO_WARNING=${UXBOX_DEMO_WARNING} \
|
||||||
-e UXBOX_DEMO_WARNING=true \
|
|
||||||
$IMAGE ./scripts/build-app.sh
|
$IMAGE ./scripts/build-app.sh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue