Browse Source

fix(asset-sync): dissoc arraybuffer :body when throw

because arraybuffer is unable to be transit-writed
rcmerci 1 year ago
parent
commit
69e4657860
1 changed files with 35 additions and 35 deletions
  1. 35 35
      src/main/frontend/handler/assets.cljs

+ 35 - 35
src/main/frontend/handler/assets.cljs

@@ -276,45 +276,45 @@
   [repo asset-block-uuid-str asset-type checksum put-url]
   [repo asset-block-uuid-str asset-type checksum put-url]
   (assert (and asset-type checksum))
   (assert (and asset-type checksum))
   (m/sp
   (m/sp
-   (let [asset-file (c.m/<? (<read-asset repo asset-block-uuid-str asset-type))
-         *progress-flow (atom nil)
-         http-task (http/put put-url {:headers {"x-amz-meta-checksum" checksum
-                                                "x-amz-meta-type" asset-type}
-                                      :body asset-file
-                                      :with-credentials? false
-                                      :*progress-flow *progress-flow})]
-     (c.m/run-task
-      (m/reduce (fn [_ v]
-                  (state/update-state!
-                   :rtc/asset-upload-download-progress
-                   (fn [m] (assoc-in m [repo asset-block-uuid-str] v))))
-                @*progress-flow)
-      :upload-asset-progress
-      :succ (constantly nil))
-     (let [{:keys [status] :as r} (m/? http-task)]
-       (when-not (http/unexceptional-status? status)
-         {:ex-data {:type :rtc.exception/upload-asset-failed :data r}})))))
+    (let [asset-file (c.m/<? (<read-asset repo asset-block-uuid-str asset-type))
+          *progress-flow (atom nil)
+          http-task (http/put put-url {:headers {"x-amz-meta-checksum" checksum
+                                                 "x-amz-meta-type" asset-type}
+                                       :body asset-file
+                                       :with-credentials? false
+                                       :*progress-flow *progress-flow})]
+      (c.m/run-task
+       (m/reduce (fn [_ v]
+                   (state/update-state!
+                    :rtc/asset-upload-download-progress
+                    (fn [m] (assoc-in m [repo asset-block-uuid-str] v))))
+                 @*progress-flow)
+       :upload-asset-progress
+       :succ (constantly nil))
+      (let [{:keys [status] :as r} (m/? http-task)]
+        (when-not (http/unexceptional-status? status)
+          {:ex-data {:type :rtc.exception/upload-asset-failed :data (dissoc r :body)}})))))
 
 
 (defn new-task--rtc-download-asset
 (defn new-task--rtc-download-asset
   [repo asset-block-uuid-str asset-type get-url]
   [repo asset-block-uuid-str asset-type get-url]
   (m/sp
   (m/sp
-   (let [*progress-flow (atom nil)
-         http-task (http/get get-url {:with-credentials? false
-                                      :response-type :array-buffer
-                                      :*progress-flow *progress-flow})]
-     (c.m/run-task
-      (m/reduce (fn [_ v]
-                  (state/update-state!
-                   :rtc/asset-upload-download-progress
-                   (fn [m] (assoc-in m [repo asset-block-uuid-str] v))))
-                @*progress-flow)
-      :download-asset-progress
-      :succ (constantly nil))
-     (let [{:keys [status body] :as r} (m/? http-task)]
-       (if-not (http/unexceptional-status? status)
-         {:ex-data {:type :rtc.exception/download-asset-failed :data r}}
-         (do (c.m/<? (<write-asset repo asset-block-uuid-str asset-type body))
-             nil))))))
+    (let [*progress-flow (atom nil)
+          http-task (http/get get-url {:with-credentials? false
+                                       :response-type :array-buffer
+                                       :*progress-flow *progress-flow})]
+      (c.m/run-task
+       (m/reduce (fn [_ v]
+                   (state/update-state!
+                    :rtc/asset-upload-download-progress
+                    (fn [m] (assoc-in m [repo asset-block-uuid-str] v))))
+                 @*progress-flow)
+       :download-asset-progress
+       :succ (constantly nil))
+      (let [{:keys [status body] :as r} (m/? http-task)]
+        (if-not (http/unexceptional-status? status)
+          {:ex-data {:type :rtc.exception/download-asset-failed :data (dissoc r :body)}}
+          (do (c.m/<? (<write-asset repo asset-block-uuid-str asset-type body))
+              nil))))))
 
 
 (comment
 (comment
   ;; read asset
   ;; read asset