improve(electron): compatible paste assets for multiple platform

This commit is contained in:
charlie
2021-01-28 18:01:03 +08:00
parent 32c2d4f268
commit c151c9c7cf
3 changed files with 134 additions and 119 deletions

View File

@@ -48,9 +48,9 @@
[lambdaisland.glogi :as log]))
;; FIXME: should support multiple images concurrently uploading
(defonce *image-pending-file (atom nil))
(defonce *image-uploading? (atom false))
(defonce *image-uploading-process (atom 0))
(defonce *asset-pending-file (atom nil))
(defonce *asset-uploading? (atom false))
(defonce *asset-uploading-process (atom 0))
(defonce *selected-text (atom nil))
(defn- get-selection-and-format
@@ -1561,7 +1561,7 @@
(if (util/electron?)
(let [from (.-path file)]
(p/then (js/window.apis.copyFileToAssets dir filename from)
#(p/resolved [filename file])))
#(p/resolved [filename (if (string? %) (js/File. #js[] %) file)])))
(p/then (fs/write-file! repo dir filename (.stream file) nil)
#(p/resolved [filename file]))))))))
@@ -1600,7 +1600,7 @@
(string/replace #"^assets://" ""))) nil))))
(defn upload-image
[id files format uploading? drop-or-paste?]
[id ^js files format uploading? drop-or-paste?]
(let [repo (state/get-current-repo)
block (state/get-edit-block)]
(if (config/local-db? repo)
@@ -1618,32 +1618,32 @@
(p/finally
(fn []
(reset! uploading? false)
(reset! *image-uploading? false)
(reset! *image-uploading-process 0))))
(reset! *asset-uploading? false)
(reset! *asset-uploading-process 0))))
(image/upload
files
(fn [file file-name file-type]
files
(fn [file file-name file-type]
(image-handler/request-presigned-url
file file-name file-type
uploading?
(fn [signed-url]
file file-name file-type
uploading?
(fn [signed-url]
(insert-command! id
(get-image-link format signed-url file-name)
format
{:last-pattern (if drop-or-paste? "" commands/slash)
:restore? true})
(reset! *image-uploading? false)
(reset! *image-uploading-process 0))
(fn [e]
(reset! *asset-uploading? false)
(reset! *asset-uploading-process 0))
(fn [e]
(let [process (* (/ (gobj/get e "loaded")
(gobj/get e "total"))
100)]
(reset! *image-uploading? false)
(reset! *image-uploading-process process)))))))))
(reset! *asset-uploading? false)
(reset! *asset-uploading-process process)))))))))
(defn set-image-pending-file [file]
(reset! *image-pending-file file))
(defn set-asset-pending-file [file]
(reset! *asset-pending-file file))
;; Editor should track some useful information, like editor modes.
;; For example:
@@ -1791,7 +1791,7 @@
[input]
(or @*show-commands
@*show-block-commands
@*image-uploading?
@*asset-uploading?
(state/get-editor-show-input)
(state/get-editor-show-page-search?)
(state/get-editor-show-block-search?)