mirror of https://github.com/logseq/logseq
fix: dragged video doesn't render by default
parent
410381c820
commit
df2b9fc53c
|
@ -66,11 +66,6 @@
|
|||
"http://localhost:3000"
|
||||
(util/format "https://%s.com" app-name)))
|
||||
|
||||
(def api
|
||||
(if dev?
|
||||
"http://localhost:3000/api/v1/"
|
||||
(str website "/api/v1/")))
|
||||
|
||||
(def asset-domain (util/format "https://asset.%s.com"
|
||||
app-name))
|
||||
|
||||
|
|
|
@ -17,13 +17,11 @@
|
|||
[frontend.handler.block :as block-handler]
|
||||
[frontend.handler.common :as common-handler]
|
||||
[frontend.handler.export :as export]
|
||||
[frontend.handler.image :as image-handler]
|
||||
[frontend.handler.notification :as notification]
|
||||
[frontend.handler.repeated :as repeated]
|
||||
[frontend.handler.route :as route-handler]
|
||||
[frontend.handler.assets :as assets-handler]
|
||||
[frontend.idb :as idb]
|
||||
[frontend.image :as image]
|
||||
[frontend.mobile.util :as mobile-util]
|
||||
[frontend.modules.outliner.core :as outliner-core]
|
||||
[frontend.modules.outliner.transaction :as outliner-tx]
|
||||
|
@ -1322,9 +1320,10 @@
|
|||
|
||||
(defn get-asset-file-link
|
||||
[format url file-name image?]
|
||||
(let [pdf? (and url (string/ends-with? (string/lower-case url) ".pdf"))]
|
||||
(let [pdf? (and url (string/ends-with? (string/lower-case url) ".pdf"))
|
||||
video? (and url (util/ext-of-video? url))]
|
||||
(case (keyword format)
|
||||
:markdown (util/format (str (when (or image? pdf?) "!") "[%s](%s)") file-name url)
|
||||
:markdown (util/format (str (when (or image? video? pdf?) "!") "[%s](%s)") file-name url)
|
||||
:org (if image?
|
||||
(util/format "[[%s]]" url)
|
||||
(util/format "[[%s][%s]]" url file-name))
|
||||
|
@ -1464,7 +1463,7 @@
|
|||
[id ^js files format uploading? drop-or-paste?]
|
||||
(let [repo (state/get-current-repo)
|
||||
block (state/get-edit-block)]
|
||||
(if (config/local-db? repo)
|
||||
(when (config/local-db? repo)
|
||||
(-> (save-assets! block repo (js->clj files))
|
||||
(p/then
|
||||
(fn [res]
|
||||
|
@ -1487,28 +1486,7 @@
|
|||
(fn []
|
||||
(reset! uploading? false)
|
||||
(reset! *asset-uploading? false)
|
||||
(reset! *asset-uploading-process 0))))
|
||||
(image/upload
|
||||
files
|
||||
(fn [file file-name file-type]
|
||||
(image-handler/request-presigned-url
|
||||
file file-name file-type
|
||||
uploading?
|
||||
(fn [signed-url]
|
||||
(insert-command! id
|
||||
(get-asset-file-link format signed-url file-name true)
|
||||
format
|
||||
{:last-pattern (if drop-or-paste? "" (state/get-editor-command-trigger))
|
||||
:restore? true})
|
||||
|
||||
(reset! *asset-uploading? false)
|
||||
(reset! *asset-uploading-process 0))
|
||||
(fn [e]
|
||||
(let [process (* (/ (gobj/get e "loaded")
|
||||
(gobj/get e "total"))
|
||||
100)]
|
||||
(reset! *asset-uploading? false)
|
||||
(reset! *asset-uploading-process process)))))))))
|
||||
(reset! *asset-uploading-process 0)))))))
|
||||
|
||||
;; Editor should track some useful information, like editor modes.
|
||||
;; For example:
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
(:require [clojure.string :as string]
|
||||
[frontend.config :as config]
|
||||
[frontend.fs :as fs]
|
||||
[frontend.handler.notification :as notification]
|
||||
[frontend.image :as image]
|
||||
[frontend.state :as state]
|
||||
[frontend.util :as util]
|
||||
|
@ -51,46 +50,3 @@
|
|||
(js/console.dir error))))))
|
||||
(catch :default _e
|
||||
nil))))
|
||||
|
||||
(defn request-presigned-url
|
||||
[file filename mime-type uploading? url-handler on-processing]
|
||||
(cond
|
||||
(> (gobj/get file "size") (* 12 1024 1024))
|
||||
(notification/show! [:p "Sorry, we don't support any file that's larger than 12MB."] :error)
|
||||
|
||||
:else
|
||||
(do
|
||||
(reset! uploading? true)
|
||||
;; start uploading?
|
||||
(util/post (str config/api "presigned_url")
|
||||
{:filename filename
|
||||
:mime-type mime-type}
|
||||
(fn [{:keys [presigned-url s3-object-key] :as resp}]
|
||||
(if presigned-url
|
||||
(util/upload presigned-url
|
||||
file
|
||||
(fn [_result]
|
||||
;; request cdn signed url
|
||||
(util/post (str config/api "signed_url")
|
||||
{:s3-object-key s3-object-key}
|
||||
(fn [{:keys [signed-url]}]
|
||||
(reset! uploading? false)
|
||||
(if signed-url
|
||||
(url-handler signed-url)
|
||||
(prn "Something error, can't get a valid signed url.")))
|
||||
(fn [_error]
|
||||
(reset! uploading? false)
|
||||
(prn "Something error, can't get a valid signed url."))))
|
||||
(fn [error]
|
||||
(reset! uploading? false)
|
||||
(prn "upload failed.")
|
||||
(js/console.dir error))
|
||||
(fn [e]
|
||||
(on-processing e)))
|
||||
;; TODO: notification, or re-try
|
||||
(do
|
||||
(reset! uploading? false)
|
||||
(prn "failed to get any presigned url, resp: " resp))))
|
||||
(fn [_error]
|
||||
;; (prn "Get token failed, error: " error)
|
||||
(reset! uploading? false))))))
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
(ns frontend.image
|
||||
"Image related utility fns"
|
||||
(:require ["/frontend/exif" :as exif]
|
||||
[clojure.string :as string]
|
||||
[frontend.date :as date]
|
||||
[goog.object :as gobj]))
|
||||
|
||||
(defn reverse?
|
||||
|
@ -70,19 +68,3 @@
|
|||
(.createObjectURL (or (.-URL js/window)
|
||||
(.-webkitURL js/window))
|
||||
file))
|
||||
|
||||
;; (defn build-image
|
||||
;; []
|
||||
;; (let [img (js/Image.)]
|
||||
;; ))
|
||||
|
||||
(defn upload
|
||||
[files file-handler & {:keys [files-limit]
|
||||
:or {files-limit 1}}]
|
||||
(doseq [file (take files-limit (array-seq files))]
|
||||
(let [file-type (gobj/get file "type")
|
||||
ymd (->> (vals (date/year-month-day-padded))
|
||||
(string/join "_"))
|
||||
file-name (str ymd "_" (gobj/get file "name"))]
|
||||
(when (= 0 (.indexOf file-type "image/"))
|
||||
(file-handler file file-name file-type)))))
|
||||
|
|
|
@ -201,6 +201,11 @@
|
|||
(string/ends-with? %))
|
||||
[".png" ".jpg" ".jpeg" ".bmp" ".gif" ".webp" ".svg"]))
|
||||
|
||||
(defn ext-of-video? [s]
|
||||
(some #(-> (string/lower-case s)
|
||||
(string/ends-with? %))
|
||||
[".mp4" ".mkv" ".mov" ".wmv" ".avi" ".webm" ".mpg" ".ts" ".ogg" ".flv"]))
|
||||
|
||||
;; ".lg:absolute.lg:inset-y-0.lg:right-0.lg:w-1/2"
|
||||
(defn hiccup->class
|
||||
[class]
|
||||
|
@ -223,29 +228,6 @@
|
|||
(.then #(on-ok %)))
|
||||
(on-failed resp)))))))))
|
||||
|
||||
#?(:cljs
|
||||
(defn upload
|
||||
[url file on-ok on-failed on-progress]
|
||||
(let [xhr (js/XMLHttpRequest.)]
|
||||
(.open xhr "put" url)
|
||||
(gobj/set xhr "onload" on-ok)
|
||||
(gobj/set xhr "onerror" on-failed)
|
||||
(when (and (gobj/get xhr "upload")
|
||||
on-progress)
|
||||
(gobj/set (gobj/get xhr "upload")
|
||||
"onprogress"
|
||||
on-progress))
|
||||
(.send xhr file))))
|
||||
|
||||
#?(:cljs
|
||||
(defn post
|
||||
[url body on-ok on-failed]
|
||||
(fetch url {:method "post"
|
||||
:headers {:Content-Type "application/json"}
|
||||
:body (js/JSON.stringify (clj->js body))}
|
||||
on-ok
|
||||
on-failed)))
|
||||
|
||||
(defn zero-pad
|
||||
[n]
|
||||
(if (< n 10)
|
||||
|
|
Loading…
Reference in New Issue