mirror of
https://github.com/logseq/logseq.git
synced 2026-05-27 14:14:24 +00:00
enhance: use /api instead of /api-invoker
This commit is contained in:
@@ -69,11 +69,12 @@
|
||||
|
||||
(defn- validate-auth-token
|
||||
[token]
|
||||
(when-let [valid-tokens (cfgs/get-item :server/tokens)]
|
||||
(when (or (string/blank? token)
|
||||
(not (some #(or (= % token)
|
||||
(= (:value %) token)) valid-tokens)))
|
||||
(throw (js/Error. "Access Deny!")))))
|
||||
(let [token (string/replace token "Bearer " "")]
|
||||
(when-let [valid-tokens (cfgs/get-item :server/tokens)]
|
||||
(when (or (string/blank? token)
|
||||
(not (some #(or (= % token)
|
||||
(= (:value %) token)) valid-tokens)))
|
||||
(throw (js/Error. "Access Deny!"))))))
|
||||
|
||||
(defn- api-pre-handler!
|
||||
[^js req ^js rep callback]
|
||||
@@ -98,7 +99,7 @@
|
||||
(utils/send-to-renderer @*win :invokeLogseqAPI {:syncId sid :method method :args args})
|
||||
(.handleOnce ipcMain (str ::sync! sid) ret-handle)))))
|
||||
|
||||
(defn- api-invoker-fn!
|
||||
(defn- api-handler!
|
||||
[^js req ^js rep]
|
||||
(if-let [^js body (.-body req)]
|
||||
(if-let [method (resolve-real-api-method (.-method body))]
|
||||
@@ -132,7 +133,7 @@
|
||||
;; hooks & routes
|
||||
_ (doto s
|
||||
(.addHook "preHandler" api-pre-handler!)
|
||||
(.post "/api-invoker" api-invoker-fn!)
|
||||
(.post "/api" api-handler!)
|
||||
(.get "/" (fn [_ ^js rep]
|
||||
(let [html (fs-extra/readFileSync (.join path js/__dirname "./docs/api_server.html"))
|
||||
HOST (get-host)
|
||||
@@ -164,4 +165,4 @@
|
||||
[^js win]
|
||||
(reset! *win win)
|
||||
(let [t (setup-state-watch!)]
|
||||
(reset-state!) t))
|
||||
(reset-state!) t))
|
||||
|
||||
@@ -57,10 +57,12 @@
|
||||
[dir & {:keys [path-only?]}]
|
||||
(p/let [result (protocol/readdir (get-fs dir) dir)
|
||||
result (bean/->clj result)]
|
||||
(if (and path-only? (map? (first result)))
|
||||
(->> (map :uri result)
|
||||
(map gp-util/path-normalize))
|
||||
(map #(update % :uri gp-util/path-normalize) result))))
|
||||
(let [result (if (and path-only? (map? (first result)))
|
||||
(map :uri result)
|
||||
result)]
|
||||
(if (and (map? (first result)) (:uri (first result)))
|
||||
(map #(update % :uri gp-util/path-normalize) result)
|
||||
(map gp-util/path-normalize result)))))
|
||||
|
||||
(defn unlink!
|
||||
"Should move the path to logseq/recycle instead of deleting it."
|
||||
|
||||
Reference in New Issue
Block a user