|
@@ -13,52 +13,16 @@
|
|
|
[frontend.mobile.util :as mobile-util]
|
|
[frontend.mobile.util :as mobile-util]
|
|
|
[frontend.state :as state]
|
|
[frontend.state :as state]
|
|
|
[frontend.util :as util]
|
|
[frontend.util :as util]
|
|
|
- [frontend.util.text :as text-util]
|
|
|
|
|
[lambdaisland.glogi :as log]
|
|
[lambdaisland.glogi :as log]
|
|
|
[logseq.graph-parser.util :as gp-util]
|
|
[logseq.graph-parser.util :as gp-util]
|
|
|
[frontend.util.fs :as fs-util]
|
|
[frontend.util.fs :as fs-util]
|
|
|
[logseq.graph-parser.config :as gp-config]
|
|
[logseq.graph-parser.config :as gp-config]
|
|
|
- [logseq.graph-parser.mldoc :as gp-mldoc]
|
|
|
|
|
[logseq.graph-parser.util.page-ref :as page-ref]
|
|
[logseq.graph-parser.util.page-ref :as page-ref]
|
|
|
[promesa.core :as p]))
|
|
[promesa.core :as p]))
|
|
|
|
|
|
|
|
-(defn- handle-received-text [result]
|
|
|
|
|
- (let [{:keys [title url]} result
|
|
|
|
|
- page (or (state/get-current-page)
|
|
|
|
|
- (string/lower-case (date/journal-name)))
|
|
|
|
|
- format (db/get-page-format page)
|
|
|
|
|
- time (date/get-current-time)
|
|
|
|
|
- url (if (and (gp-mldoc/link? format title) (not url))
|
|
|
|
|
- title
|
|
|
|
|
- url)
|
|
|
|
|
- text (if (= url title) nil title)
|
|
|
|
|
- [text url] (if (or (gp-mldoc/link? format url) (not url))
|
|
|
|
|
- [text url]
|
|
|
|
|
- (string/split url "\"\n"))
|
|
|
|
|
- text (some-> text (string/replace #"^\"" ""))
|
|
|
|
|
- url (and url
|
|
|
|
|
- (cond (boolean (text-util/get-matched-video url))
|
|
|
|
|
- (util/format "{{video %s}}" url)
|
|
|
|
|
-
|
|
|
|
|
- (and (string/includes? url "twitter.com")
|
|
|
|
|
- (string/includes? url "status"))
|
|
|
|
|
- (util/format "{{twitter %s}}" url)
|
|
|
|
|
-
|
|
|
|
|
- :else
|
|
|
|
|
- (if text
|
|
|
|
|
- (config/link-format format text url)
|
|
|
|
|
- url)))
|
|
|
|
|
- template (get-in (state/get-config)
|
|
|
|
|
- [:quick-capture-templates :text]
|
|
|
|
|
- "**{time}** [[quick capture]]: {text} {url}")
|
|
|
|
|
- values (-> (string/replace template "{time}" time)
|
|
|
|
|
- (string/replace "{text}" (or text ""))
|
|
|
|
|
- (string/replace "{url}" (or url "")))]
|
|
|
|
|
- (if (state/get-edit-block)
|
|
|
|
|
- (editor-handler/insert values)
|
|
|
|
|
- (editor-handler/api-insert-new-block! values {:page page
|
|
|
|
|
- :edit-block? false
|
|
|
|
|
- :replace-empty-target? true}))))
|
|
|
|
|
|
|
+(defn- handle-received-text [args]
|
|
|
|
|
+ ;; {:title :type :url}
|
|
|
|
|
+ (state/pub-event! [:editor/quick-capture args]))
|
|
|
|
|
|
|
|
(defn- embed-asset-file [url format]
|
|
(defn- embed-asset-file [url format]
|
|
|
(p/let [basename (path/basename url)
|
|
(p/let [basename (path/basename url)
|
|
@@ -66,9 +30,9 @@
|
|
|
time (date/get-current-time)
|
|
time (date/get-current-time)
|
|
|
path (editor-handler/get-asset-path basename)
|
|
path (editor-handler/get-asset-path basename)
|
|
|
_file (p/catch
|
|
_file (p/catch
|
|
|
- (.copy Filesystem (clj->js {:from url :to path}))
|
|
|
|
|
- (fn [error]
|
|
|
|
|
- (log/error :copy-file-error {:error error})))
|
|
|
|
|
|
|
+ (.copy Filesystem (clj->js {:from url :to path}))
|
|
|
|
|
+ (fn [error]
|
|
|
|
|
+ (log/error :copy-file-error {:error error})))
|
|
|
url (util/format "../assets/%s" basename)
|
|
url (util/format "../assets/%s" basename)
|
|
|
url (editor-handler/get-asset-file-link format url label true)
|
|
url (editor-handler/get-asset-file-link format url label true)
|
|
|
template (get-in (state/get-config)
|
|
template (get-in (state/get-config)
|
|
@@ -90,9 +54,9 @@
|
|
|
(config/get-pages-directory)
|
|
(config/get-pages-directory)
|
|
|
(str (js/encodeURI (fs-util/file-name-sanity title)) (path/extname url)))
|
|
(str (js/encodeURI (fs-util/file-name-sanity title)) (path/extname url)))
|
|
|
_ (p/catch
|
|
_ (p/catch
|
|
|
- (.copy Filesystem (clj->js {:from url :to path}))
|
|
|
|
|
- (fn [error]
|
|
|
|
|
- (log/error :copy-file-error {:error error})))
|
|
|
|
|
|
|
+ (.copy Filesystem (clj->js {:from url :to path}))
|
|
|
|
|
+ (fn [error]
|
|
|
|
|
+ (log/error :copy-file-error {:error error})))
|
|
|
url (page-ref/->page-ref title)
|
|
url (page-ref/->page-ref title)
|
|
|
template (get-in (state/get-config)
|
|
template (get-in (state/get-config)
|
|
|
[:quick-capture-templates :text]
|
|
[:quick-capture-templates :text]
|
|
@@ -154,32 +118,32 @@
|
|
|
(defn handle-result [result]
|
|
(defn handle-result [result]
|
|
|
(let [result (decode-received-result result)]
|
|
(let [result (decode-received-result result)]
|
|
|
(when-let [type (:type result)]
|
|
(when-let [type (:type result)]
|
|
|
- (cond
|
|
|
|
|
- (string/starts-with? type "text/")
|
|
|
|
|
- (handle-received-text result)
|
|
|
|
|
-
|
|
|
|
|
- (or (string/starts-with? type "image/")
|
|
|
|
|
- (string/starts-with? type "video/")
|
|
|
|
|
- (string/starts-with? type "audio/"))
|
|
|
|
|
- (handle-received-media result)
|
|
|
|
|
-
|
|
|
|
|
- (string/starts-with? type "application/")
|
|
|
|
|
- (handle-received-application result)
|
|
|
|
|
-
|
|
|
|
|
- :else
|
|
|
|
|
- (notification/show!
|
|
|
|
|
- [:div
|
|
|
|
|
- "Parsing current shared content are not supported. Please report the following codes on "
|
|
|
|
|
- [:a {:href "https://github.com/logseq/logseq/issues/new?labels=from:in-app&template=bug_report.yaml"
|
|
|
|
|
- :target "_blank"} "Github"]
|
|
|
|
|
- ". We will look into it soon."
|
|
|
|
|
- [:pre.code (with-out-str (pprint/pprint result))]] :warning false)))))
|
|
|
|
|
|
|
+ (cond
|
|
|
|
|
+ (string/starts-with? type "text/")
|
|
|
|
|
+ (handle-received-text result)
|
|
|
|
|
+
|
|
|
|
|
+ (or (string/starts-with? type "image/")
|
|
|
|
|
+ (string/starts-with? type "video/")
|
|
|
|
|
+ (string/starts-with? type "audio/"))
|
|
|
|
|
+ (handle-received-media result)
|
|
|
|
|
+
|
|
|
|
|
+ (string/starts-with? type "application/")
|
|
|
|
|
+ (handle-received-application result)
|
|
|
|
|
+
|
|
|
|
|
+ :else
|
|
|
|
|
+ (notification/show!
|
|
|
|
|
+ [:div
|
|
|
|
|
+ "Parsing current shared content are not supported. Please report the following codes on "
|
|
|
|
|
+ [:a {:href "https://github.com/logseq/logseq/issues/new?labels=from:in-app&template=bug_report.yaml"
|
|
|
|
|
+ :target "_blank"} "Github"]
|
|
|
|
|
+ ". We will look into it soon."
|
|
|
|
|
+ [:pre.code (with-out-str (pprint/pprint result))]] :warning false)))))
|
|
|
|
|
|
|
|
(defn handle-received []
|
|
(defn handle-received []
|
|
|
(p/let [received (p/catch
|
|
(p/let [received (p/catch
|
|
|
- (.checkSendIntentReceived SendIntent)
|
|
|
|
|
- (fn [error]
|
|
|
|
|
- (log/error :intent-received-error {:error error})))]
|
|
|
|
|
|
|
+ (.checkSendIntentReceived SendIntent)
|
|
|
|
|
+ (fn [error]
|
|
|
|
|
+ (prn :intent-received-error {:error error})))]
|
|
|
(when received
|
|
(when received
|
|
|
(let [result (js->clj received :keywordize-keys true)]
|
|
(let [result (js->clj received :keywordize-keys true)]
|
|
|
(handle-result result)))))
|
|
(handle-result result)))))
|