mirror of https://github.com/logseq/logseq
fix: only proceed if permission verified
parent
0b0598cee2
commit
92e791ecad
|
@ -52,8 +52,8 @@
|
|||
(local-db? dir)
|
||||
(let [[root new-dir] (rest (string/split dir "/"))
|
||||
root-handle (str "handle/" root)]
|
||||
(p/let [handle (idb/get-item root-handle)]
|
||||
(when handle (utils/verifyPermission handle true))
|
||||
(p/let [handle (idb/get-item root-handle)
|
||||
_ (when handle (utils/verifyPermission handle true))]
|
||||
(when (and handle new-dir
|
||||
(not (string/blank? new-dir)))
|
||||
(-> (p/let [handle (.getDirectoryHandle ^js handle new-dir
|
||||
|
@ -181,8 +181,8 @@
|
|||
(if (and local-content old-content new?
|
||||
(or not-changed? new-created?))
|
||||
(do
|
||||
(utils/verifyPermission file-handle true)
|
||||
(p/let [_ (utils/writeFile file-handle content)
|
||||
(p/let [_ (utils/verifyPermission file-handle true)
|
||||
_ (utils/writeFile file-handle content)
|
||||
file (.getFile file-handle)]
|
||||
(when file
|
||||
(nfs-saved-handler repo path file))))
|
||||
|
@ -194,8 +194,8 @@
|
|||
(p/let [handle (idb/get-item handle-path)]
|
||||
(if handle
|
||||
(do
|
||||
(utils/verifyPermission handle true)
|
||||
(p/let [file-handle (.getFileHandle ^js handle basename #js {:create true})
|
||||
(p/let [_ (utils/verifyPermission handle true)
|
||||
file-handle (.getFileHandle ^js handle basename #js {:create true})
|
||||
_ (idb/set-item! basename-handle-path file-handle)
|
||||
_ (utils/writeFile file-handle content)
|
||||
file (.getFile file-handle)]
|
||||
|
|
|
@ -107,8 +107,6 @@
|
|||
(create-today-journal-if-not-exists repo-url nil))
|
||||
([repo-url content]
|
||||
(spec/validate :repos/url repo-url)
|
||||
(when (config/local-db? repo-url)
|
||||
(fs/check-directory-permission! repo-url))
|
||||
(let [repo-dir (util/get-repo-dir repo-url)
|
||||
format (state/get-preferred-format repo-url)
|
||||
title (date/today)
|
||||
|
@ -134,7 +132,8 @@
|
|||
empty-blocks? (empty? (db/get-page-blocks-no-cache repo-url (string/lower-case title)))]
|
||||
(when (or empty-blocks?
|
||||
(not page-exists?))
|
||||
(p/let [_ (fs/mkdir-if-not-exists (str repo-dir "/" config/default-journals-directory))
|
||||
(p/let [_ (fs/check-directory-permission! repo-url)
|
||||
_ (fs/mkdir-if-not-exists (str repo-dir "/" config/default-journals-directory))
|
||||
file-exists? (fs/create-if-not-exists repo-url repo-dir file-path content)]
|
||||
(when-not file-exists?
|
||||
(db/reset-file! repo-url path content)
|
||||
|
|
|
@ -116,16 +116,16 @@ export var verifyPermission = async function (handle, readWrite) {
|
|||
if (readWrite) {
|
||||
options.mode = 'readwrite';
|
||||
}
|
||||
// Check if permission was already granted. If so, return true.
|
||||
// Check if permission was already granted.
|
||||
if ((await handle.queryPermission(options)) === 'granted') {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
// Request permission. If the user grants permission, return true.
|
||||
// Request permission. If the user grants permission, just return.
|
||||
if ((await handle.requestPermission(options)) === 'granted') {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
// The user didn't grant permission, so return false.
|
||||
return false;
|
||||
// The user didn't grant permission, throw an error.
|
||||
throw new Error("Permission is not granted");
|
||||
}
|
||||
|
||||
export var openDirectory = async function (options = {}, cb) {
|
||||
|
|
Loading…
Reference in New Issue