diff --git a/backend/src/app/rpc/commands/files.clj b/backend/src/app/rpc/commands/files.clj index bc34c69b7..e3b88a8bc 100644 --- a/backend/src/app/rpc/commands/files.clj +++ b/backend/src/app/rpc/commands/files.clj @@ -355,8 +355,8 @@ (db/get pool :file {:id id} {:columns [:id :modified-at :revn]})) (defn get-file-etag - [{:keys [modified-at revn]}] - (str (dt/format-instant modified-at :iso) "-" revn)) + [{:keys [::rpc/profile-id]} {:keys [modified-at revn]}] + (str profile-id (dt/format-instant modified-at :iso) revn)) (sv/defmethod ::get-file "Retrieve a file by its ID. Only authenticated users." @@ -371,7 +371,7 @@ (check-read-permissions! perms) (let [file (-> (get-file conn id features project-id) (assoc :permissions perms))] - (vary-meta file assoc ::cond/key (get-file-etag file)))))) + (vary-meta file assoc ::cond/key (get-file-etag params file)))))) ;; --- COMMAND QUERY: get-file-fragment (by id) diff --git a/backend/src/app/rpc/cond.clj b/backend/src/app/rpc/cond.clj index 3cee44e3f..b683ded13 100644 --- a/backend/src/app/rpc/cond.clj +++ b/backend/src/app/rpc/cond.clj @@ -27,6 +27,8 @@ [app.common.logging :as l] [app.rpc.helpers :as rph] [app.util.services :as-alias sv] + [buddy.core.codecs :as bc] + [buddy.core.hash :as bh] [yetti.response :as yrs])) (def @@ -34,9 +36,16 @@ :doc "Runtime flag for enable/disable conditional processing of RPC methods."} *enabled* false) +(defn- encode + [s] + (-> s + bh/blake2b-256 + bc/bytes->b64u + bc/bytes->str)) + (defn- fmt-key [s] - (str "W/\"" s "\"")) + (str "W/\"" (encode s) "\"")) (defn wrap [_ f {:keys [::get-object ::key-fn ::reuse-key?] :as mdata}] @@ -46,9 +55,8 @@ (fn [cfg {:keys [::key] :as params}] (if *enabled* (let [key' (when (or key reuse-key?) - (some-> (get-object cfg params) key-fn fmt-key))] - (if (and (some? key) - (= key key')) + (some->> (get-object cfg params) (key-fn params) (fmt-key)))] + (if (and (some? key) (= key key')) (fn [_] {::yrs/status 304}) (let [result (f cfg params) etag (or (and reuse-key? key')