2023-04-24 08:50:45 +00:00
|
|
|
(ns utils.image-server
|
|
|
|
(:require [utils.datetime :as datetime]))
|
2022-07-18 11:43:50 +00:00
|
|
|
|
|
|
|
(def ^:const image-server-uri-prefix "https://localhost:")
|
|
|
|
(def ^:const account-images-action "/accountImages")
|
|
|
|
(def ^:const contact-images-action "/contactImages")
|
2023-04-27 13:55:49 +00:00
|
|
|
(def ^:const generate-qr-action "/GenerateQRCode")
|
|
|
|
(def ^:const status-profile-base-url "https://join.status.im/u/")
|
2023-05-16 16:27:34 +00:00
|
|
|
(def ^:const status-profile-base-url-without-https "join.status.im/u/")
|
2022-07-18 11:43:50 +00:00
|
|
|
|
2023-04-24 08:50:45 +00:00
|
|
|
(defn timestamp [] (datetime/timestamp))
|
|
|
|
|
|
|
|
(defn current-theme-index
|
|
|
|
[theme]
|
|
|
|
(case theme
|
2022-07-18 11:43:50 +00:00
|
|
|
:light 1
|
2022-12-20 14:45:37 +00:00
|
|
|
:dark 2))
|
2022-07-18 11:43:50 +00:00
|
|
|
|
2023-04-27 13:55:49 +00:00
|
|
|
(defn correction-level->index
|
|
|
|
[level]
|
|
|
|
(case (keyword level)
|
|
|
|
:low 1
|
|
|
|
:medium 2
|
|
|
|
:quart 3
|
|
|
|
:highest 4
|
|
|
|
4))
|
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn get-account-image-uri
|
2023-05-23 06:10:01 +00:00
|
|
|
[{:keys [port public-key image-name key-uid theme ring?]}]
|
2022-12-20 14:45:37 +00:00
|
|
|
(str image-server-uri-prefix
|
|
|
|
port
|
|
|
|
account-images-action
|
|
|
|
"?publicKey="
|
|
|
|
public-key
|
|
|
|
"&keyUid="
|
|
|
|
key-uid
|
|
|
|
"&imageName="
|
|
|
|
image-name
|
|
|
|
"&theme="
|
2023-04-24 08:50:45 +00:00
|
|
|
(current-theme-index theme)
|
2022-12-20 14:45:37 +00:00
|
|
|
"&clock="
|
|
|
|
(timestamp)
|
2023-05-23 06:10:01 +00:00
|
|
|
"&addRing="
|
|
|
|
(if ring? 1 0)))
|
2022-07-18 11:43:50 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn get-contact-image-uri
|
2023-04-24 08:50:45 +00:00
|
|
|
[port public-key image-name clock theme]
|
2022-12-20 14:45:37 +00:00
|
|
|
(str image-server-uri-prefix
|
|
|
|
port
|
|
|
|
contact-images-action
|
|
|
|
"?publicKey="
|
|
|
|
public-key
|
|
|
|
"&imageName="
|
|
|
|
image-name
|
|
|
|
"&theme="
|
2023-04-24 08:50:45 +00:00
|
|
|
(current-theme-index theme)
|
2022-12-20 14:45:37 +00:00
|
|
|
"&clock="
|
|
|
|
clock
|
|
|
|
"&addRing=1"))
|
2023-04-27 13:55:49 +00:00
|
|
|
|
|
|
|
(defn get-account-qr-image-uri
|
|
|
|
[{:keys [key-uid public-key port qr-size]}]
|
|
|
|
(let [profile-qr-url (str status-profile-base-url public-key)
|
|
|
|
base-64-qr-url (js/btoa profile-qr-url)
|
|
|
|
profile-image-type "large"
|
|
|
|
error-correction-level (correction-level->index :highest)
|
|
|
|
superimpose-profile? true
|
|
|
|
media-server-url (str image-server-uri-prefix
|
|
|
|
port
|
|
|
|
generate-qr-action
|
|
|
|
"?level="
|
|
|
|
error-correction-level
|
|
|
|
"&url="
|
|
|
|
base-64-qr-url
|
|
|
|
"&keyUid="
|
|
|
|
key-uid
|
|
|
|
"&allowProfileImage="
|
|
|
|
superimpose-profile?
|
|
|
|
"&size="
|
|
|
|
qr-size
|
|
|
|
"&imageName="
|
|
|
|
profile-image-type)]
|
|
|
|
media-server-url))
|
|
|
|
|
|
|
|
(defn get-qr-image-uri-for-any-url
|
|
|
|
[{:keys [url port qr-size error-level]}]
|
|
|
|
(let [qr-url-base64 (js/btoa url)
|
|
|
|
error-correction-level (correction-level->index error-level)
|
|
|
|
superimpose-profile? false
|
|
|
|
media-server-url (str image-server-uri-prefix
|
|
|
|
port
|
|
|
|
generate-qr-action
|
|
|
|
"?level="
|
|
|
|
error-correction-level
|
|
|
|
"&url="
|
|
|
|
qr-url-base64
|
|
|
|
"&allowProfileImage="
|
|
|
|
superimpose-profile?
|
|
|
|
"&size="
|
|
|
|
qr-size)]
|
|
|
|
media-server-url))
|