Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commitd1b108a

Browse files
author
mydearxym
committed
chore(editor-parser): resolve conflect
1 parent1fd0740 commitd1b108a

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

‎lib/groupher_server_web/controller/og_controller.ex‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,25 @@ defmodule GroupherServerWeb.Controller.OG do
2222
end
2323
end
2424

25-
defpok_response(conn,url,%OpenGraph{title:nil})do
25+
defpok_response(conn,url,%OpenGraph{title:nil,description:nil})do
2626
error_response(conn,url)
2727
end
2828

29-
defpok_response(conn,_url,info)do
29+
defpok_response(conn,url,%OpenGraph{title:nil,description:description}=info)
30+
whennotis_nil(description)do
31+
json(conn,%{
32+
success:1,
33+
meta:%{
34+
title:info.description|>String.slice(0,8),
35+
description:info.description,
36+
image:%{
37+
url:nil
38+
}
39+
}
40+
})
41+
end
42+
43+
defpok_response(conn,url,info)do
3044
json(conn,%{
3145
success:1,
3246
meta:%{
@@ -78,6 +92,19 @@ defmodule GroupherServerWeb.Controller.OG do
7892
})
7993
end
8094

95+
defperror_response(conn,url,"Not found :(")do
96+
json(conn,%{
97+
success:1,
98+
meta:%{
99+
title:url,
100+
description:"--",
101+
image:%{
102+
url:nil
103+
}
104+
}
105+
})
106+
end
107+
81108
defperror_response(conn,_url,_reason)do
82109
json(conn,%{
83110
success:0,

‎test/groupher_server_web/controller/og_test.exs‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,62 @@ defmodule GroupherServerWeb.Test.Controller.OG do
7979
assertMap.has_key?(image,"url")
8080
assertimage["url"]==nil
8181
end
82+
83+
test"return empty valid structure when url not found"do
84+
conn=build_conn()
85+
86+
url="https://zhihu.com"
87+
res=get(conn,"/api/og-info",%{url:url})
88+
res=json_response(res,200)
89+
90+
# IO.inspect(res, label: "json res")
91+
assertMap.has_key?(res,"success")
92+
assertMap.has_key?(res,"meta")
93+
94+
success=res["success"]
95+
assertsuccess==1
96+
97+
meta=res["meta"]
98+
assertMap.has_key?(meta,"description")
99+
assertMap.has_key?(meta,"image")
100+
assertMap.has_key?(meta,"title")
101+
102+
title=get_in(res,["meta","title"])
103+
asserttitle==url
104+
105+
description=get_in(res,["meta","description"])
106+
assertdescription=="--"
107+
108+
image=get_in(res,["meta","image"])
109+
assertMap.has_key?(image,"url")
110+
assertimage["url"]==nil
111+
end
112+
113+
test"return empty valid structure when title nil but description not nil"do
114+
conn=build_conn()
115+
116+
url="https://zhuanlan.zhihu.com"
117+
res=get(conn,"/api/og-info",%{url:url})
118+
res=json_response(res,200)
119+
120+
assertMap.has_key?(res,"success")
121+
assertMap.has_key?(res,"meta")
122+
123+
success=res["success"]
124+
assertsuccess==1
125+
126+
meta=res["meta"]
127+
assertMap.has_key?(meta,"description")
128+
assertMap.has_key?(meta,"image")
129+
assertMap.has_key?(meta,"title")
130+
131+
title=get_in(res,["meta","title"])
132+
description=get_in(res,["meta","title"])
133+
134+
assertString.contains?(description,title)
135+
136+
image=get_in(res,["meta","image"])
137+
assertMap.has_key?(image,"url")
138+
assertimage["url"]==nil
139+
end
82140
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp