💄 Add cosmetic changes to get-file rpc method

This commit is contained in:
Andrey Antukh 2024-10-16 17:37:53 +02:00
parent 40d7bb04b4
commit 790f6ce4ed

View file

@ -292,41 +292,40 @@
::cond/get-object #(get-minimal-file-with-perms %1 %2) ::cond/get-object #(get-minimal-file-with-perms %1 %2)
::cond/key-fn get-file-etag ::cond/key-fn get-file-etag
::sm/params schema:get-file ::sm/params schema:get-file
::sm/result schema:file-with-permissions} ::sm/result schema:file-with-permissions
[cfg {:keys [::rpc/profile-id id project-id] :as params}] ::db/transaction true}
(db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}] [{:keys [::db/conn] :as cfg} {:keys [::rpc/profile-id id project-id] :as params}]
;; The COND middleware makes initial request for a file and ;; The COND middleware makes initial request for a file and
;; permissions when the incoming request comes with an ;; permissions when the incoming request comes with an
;; ETAG. When ETAG does not matches, the request is resolved ;; ETAG. When ETAG does not matches, the request is resolved
;; and this code is executed, in this case the permissions ;; and this code is executed, in this case the permissions
;; will be already prefetched and we just reuse them instead ;; will be already prefetched and we just reuse them instead
;; of making an additional database queries. ;; of making an additional database queries.
(let [perms (or (:permissions (::cond/object params)) (let [perms (or (:permissions (::cond/object params))
(get-permissions conn profile-id id))] (get-permissions conn profile-id id))]
(check-read-permissions! perms) (check-read-permissions! perms)
(let [team (teams/get-team conn (let [team (teams/get-team conn
:profile-id profile-id :profile-id profile-id
:project-id project-id :project-id project-id
:file-id id) :file-id id)
file (-> (get-file cfg id :project-id project-id) file (-> (get-file cfg id :project-id project-id)
(assoc :permissions perms) (assoc :permissions perms)
(check-version!)) (check-version!))]
_ (-> (cfeat/get-team-enabled-features cf/flags team) (-> (cfeat/get-team-enabled-features cf/flags team)
(cfeat/check-client-features! (:features params)) (cfeat/check-client-features! (:features params))
(cfeat/check-file-features! (:features file) (:features params))) (cfeat/check-file-features! (:features file) (:features params)))
;; This operation is needed for backward comapatibility with frontends that ;; This operation is needed for backward comapatibility with frontends that
;; does not support pointer-map resolution mechanism; this just resolves the ;; does not support pointer-map resolution mechanism; this just resolves the
;; pointers on backend and return a complete file. ;; pointers on backend and return a complete file.
file (if (and (contains? (:features file) "fdata/pointer-map") (if (and (contains? (:features file) "fdata/pointer-map")
(not (contains? (:features params) "fdata/pointer-map"))) (not (contains? (:features params) "fdata/pointer-map")))
(binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg id)] (binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg id)]
(update file :data feat.fdata/process-pointers deref)) (update file :data feat.fdata/process-pointers deref))
file)] file))))
file)))))
;; --- COMMAND QUERY: get-file-fragment (by id) ;; --- COMMAND QUERY: get-file-fragment (by id)