Skip to content

Commit

Permalink
style: auto format
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed May 15, 2023
1 parent d0d3b6b commit 9bdba06
Showing 1 changed file with 39 additions and 42 deletions.
81 changes: 39 additions & 42 deletions lib/v2/xiaohongshu/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,52 +114,49 @@ const getNotes = (url, cache) =>
const notesPromise = userPosted.data.notes.map((n) => {
const noteUrl = url + '/' + n.note_id;

return cache.tryGet(
noteUrl,
async () => {
const notePage = await browser.newPage();
await setPageFilter(notePage);

logger.debug(`Requesting ${noteUrl}`);
await notePage.goto(noteUrl);

let feed = {};
try {
feed = await notePage.evaluate(() => window.__INITIAL_STATE__);

// Sometimes the page is not server-side rendered
if (typeof feed?.note?.note === 'undefined' || JSON.stringify(feed?.note?.note) === '{}') {
const res = await notePage.waitForResponse((res) => {
const req = res.request();
return req.url().includes('/api/sns/web/v1/feed') && req.method() === 'POST';
});

const json = await res.json();
const note_card = json.data.items[0].note_card;
feed.note.note = {
title: note_card.title,
noteId: note_card.id,
desc: note_card.desc,
tagList: note_card.tag_list,
imageList: note_card.image_list,
user: note_card.user,
time: note_card.time,
lastUpdateTime: note_card.last_update_time,
};
}
} catch (e) {
throw Error(`Could not get note ${n.note_id}\n${e}`);
}
return cache.tryGet(noteUrl, async () => {
const notePage = await browser.newPage();
await setPageFilter(notePage);

logger.debug(`Requesting ${noteUrl}`);
await notePage.goto(noteUrl);

await notePage.close();
let feed = {};
try {
feed = await notePage.evaluate(() => window.__INITIAL_STATE__);

if (typeof feed?.note?.note !== 'undefined' && JSON.stringify(feed?.note?.note) !== '{}') {
return feed.note.note;
} else {
throw Error(`Could not get note ${n.note_id}`);
// Sometimes the page is not server-side rendered
if (typeof feed?.note?.note === 'undefined' || JSON.stringify(feed?.note?.note) === '{}') {
const res = await notePage.waitForResponse((res) => {
const req = res.request();
return req.url().includes('/api/sns/web/v1/feed') && req.method() === 'POST';
});

const json = await res.json();
const note_card = json.data.items[0].note_card;
feed.note.note = {
title: note_card.title,
noteId: note_card.id,
desc: note_card.desc,
tagList: note_card.tag_list,
imageList: note_card.image_list,
user: note_card.user,
time: note_card.time,
lastUpdateTime: note_card.last_update_time,
};
}
} catch (e) {
throw Error(`Could not get note ${n.note_id}\n${e}`);
}
);

await notePage.close();

if (typeof feed?.note?.note !== 'undefined' && JSON.stringify(feed?.note?.note) !== '{}') {
return feed.note.note;
} else {
throw Error(`Could not get note ${n.note_id}`);
}
});
});

user = otherInfo.data.basic_info;
Expand Down

0 comments on commit 9bdba06

Please sign in to comment.