fix: images from github repos can't be displayed

pull/1347/head
Tienson Qin 2021-02-17 18:07:16 +08:00
parent 102e68a07a
commit f9f819a566
7 changed files with 17 additions and 10 deletions

View File

@ -241,7 +241,8 @@
nil nil
(safe-read-string metadata false)) (safe-read-string metadata false))
title (second (first label))] title (second (first label))]
(if (config/local-asset? href) (if (and (config/local-asset? href)
(config/local-db? (state/get-current-repo)))
(asset-link config title href label metadata full_text) (asset-link config title href label metadata full_text)
(let [href (if (util/starts-with? href "http") (let [href (if (util/starts-with? href "http")
href href

View File

@ -57,8 +57,14 @@
(protocol/rmdir! (get-fs dir) dir)) (protocol/rmdir! (get-fs dir) dir))
(defn read-file (defn read-file
[dir path] ([dir path]
(protocol/read-file (get-fs dir) dir path)) (let [fs (get-fs dir)
options (if (= fs bfs-record)
{:encoding "utf8"}
{})]
(read-file dir path {})))
([dir path options]
(protocol/read-file (get-fs dir) dir path options)))
(defn write-file! (defn write-file!
[repo dir path content opts] [repo dir path content opts]

View File

@ -22,9 +22,8 @@
(p/rejected "Unlinking a directory is not allowed"))))) (p/rejected "Unlinking a directory is not allowed")))))
(rmdir! [this dir] (rmdir! [this dir]
(js/window.workerThread.rimraf dir)) (js/window.workerThread.rimraf dir))
(read-file [this dir path] (read-file [this dir path options]
(let [option (clj->js {:encoding "utf8"})] (js/window.pfs.readFile (str dir "/" path) (clj->js options)))
(js/window.pfs.readFile (str dir "/" path) option)))
(write-file! [this repo dir path content opts] (write-file! [this repo dir path content opts]
(when-not (util/electron?) (when-not (util/electron?)
(js/window.pfs.writeFile (str dir "/" path) content))) (js/window.pfs.writeFile (str dir "/" path) content)))

View File

@ -97,7 +97,7 @@
(rmdir! [this dir] (rmdir! [this dir]
nil) nil)
(read-file [this dir path] (read-file [this dir path options]
(let [handle-path (str "handle" dir "/" path)] (let [handle-path (str "handle" dir "/" path)]
(p/let [handle (idb/get-item handle-path) (p/let [handle (idb/get-item handle-path)
local-file (and handle (.getFile handle))] local-file (and handle (.getFile handle))]

View File

@ -30,7 +30,7 @@
(ipc/ipc "unlink" path)) (ipc/ipc "unlink" path))
(rmdir! [this dir] (rmdir! [this dir]
nil) nil)
(read-file [this dir path] (read-file [this dir path _options]
(let [path (concat-path dir path)] (let [path (concat-path dir path)]
(ipc/ipc "readFile" path))) (ipc/ipc "readFile" path)))
(write-file! [this repo dir path content _opts] (write-file! [this repo dir path content _opts]

View File

@ -5,7 +5,7 @@
(readdir [this dir]) (readdir [this dir])
(unlink! [this path opts]) (unlink! [this path opts])
(rmdir! [this dir]) (rmdir! [this dir])
(read-file [this dir path]) (read-file [this dir path opts])
(write-file! [this repo dir path content opts]) (write-file! [this repo dir path content opts])
(rename! [this repo old-path new-path]) (rename! [this repo old-path new-path])
(stat [this dir path]) (stat [this dir path])

View File

@ -37,7 +37,8 @@
path)] path)]
(util/p-handle (util/p-handle
(fs/read-file (config/get-repo-dir (state/get-current-repo)) (fs/read-file (config/get-repo-dir (state/get-current-repo))
path) path
{})
(fn [blob] (fn [blob]
(let [blob (js/Blob. (array blob) (clj->js {:type "image"})) (let [blob (js/Blob. (array blob) (clj->js {:type "image"}))
img-url (image/create-object-url blob)] img-url (image/create-object-url blob)]