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

fix(route): picnob #13986

Merged
merged 7 commits into from
Dec 13, 2023
2 changes: 1 addition & 1 deletion lib/v2/picnob/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
'/user/:id': ['TonyRL'],
'/user/:id': ['TonyRL', 'micheal-death'],
};
6 changes: 3 additions & 3 deletions lib/v2/picnob/templates/desc.art
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<source src="{{ item.video }}" type="video/mp4">
</video>
{{ else if item.type === 'img_multi' }}
{{ each images i }}
<a href="{{ i.ori }}"><img src="{{ i.url }}"></a>
{{ each item.images i }}
<img src="{{ i.url }}">
{{ /each }}
{{ else if item.type === 'img_sig' }}
<a href="{{ item.pic }}"><img src="{{ item.pic }}"></a>
<img src="{{ item.pic }}">
{{ /if }}
<br>
{{@ item.sum }}
76 changes: 48 additions & 28 deletions lib/v2/picnob/user.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
// const { parseRelativeDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
const { puppeteerGet } = require('./utils');

module.exports = async (ctx) => {
const baseUrl = 'https://www.picnob.com';
const { id } = ctx.params;
const url = `${baseUrl}/profile/${id}/`;
const { data: response } = await got(url);
const $ = cheerio.load(response);

const data = await puppeteerGet(url);
const $ = cheerio.load(data);
const profileName = $('h1.fullname').text();
const userId = $('input[name=userid]').attr('value');

const { data } = await got(`${baseUrl}/api/posts`, {
searchParams: {
userid: userId,
},
});
const posts = $('.posts .items .item')
.toArray()
.map((item) => {
const link = $(item).find('.cover_link').attr('href');
const icon = $(item).find('.corner .icon');
let type = 'img_sig';
if (icon.hasClass('icon_video')) {
type = 'video';
}
if (icon.hasClass('icon_multi')) {
type = 'img_multi';
}
return {
link,
type,
};
});

const list = data.posts.items.map(async (item) => {
const { shortcode, type } = item;
const link = `${baseUrl}/post/${shortcode}/`;
let images = [];
if (type === 'img_multi') {
images = await ctx.cache.tryGet(link, async () => {
const { data } = await got(link);
const $ = cheerio.load(data);
return [
const list = await Promise.all(
posts.slice(0, 10).map(async (item) => {
const link = `${baseUrl}${item.link}`;
const data = await ctx.cache.tryGet(link, async () => await puppeteerGet(link));
const $ = cheerio.load(data);
item.sum = $('.sum_full').text();
item.time = $('.time').find('.txt').text();

if (item.type === 'img_multi') {
item.images = [
...new Set(
$('.post_slide a')
.toArray()
Expand All @@ -41,15 +53,23 @@ module.exports = async (ctx) => {
})
),
];
});
}
return {
title: item.sum_pure,
description: art(path.join(__dirname, 'templates/desc.art'), { item, images }),
link,
pubDate: parseDate(item.time, 'X'),
};
});
}
if (item.type === 'video') {
item.pic = $('.video_img').find('img').attr('data-src');
item.video = $('.downbtn').attr('href');
}
if (item.type === 'img_sig') {
item.pic = $('.pic').find('img').attr('data-src');
}

return {
title: item.sum,
description: art(path.join(__dirname, 'templates/desc.art'), { item }),
link,
// pubDate: parseRelativeDate(item.time),
};
})
);

ctx.state.data = {
title: `${profileName} (@${id}) - Picnob`,
Expand Down
13 changes: 13 additions & 0 deletions lib/v2/picnob/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const puppeteerGet = async (url) => {
const browser = await require('@/utils/puppeteer')();
const page = await browser.newPage();
await page.goto(url);
const html = await page.evaluate(() => document.documentElement.innerHTML);
await page.close();
await browser.close();
return html;
};

module.exports = {
puppeteerGet,
};