Skip to content
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
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions packages/server/src/routes/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function search(ctx: Context<{ keywords: string }>) {
}

/**
* 搜索表情包, 爬其它站资源
* 搜索表情包, 爬其它站资源,搜狗表情站
* @param ctx Context
*/
export async function searchExpression(
Expand All @@ -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=>{
Copy link
Owner

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 */)


img_arr.push({image:element.thumbSrc,width:90,height:90});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

width and height should not be fixed value. It should get from image data.

})


const images = img_arr as Image[];






return images;



}

/**
Expand Down