mirror of https://github.com/logseq/logseq
feat: support Media Fragment URIs with audio (#8300)
* fix: fragment urls for audio player * fix: add Support for url queries and fragments to extension detection * feat: add tests for extraction of file extension Co-authored-by: Gabriel Horner <gabriel@logseq.com>pull/8327/head^2
parent
a3c7308dc0
commit
351a4f34a3
|
@ -208,12 +208,12 @@
|
|||
|
||||
(defn path->file-ext
|
||||
[path-or-file-name]
|
||||
(last (split-last "." path-or-file-name)))
|
||||
(second (re-find #"(?:\.)(\w+)[^.]*$" path-or-file-name)))
|
||||
|
||||
(defn get-format
|
||||
[file]
|
||||
(when file
|
||||
(normalize-format (keyword (string/lower-case (path->file-ext file))))))
|
||||
(normalize-format (keyword (some-> (path->file-ext file) string/lower-case)))))
|
||||
|
||||
(defn get-file-ext
|
||||
"Copy of frontend.util/get-file-ext. Too basic to couple to main app"
|
||||
|
|
|
@ -12,3 +12,19 @@
|
|||
"4" false
|
||||
"foo bar" false
|
||||
"`property" false))
|
||||
|
||||
(deftest extract-file-extension?
|
||||
(are [x y]
|
||||
(= (gp-util/path->file-ext x) y)
|
||||
"foo.bar" "bar"
|
||||
"foo" nil
|
||||
"foo.bar.baz" "baz"
|
||||
"../assets/audio.mp3" "mp3"
|
||||
;; From https://www.w3.org/TR/media-frags/
|
||||
"../assets/audio.mp3?t=10,20" "mp3"
|
||||
"../assets/audio.mp3?t=10,20#t=10" "mp3"
|
||||
"/root/Documents/audio.mp3" "mp3"
|
||||
"C:\\Users\\foo\\Documents\\audio.mp3" "mp3"
|
||||
"/root/Documents/audio" nil
|
||||
"/root/Documents/audio." nil
|
||||
"special/characters/aäääöüß.7z" "7z"))
|
||||
|
|
|
@ -364,7 +364,8 @@
|
|||
(ui/icon "maximize")]]])]))))
|
||||
|
||||
(rum/defc audio-cp [src]
|
||||
[:audio {:src src
|
||||
;; Change protocol to allow media fragment uris to play
|
||||
[:audio {:src (string/replace-first src gp-config/asset-protocol "file://")
|
||||
:controls true
|
||||
:on-touch-start #(util/stop %)}])
|
||||
|
||||
|
|
Loading…
Reference in New Issue