💄 Fix format issues on backend module

This commit is contained in:
Andrey Antukh 2023-11-29 12:53:34 +01:00
parent 99e323dabc
commit 87615ce221
58 changed files with 293 additions and 411 deletions

View file

@ -353,8 +353,7 @@
(get-name [props]
(let [attr-kw (cf/get :oidc-name-attr "name")
attr-ph (parse-attr-path provider attr-kw)]
(get-in props attr-ph)))
]
(get-in props attr-ph)))]
(let [props (qualify-props provider info)
email (get-email props)]

View file

@ -97,7 +97,7 @@
:with-credentials (and (contains? cfg ::username)
(contains? cfg ::password))
:min-size (::min-size cfg)
:max-size (::max-size cfg))
:max-size (::max-size cfg))
(create-pool cfg)))
(defmethod ig/halt-key! ::pool
@ -412,7 +412,7 @@
(.setSavepoint conn (name label))))
(defn release!
[^Connection conn ^Savepoint sp ]
[^Connection conn ^Savepoint sp]
(.releaseSavepoint conn sp))
(defn rollback!

View file

@ -39,9 +39,9 @@
(let [{:keys [host port] :as url} (sto/get-object-url storage obj {:max-age signature-max-age})]
{::rres/status 307
::rres/headers {"location" (str url)
"x-host" (cond-> host port (str ":" port))
"x-mtype" (-> obj meta :content-type)
"cache-control" (str "max-age=" (inst-ms cache-max-age))}}))
"x-host" (cond-> host port (str ":" port))
"x-mtype" (-> obj meta :content-type)
"cache-control" (str "max-age=" (inst-ms cache-max-age))}}))
(defn- serve-object-from-fs
[{:keys [::path]} obj]

View file

@ -230,8 +230,7 @@
(-> (io/resource "app/templates/error-report.v3.tmpl")
(tmpl/render (-> content
(assoc :id id)
(assoc :created-at (dt/format-instant created-at :rfc1123))))))
]
(assoc :created-at (dt/format-instant created-at :rfc1123))))))]
(if-let [report (get-report request)]
(let [result (case (:version report)

View file

@ -117,21 +117,21 @@
:profile-id profile-id
:session-id session-id}]
;; Close profile subscription if exists
(when-let [ch (:channel psub)]
(sp/close! ch)
(mbus/purge! msgbus [ch]))
;; Close profile subscription if exists
(when-let [ch (:channel psub)]
(sp/close! ch)
(mbus/purge! msgbus [ch]))
;; Close team subscription if exists
(when-let [ch (:channel tsub)]
(sp/close! ch)
(mbus/purge! msgbus [ch]))
;; Close team subscription if exists
(when-let [ch (:channel tsub)]
(sp/close! ch)
(mbus/purge! msgbus [ch]))
;; Close file subscription if exists
(when-let [{:keys [topic channel]} fsub]
(sp/close! channel)
(mbus/purge! msgbus [channel])
(mbus/pub! msgbus :topic topic :message msg))))
;; Close file subscription if exists
(when-let [{:keys [topic channel]} fsub]
(sp/close! channel)
(mbus/purge! msgbus [channel])
(mbus/pub! msgbus :topic topic :message msg))))
(defmethod handle-message :subscribe-team
[{:keys [::mbus/msgbus]} {:keys [::ws/id ::ws/state ::ws/output-ch ::session-id]} {:keys [team-id] :as params}]
@ -179,7 +179,7 @@
(let [message {:type :presence
:file-id file-id
:session-id session-id
:profile-id profile-id}]
:profile-id profile-id}]
(mbus/pub! msgbus
:topic file-id
:message message)))

View file

@ -182,5 +182,4 @@
"invalid-uri"
(instance? java.net.http.HttpConnectTimeoutException cause)
"timeout"
))
"timeout"))

View file

@ -160,8 +160,7 @@
{::mdef/name "penpot_executors_running_threads"
::mdef/help "Current number of threads with state RUNNING."
::mdef/labels ["name"]
::mdef/type :gauge}
})
::mdef/type :gauge}})
(def system-config
{::db/pool
@ -322,8 +321,7 @@
::setup/templates (ig/ref ::setup/templates)
::props (ig/ref ::setup/props)
:pool (ig/ref ::db/pool)
}
:pool (ig/ref ::db/pool)}
:app.rpc.doc/routes
{:methods (ig/ref :app.rpc/methods)}
@ -443,8 +441,7 @@
::sto.s3/io-threads (cf/get :storage-assets-s3-io-threads)}
[::assets :app.storage.fs/backend]
{::sto.fs/directory (cf/get :storage-assets-fs-directory)}
})
{::sto.fs/directory (cf/get :storage-assets-fs-directory)}})
(def worker-config

View file

@ -94,7 +94,7 @@
writer (StringWriter.)]
(TextFormat/write004 writer samples)
{:headers {"content-type" TextFormat/CONTENT_TYPE_004}
:body (.toString writer)}))
:body (.toString writer)}))

View file

@ -337,9 +337,7 @@
:fn (mg/resource "app/migrations/sql/0106-mod-team-table.sql")}
{:name "0107-mod-file-tagged-object-thumbnail-table"
:fn (mg/resource "app/migrations/sql/0107-mod-file-tagged-object-thumbnail-table.sql")}
])
:fn (mg/resource "app/migrations/sql/0107-mod-file-tagged-object-thumbnail-table.sql")}])
(defn apply-migrations!
[pool name migrations]

View file

@ -181,8 +181,8 @@
(let [f (px/wrap-bindings f)]
(p/await! (px/submit! executor f))))]
(if (and cache id)
(invoke! cache metrics id nil f)
(f)))))
(invoke! cache metrics id nil f)
(f)))))
(def noop-fn (constantly nil))

View file

@ -636,8 +636,8 @@
input (io/data-input-stream input)]
(binding [*state* (volatile! {:media [] :index {}})]
(let [team (teams/get-team options
:profile-id profile-id
:project-id project-id)
:profile-id profile-id
:project-id project-id)
validate? (contains? cf/flags :file-validation)
features (cfeat/get-team-enabled-features cf/flags team)]

View file

@ -361,7 +361,7 @@
{::doc/added "1.17"
::sm/params schema:get-file-fragment
::sm/result schema:file-fragment}
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id fragment-id share-id] }]
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id fragment-id share-id]}]
(dm/with-open [conn (db/open pool)]
(let [perms (get-permissions conn profile-id file-id share-id)]
(check-read-permissions! perms)
@ -491,7 +491,7 @@
page (dm/get-in file [:data :pages-index page-id])]
(if (pmap/pointer-map? page)
(deref page)
page)))]
page)))]
(cond-> (prune-thumbnails page)
(some? object-id)
@ -549,10 +549,10 @@
(defn get-team-shared-files
[conn team-id]
(letfn [(assets-sample [assets limit]
(let [sorted-assets (->> (vals assets)
(sort-by #(str/lower (:name %))))]
{:count (count sorted-assets)
:sample (into [] (take limit sorted-assets))}))
(let [sorted-assets (->> (vals assets)
(sort-by #(str/lower (:name %))))]
{:count (count sorted-assets)
:sample (into [] (take limit sorted-assets))}))
(library-summary [{:keys [id data] :as file}]
(binding [pmap/*load-fn* (partial load-pointer conn id)]

View file

@ -78,8 +78,8 @@
(create-file-role! conn))
(db/update! conn :project
{:modified-at (dt/now)}
{:id project-id})
{:modified-at (dt/now)}
{:id project-id})
(files/decode-row file)))

View file

@ -74,8 +74,8 @@
:file-id file-id)
(db/update! conn :file
{:data (:data snapshot)}
{:id file-id})
{:data (:data snapshot)}
{:id file-id})
;; clean object thumbnails
(let [sql (str "delete from file_object_thumbnail "

View file

@ -361,8 +361,7 @@
::sm/params [:map {:title "create-file-thumbnail"}
[:file-id ::sm/uuid]
[:revn :int]
[:media ::media/upload]]
}
[:media ::media/upload]]}
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id] :as params}]
(db/with-atomic [conn pool]

View file

@ -338,7 +338,7 @@
(cond-> (and (contains? cfeat/*current* "fdata/pointer-map")
(not (contains? cfeat/*previous* "fdata/pointer-map")))
(enable-pointer-map))
(enable-pointer-map))
(update :data blob/encode))))

View file

@ -81,8 +81,8 @@
perms (files/get-permissions conn profile-id file-id share-id)]
(files/check-read-permissions! perms)
(db/query conn :team-font-variant
{:team-id (:team-id project)
:deleted-at nil})))))
{:team-id (:team-id project)
:deleted-at nil})))))
(declare create-font-variant)
@ -157,8 +157,7 @@
:woff1-file-id (:id woff1)
:woff2-file-id (:id woff2)
:otf-file-id (:id otf)
:ttf-file-id (:id ttf)}))
]
:ttf-file-id (:id ttf)}))]
(let [data (-> (climit/configure cfg :process-font/global)
(climit/run! (partial generate-missing! data)

View file

@ -234,9 +234,9 @@
(assoc :is-pinned false))
files (db/query conn :file
{:project-id (:id project)
:deleted-at nil}
{:columns [:id]})
{:project-id (:id project)
:deleted-at nil}
{:columns [:id]})
project (cond-> project
(string? name)

View file

@ -106,8 +106,7 @@
profile (-> profile
(assoc :fullname fullname)
(assoc :lang lang)
(assoc :theme theme))
]
(assoc :theme theme))]
(db/update! conn :profile
{:fullname fullname

View file

@ -50,11 +50,11 @@
is-owner (boolean (some :is-owner rows))
is-admin (boolean (some :is-admin rows))
can-edit (boolean (some :can-edit rows))]
(when (seq rows)
{:is-owner is-owner
:is-admin (or is-owner is-admin)
:can-edit (or is-owner is-admin can-edit)
:can-read true})))
(when (seq rows)
{:is-owner is-owner
:is-admin (or is-owner is-admin)
:can-edit (or is-owner is-admin can-edit)
:can-read true})))
(def has-edit-permissions?
(perms/make-edition-predicate-fn get-permissions))

View file

@ -56,11 +56,11 @@
is-owner (boolean (some :is-owner rows))
is-admin (boolean (some :is-admin rows))
can-edit (boolean (some :can-edit rows))]
(when (seq rows)
{:is-owner is-owner
:is-admin (or is-owner is-admin)
:can-edit (or is-owner is-admin can-edit)
:can-read true})))
(when (seq rows)
{:is-owner is-owner
:is-admin (or is-owner is-admin)
:can-edit (or is-owner is-admin can-edit)
:can-read true})))
(def has-admin-permissions?
(perms/make-admin-predicate-fn get-permissions))
@ -368,8 +368,8 @@
(let [conn (db/get-connection cfg-or-conn)
team (create-team* conn params)
params (assoc params
:team-id (:id team)
:role :owner)
:team-id (:id team)
:role :owner)
project (create-team-default-project conn params)]
(create-team-role conn params)
(assoc team :default-project-id (:id project))))
@ -667,8 +667,8 @@
;; Save new photo
(db/update! pool :team
{:photo-id (:id photo)}
{:id team-id})
{:photo-id (:id photo)}
{:id team-id})
(assoc team :photo-id (:id photo)))))

View file

@ -88,7 +88,7 @@
context (assoc context :param-style pstyle)]
{::rres/status 200
::rres/body (-> (io/resource "app/templates/api-doc.tmpl")
(tmpl/render context))}))
(tmpl/render context))}))
(fn [_]
{::rres/status 404})))
@ -141,8 +141,7 @@
{:name (-> mdata ::sv/name d/name)
:module (-> (:ns mdata) (str/split ".") last)
:repr {:post rpost}}))
]
:repr {:post rpost}}))]
(let [definitions (atom {})
options {:registry sr/default-registry
@ -158,16 +157,16 @@
(map (fn [doc]
[(str/ffmt "/command/%" (:name doc)) (:repr doc)]))
(into {})))]
{:openapi "3.0.0"
:info {:version (:main cf/version)}
:servers [{:url (str/ffmt "%/api/rpc" (cf/get :public-uri))
{:openapi "3.0.0"
:info {:version (:main cf/version)}
:servers [{:url (str/ffmt "%/api/rpc" (cf/get :public-uri))
;; :description "penpot backend"
}]
:security
{:api_key []}
}]
:security
{:api_key []}
:paths paths
:components {:schemas @definitions}})))
:paths paths
:components {:schemas @definitions}})))
(defn openapi-json-handler
[context]
@ -192,7 +191,7 @@
{::rres/status 200
::rres/headers {"content-type" "text/html"}
::rres/body (-> (io/resource "app/templates/openapi.tmpl")
(tmpl/render context))}))
(tmpl/render context))}))
(fn [_]
{::rres/status 404})))

View file

@ -158,15 +158,15 @@
(p/await! scope))
(-> (deref feat/*stats*)
(assoc :elapsed (dt/format-duration (tpoint))))
(-> (deref feat/*stats*)
(assoc :elapsed (dt/format-duration (tpoint))))
(catch Throwable cause
(l/dbg :hint "migrate:error" :cause cause))
(catch Throwable cause
(l/dbg :hint "migrate:error" :cause cause))
(finally
(let [elapsed (dt/format-duration (tpoint))]
(l/dbg :hint "migrate:end" :elapsed elapsed))))))))
(finally
(let [elapsed (dt/format-duration (tpoint))]
(l/dbg :hint "migrate:end" :elapsed elapsed))))))))
(defn migrate-team!
[{:keys [::db/pool] :as system} team-id

View file

@ -96,9 +96,9 @@
:name (:name file)))
new-file))))
([file state]
(rename-layout-attrs file)
(update state :total (fnil inc 0))))
([file state]
(rename-layout-attrs file)
(update state :total (fnil inc 0))))
(defn fix-components-shaperefs
([file]
@ -369,11 +369,11 @@
(= (:shape-ref child) ref-child-id))
false))
equal? (every? matches? (d/zip-all (:shapes shape) (:shapes ref-shape)))]
(when (and (not equal?) (not (cfh/touched-group? shape :shapes-group)))
(println " -> set touched " (:name shape) (:id shape) :shapes :shapes-group))
(cond-> shape
(and (not equal?) (not (cfh/touched-group? shape :shapes-group)))
(update :touched cfh/set-touched-group :shapes-group))))]
(when (and (not equal?) (not (cfh/touched-group? shape :shapes-group)))
(println " -> set touched " (:name shape) (:id shape) :shapes :shapes-group))
(cond-> shape
(and (not equal?) (not (cfh/touched-group? shape :shapes-group)))
(update :touched cfh/set-touched-group :shapes-group))))]
(as-> shape $
(reduce fix-touched-attr $ ctk/sync-attrs)

View file

@ -245,8 +245,7 @@
(start-worker [input index]
(px/thread
{:name (str "penpot/srepl/worker/" index)}
(run-worker input index)))
]
(run-worker input index)))]
(when (fn? on-init) (on-init))

View file

@ -313,8 +313,7 @@
(= op :profile-id)
(if (coll? param)
(sequence (keep parse-uuid) param)
(resolve-dest param))))))
]
(resolve-dest param))))))]
(->> (resolve-dest dest)
(filter some?)

View file

@ -403,8 +403,7 @@
(do
(some->> (seq to-freeze) (mark-freeze-in-bulk conn))
(some->> (seq to-delete) (mark-delete-in-bulk conn))
[(count to-freeze) (count to-delete)]))))
]
[(count to-freeze) (count to-delete)]))))]
(fn [_]
(db/with-atomic [conn pool]

View file

@ -18,8 +18,8 @@
[datoteka.io :as io]
[integrant.core :as ig])
(:import
java.nio.file.Path
java.nio.file.Files))
java.nio.file.Files
java.nio.file.Path))
;; --- BACKEND INIT

View file

@ -194,9 +194,7 @@
builder (cond-> ^S3AsyncClientBuilder builder
(some? endpoint)
(.endpointOverride (URI. endpoint)))]
(.build ^S3AsyncClientBuilder builder))
]
(.build ^S3AsyncClientBuilder builder))]
(reify
clojure.lang.IDeref
@ -265,15 +263,15 @@
(Optional/of (long (impl/get-size content))))
(^void subscribe [_ ^Subscriber subscriber]
(let [sem (Semaphore. 0)
thr (upload-thread id subscriber sem content)]
(.onSubscribe subscriber
(reify Subscription
(cancel [_]
(px/interrupt! thr)
(.release sem 1))
(request [_ n]
(.release sem (int n)))))))))
(let [sem (Semaphore. 0)
thr (upload-thread id subscriber sem content)]
(.onSubscribe subscriber
(reify Subscription
(cancel [_]
(px/interrupt! thr)
(.release sem 1))
(request [_ n]
(.release sem (int n)))))))))
(defn- put-object

View file

@ -151,7 +151,7 @@
{::db/return-keys? false})
count (db/get-update-count result)]
(when (pos? count)
(l/debug :hint "mark team for deletion" :id (str id) ))
(l/debug :hint "mark team for deletion" :id (str id)))
(+ total count)))]

View file

@ -178,7 +178,7 @@
(defn- retrieve-enabled-auth-providers
[conn]
(let [sql (str "select auth_backend as backend, count(*) as total "
" from profile group by 1")
" from profile group by 1")
rows (db/exec! conn [sql])]
(->> rows
(map (fn [{:keys [backend total]}]

View file

@ -8,8 +8,8 @@
"A syntactic helpers for using locks."
(:refer-clojure :exclude [locking])
(:import
java.util.concurrent.locks.ReentrantLock
java.util.concurrent.locks.Lock))
java.util.concurrent.locks.Lock
java.util.concurrent.locks.ReentrantLock))
(defn create
[]

View file

@ -335,8 +335,7 @@
Iterable
(iterator [this]
(when-not loaded? (load! this))
(ObjectsMapIterator. (.iterator ^Iterable positions) this))
)
(ObjectsMapIterator. (.iterator ^Iterable positions) this)))
(defn create
([]

View file

@ -371,8 +371,7 @@
::sm/decode instant
:gen/gen (tgen/fmap (fn [i] (in-past i)) tgen/pos-int)
::oapi/type "string"
::oapi/format "iso"
}})
::oapi/format "iso"}})
(sm/def! ::duration
{:type :durations
@ -383,5 +382,4 @@
:title "duration"
::sm/decode duration
::oapi/type "string"
::oapi/format "duration"
}})
::oapi/format "duration"}})

View file

@ -89,17 +89,17 @@
state (atom {})
beats (atom #{})
options (-> options
(update ::handler wrap-handler)
(assoc ::id id)
(assoc ::state state)
(assoc ::beats beats)
(assoc ::created-at (dt/now))
(assoc ::input-ch input-ch)
(assoc ::heartbeat-ch hbeat-ch)
(assoc ::output-ch output-ch)
(assoc ::close-ch close-ch)
(assoc ::remote-addr ip-addr)
(assoc ::user-agent uagent))]
(update ::handler wrap-handler)
(assoc ::id id)
(assoc ::state state)
(assoc ::beats beats)
(assoc ::created-at (dt/now))
(assoc ::input-ch input-ch)
(assoc ::heartbeat-ch hbeat-ch)
(assoc ::output-ch output-ch)
(assoc ::close-ch close-ch)
(assoc ::remote-addr ip-addr)
(assoc ::user-agent uagent))]
{:on-open
(fn on-open [channel]
@ -115,9 +115,9 @@
:on-close
(fn on-close [_channel code reason]
(l/info :fn "on-ws-terminate"
:conn-id id
:code code
:reason reason)
:conn-id id
:code code
:reason reason)
(sp/close! close-ch))
:on-error

View file

@ -25,9 +25,9 @@
[promesa.core :as p]
[promesa.exec :as px])
(:import
java.util.concurrent.ThreadPoolExecutor
java.util.concurrent.Executor
java.util.concurrent.Future))
java.util.concurrent.Future
java.util.concurrent.ThreadPoolExecutor))
(set! *warn-on-reflection* true)