fix(route): iwara subscriptions (#12417)
* fix(route): iwara subscriptions * style: auto format --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
3888e6781c
commit
a45d2b49b6
|
|
@ -1,48 +1,92 @@
|
|||
const got = require('@/utils/got');
|
||||
const config = require('@/config').value;
|
||||
const cheerio = require('cheerio');
|
||||
const { art } = require('@/utils/render');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const path = require('path');
|
||||
const md = require('markdown-it')({
|
||||
html: true,
|
||||
});
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = `https://ecchi.iwara.tv`;
|
||||
const subUrl = `https://ecchi.iwara.tv/subscriptions`;
|
||||
const rootUrl = `https://www.iwara.tv`;
|
||||
const videoSubUrl = 'https://api.iwara.tv/videos?page=0&limit=30&subscribed=true';
|
||||
const imageSubUrl = 'https://api.iwara.tv/images?page=0&limit=30&subscribed=true';
|
||||
const cookie = config.iwara.cookie;
|
||||
|
||||
if (cookie === undefined) {
|
||||
throw Error('Iwara subscription RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
const videoResponse = await got({
|
||||
method: 'get',
|
||||
url: subUrl,
|
||||
url: videoSubUrl,
|
||||
headers: {
|
||||
Cookie: cookie,
|
||||
},
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const username = $('a.btn.btn-info.btn-sm.user').text().trim();
|
||||
const list = $('div.views-column');
|
||||
|
||||
const items = list
|
||||
.map((_, item) => {
|
||||
const imageUrl = 'https:' + $(item).find('img').attr('src');
|
||||
const type = $(item).find('div.field').hasClass('field-type-video') ? 'Video' : 'Image';
|
||||
return {
|
||||
title: $(item).find('h3.title').text(),
|
||||
author: $(item).find('a.username').text(),
|
||||
link: rootUrl + $(item).find('h3.title > a').attr('href'),
|
||||
category: type,
|
||||
description: art(path.join(__dirname, 'templates/subscriptions.art'), {
|
||||
const imageResponse = await got({
|
||||
method: 'get',
|
||||
url: imageSubUrl,
|
||||
headers: {
|
||||
Cookie: cookie,
|
||||
},
|
||||
});
|
||||
|
||||
const videoList = videoResponse.data.results.map((item) => {
|
||||
const imageUrl = item.file ? 'https://i.iwara.tv/image/original/' + item.file.id.toString().padStart(2, '0') + '/thumbnail-' + item.thumbnail.toString().padStart(2, '0') + '.jpg' : '';
|
||||
return {
|
||||
title: item.title,
|
||||
author: item.user.name,
|
||||
link: rootUrl + '/video/' + item.id,
|
||||
category: 'Video',
|
||||
imageUrl,
|
||||
pubDate: parseDate(item.createdAt),
|
||||
};
|
||||
});
|
||||
|
||||
const imageList = imageResponse.data.results.map((item) => {
|
||||
const imageUrl = item.thumbnail ? 'https://i.iwara.tv/image/thumbnail/' + item.thumbnail.id + '/' + item.thumbnail.id + '.jpg' : '';
|
||||
return {
|
||||
title: item.title,
|
||||
author: item.user.name,
|
||||
link: rootUrl + '/image/' + item.id,
|
||||
category: 'Image',
|
||||
imageUrl,
|
||||
pubDate: parseDate(item.createdAt),
|
||||
};
|
||||
});
|
||||
|
||||
const list = videoList.concat(imageList);
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const link = item.link.replace('www.iwara.tv', 'api.iwara.tv');
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
headers: {
|
||||
Cookie: cookie,
|
||||
},
|
||||
});
|
||||
const type = item.category;
|
||||
const imageUrl = item.imageUrl;
|
||||
const body = response.data.body ? md.render(response.data.body) : '';
|
||||
|
||||
item.description = art(path.join(__dirname, 'templates/subscriptions.art'), {
|
||||
type,
|
||||
imageUrl,
|
||||
}),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
});
|
||||
item.description += body;
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${username}'s iwara Subscription`,
|
||||
title: `Iwara Subscription`,
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<h3>{{ type }}</h3><br><img src="{{ imageUrl }}">
|
||||
<h3>{{ type }}</h3><br><img src="{{ imageUrl }}"><br>
|
||||
Loading…
Reference in New Issue