[perf] handle 404

This commit is contained in:
SouthFox 2023-08-31 02:48:41 +08:00
parent a65fd26722
commit 43ffb71113

View file

@ -62,18 +62,31 @@
(let [id (-> request :path-params :id) (let [id (-> request :path-params :id)
post-url (str/join ["https://zhuanlan.zhihu.com/p/" id]) post-url (str/join ["https://zhuanlan.zhihu.com/p/" id])
page (-> (client/get post-url) :body Jsoup/parse) page (-> (client/get post-url) :body Jsoup/parse)
docs (.getElementsByClass page "Post-RichTextContainer")
title (.getElementsByClass page "Post-Title") title (.getElementsByClass page "Post-Title")
post-time (.getElementsByClass page "ContentItem-time") post-time (.getElementsByClass page "ContentItem-time")]
docs (.getElementsByClass page "Post-RichTextContainer")]
(clean-html docs hugo) (clean-html docs hugo)
(clean-images docs) (clean-images docs)
(render-linkcard docs) (render-linkcard docs)
(let [content {:content (.toString docs)
:title (.text title) (if (empty? docs)
:time (first (str/split (.text post-time) #"・")) (let [content {:content "Not Found"
:catalog (.toString (build-catalog docs))}] :title "Not Found"
(if hugo :time ""
content :catalog ""}]
{:status 200 (if hugo
:headers {"Content-Type" "application/json; charset=utf-8"} content
:body (wrap-json content)})))) {:status 404
:headers {"Content-Type" "application/json; charset=utf-8"}
:body (wrap-json content)}))
(let [content {:content (.toString docs)
:title (.text title)
:time (first (str/split (.text post-time) #"・"))
:catalog (.toString (build-catalog docs))}]
(if hugo
content
{:status 200
:headers {"Content-Type" "application/json; charset=utf-8"}
:body (wrap-json content)})))))