-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
表情搜索403报错的问题修复 #469
Open
iqovo
wants to merge
3
commits into
yinxin630:master
Choose a base branch
from
iqovo:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
表情搜索403报错的问题修复 #469
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,7 @@ export async function search(ctx: Context<{ keywords: string }>) { | |
} | ||
|
||
/** | ||
* 搜索表情包, 爬其它站资源 | ||
* 搜索表情包, 爬其它站资源,搜狗表情站 | ||
* @param ctx Context | ||
*/ | ||
export async function searchExpression( | ||
|
@@ -75,50 +75,52 @@ export async function searchExpression( | |
|
||
const res = await axios({ | ||
method: 'get', | ||
url: `https://pic.sogou.com/pics/json.jsp?query=${encodeURIComponent( | ||
`${keywords} 表情`, | ||
)}&st=5&start=0&xml_len=60&callback=callback&reqFrom=wap_result&`, | ||
url: `https://pic.sogou.com/napi/wap/emoji/searchlist?keyword=${encodeURIComponent(`${keywords}`)}&st=5&start=0&xml_len=60&callback=callback&reqFrom=wap_result&routeName=emosearch`, | ||
headers: { | ||
accept: '*/*', | ||
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7', | ||
'cache-control': 'no-cache', | ||
pragma: 'no-cache', | ||
'sec-fetch-mode': 'navigate', | ||
'sec-fetch-site': 'same-origin', | ||
referrer: `https://pic.sogou.com/pic/emo/searchList.jsp?statref=search_form&uID=hTHHybkSPt37C46z&spver=0&rcer=&keyword=${encodeURIComponent( | ||
keywords, | ||
)}`, | ||
referrer: `https://pic.sogou.com/`, | ||
referrerPolicy: 'no-referrer-when-downgrade', | ||
'user-agent': | ||
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1', | ||
}, | ||
}); | ||
assert(res.status === 200, '搜索表情包失败, 请重试'); | ||
|
||
try { | ||
const parseDataResult = res.data.match(/callback\((.+)\)/); | ||
const data = JSON.parse(`${parseDataResult[1]}`); | ||
|
||
type Image = { | ||
|
||
|
||
const data = res.data.data.emotions; | ||
|
||
type Image = { | ||
locImageLink: string; | ||
width: number; | ||
height: number; | ||
}; | ||
const images = data.items as Image[]; | ||
return images | ||
.map(({ locImageLink, width, height }) => ({ | ||
image: locImageLink, | ||
width, | ||
height, | ||
})) | ||
.filter((image, index) => | ||
limit === Infinity ? true : index < limit, | ||
); | ||
} catch (err) { | ||
assert(false, '搜索表情包失败, 数据解析异常'); | ||
} | ||
|
||
return []; | ||
}; | ||
|
||
var img_arr=[]; | ||
|
||
data.forEach(element=>{ | ||
|
||
img_arr.push({image:element.thumbSrc,width:90,height:90}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}) | ||
|
||
|
||
const images = img_arr as Image[]; | ||
|
||
|
||
|
||
|
||
|
||
|
||
return images; | ||
|
||
|
||
|
||
} | ||
|
||
/** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should just return
data.map(/* do something */)