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
sallto 2023-02-06 09:47:23 +01:00 committed by GitHub
parent a3c7308dc0
commit 351a4f34a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View File

@ -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"

View File

@ -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"))

View File

@ -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 %)}])