fix: handle wrong e2ee password on download

This commit is contained in:
Tienson Qin
2026-05-09 12:18:45 +08:00
parent b71228a7b0
commit c19eca0fd6
5 changed files with 92 additions and 13 deletions

View File

@@ -24,6 +24,7 @@
[frontend.handler.db-based.rtc-flows :as rtc-flows]
[frontend.handler.db-based.sync :as rtc-handler]
[frontend.handler.editor :as editor-handler]
[frontend.handler.events.rtc-error :as rtc-error]
[frontend.handler.export :as export]
[frontend.handler.graph :as graph-handler]
[frontend.handler.notification :as notification]
@@ -57,13 +58,6 @@
(defmulti handle first)
(defonce ^:private *search-index-build-timeout (atom nil))
(def ^:private decrypt-aes-key-failed-notification
"Failed to decrypt this graph.")
(defn- decrypt-aes-key-failed?
[error]
(string/includes? (or (ex-message error) (str error)) "decrypt-aes-key"))
(defn- <build-search-index!
[repo]
(-> (state/<invoke-db-worker :thread-api/search-build-blocks-indice-in-worker repo)
@@ -389,8 +383,8 @@
(println "RTC download graph failed, error:")
(log/error :rtc-download-graph-failed e)
(shui/popup-hide! :download-rtc-graph)
(when (decrypt-aes-key-failed? e)
(notification/show! decrypt-aes-key-failed-notification :error false))))))
(when (rtc-error/download-decrypt-failed? e)
(notification/show! (t :encryption/wrong-password) :error false))))))
;; db-worker -> UI
(defmethod handle :db/sync-changes [[_ data]]

View File

@@ -0,0 +1,30 @@
(ns frontend.handler.events.rtc-error
"RTC event error helpers."
(:require [clojure.string :as string]))
(defn- throwable-message
[error]
(or (ex-message error)
(when (instance? js/Error error)
(.-message error))
(some-> error str)))
(defn- error-texts
[error]
(when error
(let [data (ex-data error)]
(concat
[(throwable-message error)
(:error-message data)
(:error-cause data)]
(error-texts (:error data))
(error-texts (ex-cause error))))))
(defn download-decrypt-failed?
[error]
(boolean
(some (fn [text]
(and (string? text)
(or (string/includes? text "decrypt-aes-key")
(string/includes? text "decrypt-private-key"))))
(error-texts error))))