2016-06-14 17:39:44 +03:00
|
|
|
;; 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/.
|
|
|
|
;;
|
2021-04-10 09:43:04 +02:00
|
|
|
;; Copyright (c) UXBOX Labs SL
|
2016-06-14 17:39:44 +03:00
|
|
|
|
2020-08-18 19:26:37 +02:00
|
|
|
(ns app.config
|
2020-10-05 18:20:39 +02:00
|
|
|
(:require
|
2021-08-27 13:37:55 +02:00
|
|
|
[app.common.flags :as flags]
|
2020-11-30 17:59:39 +01:00
|
|
|
[app.common.spec :as us]
|
2021-06-17 13:26:38 +02:00
|
|
|
[app.common.uri :as u]
|
2020-12-04 16:01:33 +01:00
|
|
|
[app.common.version :as v]
|
2021-04-19 18:35:36 +02:00
|
|
|
[app.util.avatars :as avatars]
|
|
|
|
[app.util.dom :as dom]
|
2021-01-29 13:00:03 +01:00
|
|
|
[app.util.globals :refer [global location]]
|
2020-10-05 18:20:39 +02:00
|
|
|
[app.util.object :as obj]
|
2021-04-19 18:35:36 +02:00
|
|
|
[clojure.spec.alpha :as s]
|
2020-10-05 18:20:39 +02:00
|
|
|
[cuerdas.core :as str]))
|
2016-07-29 13:45:00 +03:00
|
|
|
|
2020-12-04 16:01:33 +01:00
|
|
|
;; --- Auxiliar Functions
|
|
|
|
|
2020-11-30 17:59:39 +01:00
|
|
|
(s/def ::platform #{:windows :linux :macos :other})
|
2021-01-28 13:06:47 +01:00
|
|
|
(s/def ::browser #{:chrome :firefox :safari :edge :other})
|
2020-11-30 17:59:39 +01:00
|
|
|
|
2020-12-04 16:01:33 +01:00
|
|
|
(defn- parse-browser
|
2020-11-30 17:59:39 +01:00
|
|
|
[]
|
|
|
|
(let [user-agent (-> (dom/get-user-agent) str/lower)
|
|
|
|
check-chrome? (fn [] (str/includes? user-agent "chrom"))
|
|
|
|
check-firefox? (fn [] (str/includes? user-agent "firefox"))
|
|
|
|
check-edge? (fn [] (str/includes? user-agent "edg"))
|
|
|
|
check-safari? (fn [] (str/includes? user-agent "safari"))]
|
|
|
|
(cond
|
|
|
|
(check-edge?) :edge
|
|
|
|
(check-chrome?) :chrome
|
|
|
|
(check-firefox?) :firefox
|
|
|
|
(check-safari?) :safari
|
|
|
|
:else :other)))
|
|
|
|
|
2020-12-04 16:01:33 +01:00
|
|
|
(defn- parse-platform
|
2020-11-30 17:59:39 +01:00
|
|
|
[]
|
2021-01-29 13:00:03 +01:00
|
|
|
(let [user-agent (str/lower (dom/get-user-agent))
|
2020-11-30 17:59:39 +01:00
|
|
|
check-windows? (fn [] (str/includes? user-agent "windows"))
|
2021-01-29 13:00:03 +01:00
|
|
|
check-linux? (fn [] (str/includes? user-agent "linux"))
|
|
|
|
check-macos? (fn [] (str/includes? user-agent "mac os"))]
|
2020-11-30 17:59:39 +01:00
|
|
|
(cond
|
|
|
|
(check-windows?) :windows
|
|
|
|
(check-linux?) :linux
|
|
|
|
(check-macos?) :macos
|
|
|
|
:else :other)))
|
|
|
|
|
2020-12-11 11:37:01 +01:00
|
|
|
(defn- parse-target
|
|
|
|
[global]
|
|
|
|
(if (some? (obj/get global "document"))
|
|
|
|
:browser
|
|
|
|
:webworker))
|
|
|
|
|
2022-04-04 23:10:41 +02:00
|
|
|
(def default-flags
|
|
|
|
[:enable-newsletter-subscription])
|
|
|
|
|
2021-06-15 17:24:00 +02:00
|
|
|
(defn- parse-flags
|
|
|
|
[global]
|
2021-08-27 13:19:36 +02:00
|
|
|
(let [flags (obj/get global "penpotFlags" "")
|
2021-11-10 15:53:54 +01:00
|
|
|
flags (sequence (map keyword) (str/words flags))]
|
2022-04-04 23:10:41 +02:00
|
|
|
(flags/parse flags/default default-flags flags)))
|
2021-06-15 17:24:00 +02:00
|
|
|
|
2022-07-29 10:54:52 +02:00
|
|
|
(defn- parse-features
|
|
|
|
[global]
|
|
|
|
(when-let [features-str (obj/get global "penpotFeatures")]
|
|
|
|
(map keyword (str/words features-str))))
|
|
|
|
|
2020-12-11 11:37:01 +01:00
|
|
|
(defn- parse-version
|
|
|
|
[global]
|
2021-01-29 13:00:03 +01:00
|
|
|
(-> (obj/get global "penpotVersion")
|
2020-12-11 11:37:01 +01:00
|
|
|
(v/parse)))
|
|
|
|
|
2022-04-06 11:14:18 +02:00
|
|
|
(defn parse-build-date
|
|
|
|
[global]
|
|
|
|
(let [date (obj/get global "penpotBuildDate")]
|
|
|
|
(if (= date "%buildDate%")
|
|
|
|
"unknown"
|
|
|
|
date)))
|
|
|
|
|
2020-12-04 16:01:33 +01:00
|
|
|
;; --- Globar Config Vars
|
|
|
|
|
|
|
|
(def default-theme "default")
|
2021-01-29 13:00:03 +01:00
|
|
|
(def default-language "en")
|
|
|
|
|
2021-02-22 17:11:51 +01:00
|
|
|
(def worker-uri (obj/get global "penpotWorkerURI" "/js/worker.js"))
|
|
|
|
(def translations (obj/get global "penpotTranslations"))
|
|
|
|
(def themes (obj/get global "penpotThemes"))
|
2021-09-20 14:37:26 +02:00
|
|
|
(def sentry-dsn (obj/get global "penpotSentryDsn"))
|
2021-11-04 15:17:12 +01:00
|
|
|
(def onboarding-form-id (obj/get global "penpotOnboardingQuestionsFormId"))
|
2021-02-22 17:11:51 +01:00
|
|
|
|
2022-04-06 11:14:18 +02:00
|
|
|
(def build-date (parse-build-date global))
|
2021-08-27 13:19:36 +02:00
|
|
|
(def flags (atom (parse-flags global)))
|
2022-07-29 10:54:52 +02:00
|
|
|
(def features (atom (parse-features global)))
|
2021-08-27 13:19:36 +02:00
|
|
|
(def version (atom (parse-version global)))
|
|
|
|
(def target (atom (parse-target global)))
|
|
|
|
(def browser (atom (parse-browser)))
|
|
|
|
(def platform (atom (parse-platform)))
|
2021-06-15 17:24:00 +02:00
|
|
|
|
2022-03-10 18:22:22 +01:00
|
|
|
(def terms-of-service-uri (obj/get global "penpotTermsOfServiceURI" nil))
|
|
|
|
(def privacy-policy-uri (obj/get global "penpotPrivacyPolicyURI" nil))
|
|
|
|
|
2021-10-20 11:09:30 +02:00
|
|
|
(defn get-public-uri
|
|
|
|
[]
|
2021-04-19 18:35:36 +02:00
|
|
|
(let [uri (u/uri (or (obj/get global "penpotPublicURI")
|
2021-04-24 12:12:13 +02:00
|
|
|
(.-origin ^js location)))]
|
2021-04-19 18:35:36 +02:00
|
|
|
;; Ensure that the path always ends with "/"; this ensures that
|
|
|
|
;; all path join operations works as expected.
|
|
|
|
(cond-> uri
|
|
|
|
(not (str/ends-with? (:path uri) "/"))
|
|
|
|
(update :path #(str % "/")))))
|
|
|
|
|
2021-10-20 11:09:30 +02:00
|
|
|
(def public-uri (get-public-uri))
|
|
|
|
|
2020-12-04 16:01:33 +01:00
|
|
|
;; --- Helper Functions
|
|
|
|
|
2020-11-30 17:59:39 +01:00
|
|
|
(defn ^boolean check-browser? [candidate]
|
2022-07-07 12:27:31 +02:00
|
|
|
(us/verify! ::browser candidate)
|
2020-12-11 11:37:01 +01:00
|
|
|
(= candidate @browser))
|
2020-11-30 17:59:39 +01:00
|
|
|
|
|
|
|
(defn ^boolean check-platform? [candidate]
|
2022-07-07 12:27:31 +02:00
|
|
|
(us/verify! ::platform candidate)
|
2020-12-11 11:37:01 +01:00
|
|
|
(= candidate @platform))
|
2020-08-17 13:39:36 +02:00
|
|
|
|
2021-01-04 18:41:05 +01:00
|
|
|
(defn resolve-profile-photo-url
|
|
|
|
[{:keys [photo-id fullname name] :as profile}]
|
|
|
|
(if (nil? photo-id)
|
|
|
|
(avatars/generate {:name (or fullname name)})
|
2021-04-19 18:35:36 +02:00
|
|
|
(str (u/join public-uri "assets/by-id/" photo-id))))
|
2021-01-04 18:41:05 +01:00
|
|
|
|
|
|
|
(defn resolve-team-photo-url
|
|
|
|
[{:keys [photo-id name] :as team}]
|
|
|
|
(if (nil? photo-id)
|
|
|
|
(avatars/generate {:name name})
|
2021-04-19 18:35:36 +02:00
|
|
|
(str (u/join public-uri "assets/by-id/" photo-id))))
|
2021-01-04 18:41:05 +01:00
|
|
|
|
|
|
|
(defn resolve-file-media
|
|
|
|
([media]
|
|
|
|
(resolve-file-media media false))
|
2022-02-28 17:15:58 +01:00
|
|
|
([{:keys [id] :as media} thumbnail?]
|
2021-04-19 18:35:36 +02:00
|
|
|
(str (cond-> (u/join public-uri "assets/by-file-media-id/")
|
2021-05-13 14:50:28 +02:00
|
|
|
(true? thumbnail?) (u/join (str id "/thumbnail"))
|
|
|
|
(false? thumbnail?) (u/join (str id))))))
|