Files
RSSHub/lib/v2/myfigurecollection/activity.js
Ethan Shen 6153347f6e feat(route): add MyFigureCollection (#10203)
* feat(route): add MyFigureCollection

* docs: fix typo

* fix: add more pictures & add easy-to-read forms

* fix: some items are inaccessible

* fix: bad urls

* fix: pictures without weight and height
2022-07-15 19:12:52 +08:00

59 lines
2.3 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const category = ctx.params.category ?? '-1';
const language = ctx.params.language ?? '';
const latestAdditions = ctx.params.latestAdditions ?? '1';
const latestEdits = ctx.params.latestEdits ?? '1';
const latestAlerts = ctx.params.latestAlerts ?? '1';
const latestPictures = ctx.params.latestPictures ?? '1';
const rootUrl = `https://${language === 'en' || language === '' ? '' : `${language}.`}myfigurecollection.net`;
const currentUrl = `${rootUrl}/browse.v4.php?mode=activity&latestAdditions=${latestAdditions}&latestEdits=${latestEdits}&latestAlerts=${latestAlerts}&latestPictures=${latestPictures}&rootId=${category}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const items = $('.activity-wrapper')
.toArray()
.map((item) => {
item = $(item);
return {
title: `${item.find('.activity-label').text().split(' • ')[0]}: ${item.find('.stamp-anchor').text()}`,
link: `${rootUrl}${item.find('.stamp-anchor .tbx-tooltip').attr('href')}`,
pubDate: timezone(parseDate(item.find('.activity-time span').attr('title')), +0),
author: item.find('.user-anchor').text(),
description: art(path.join(__dirname, 'templates/activity.art'), {
changelog: item.find('.changelog').text(),
pictures: item
.find('.picture-icon')
.toArray()
.map((image) =>
$(image)
.html()
.match(/url\((.*)\)/)[1]
.replace(/\/thumbnails/, '')
),
}),
};
});
ctx.state.data = {
title: $('title')
.text()
.replace(/ \(.*\)/, ''),
link: currentUrl,
item: items,
};
};