fix(route): add debug json output and cookie support (#9539)
* fix(route): add debug json output and cookie support * Update lib/v2/qbittorrent/news.js
This commit is contained in:
parent
48c0faa01c
commit
edb6e5deec
|
|
@ -4,6 +4,9 @@ const { parseDate } = require('@/utils/parse-date');
|
|||
const timezone = require('@/utils/timezone');
|
||||
const path = require('path');
|
||||
const { art } = require('@/utils/render');
|
||||
const { CookieJar } = require('tough-cookie');
|
||||
|
||||
const cookieJar = new CookieJar();
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://agirls.aotter.net';
|
||||
|
|
@ -14,6 +17,7 @@ module.exports = async (ctx) => {
|
|||
headers: {
|
||||
Referer: baseUrl,
|
||||
},
|
||||
cookieJar,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
|
@ -36,6 +40,7 @@ module.exports = async (ctx) => {
|
|||
headers: {
|
||||
Referer: baseUrl + '/posts/' + (category ? `/${category}` : ''),
|
||||
},
|
||||
cookieJar,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
|
|
@ -67,5 +72,6 @@ module.exports = async (ctx) => {
|
|||
description: $('head meta[name=description]').attr('content'),
|
||||
item: items,
|
||||
language: $('html').attr('lang'),
|
||||
cookieJar,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ const { parseDate } = require('@/utils/parse-date');
|
|||
const timezone = require('@/utils/timezone');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
const { CookieJar } = require('tough-cookie');
|
||||
|
||||
const cookieJar = new CookieJar();
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://monitor.firefox.com';
|
||||
|
|
@ -13,6 +16,7 @@ module.exports = async (ctx) => {
|
|||
headers: {
|
||||
Referer: baseUrl,
|
||||
},
|
||||
cookieJar,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.body);
|
||||
|
|
@ -35,6 +39,7 @@ module.exports = async (ctx) => {
|
|||
headers: {
|
||||
Referer: baseUrl + '/breaches',
|
||||
},
|
||||
cookieJar,
|
||||
});
|
||||
const content = cheerio.load(article.body);
|
||||
|
||||
|
|
@ -54,7 +59,7 @@ module.exports = async (ctx) => {
|
|||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: baseUrl,
|
||||
description: String($('head meta[name=description]').attr('content').trim()),
|
||||
description: $('head meta[name=description]').attr('content').trim(),
|
||||
item: items,
|
||||
image: $('head meta[property=og:image]').attr('content'),
|
||||
};
|
||||
|
|
@ -62,7 +67,7 @@ module.exports = async (ctx) => {
|
|||
ctx.state.json = {
|
||||
title: $('title').text(),
|
||||
link: baseUrl,
|
||||
description: String($('head meta[name=description]').attr('content').trim()),
|
||||
description: $('head meta[name=description]').attr('content').trim(),
|
||||
item: items,
|
||||
image: $('head meta[property=og:image]').attr('content'),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -118,5 +118,12 @@ module.exports = async (ctx) => {
|
|||
title: `${user}/${repo}: ${typeDict[type].title} #${number} - ${issue.title}`,
|
||||
link: issue.html_url,
|
||||
item: items,
|
||||
rateLimit: {
|
||||
limit: parseInt(response.headers['x-ratelimit-limit']),
|
||||
remaining: parseInt(response.headers['x-ratelimit-remaining']),
|
||||
reset: parseDate(parseInt(response.headers['x-ratelimit-reset']) * 1000),
|
||||
resoure: response.headers['x-ratelimit-resource'],
|
||||
used: parseInt(response.headers['x-ratelimit-used']),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -49,4 +49,12 @@ module.exports = async (ctx) => {
|
|||
language: 'en-US',
|
||||
item: items,
|
||||
};
|
||||
|
||||
ctx.state.json = {
|
||||
title: $('title').text(),
|
||||
link: rootUrl + '/blog',
|
||||
description: $('meta[name="description"]').attr('content'),
|
||||
language: 'en-US',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const dayjs = require('dayjs');
|
||||
const utc = require('dayjs/plugin/utc');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { parseDate, parseRelativeDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
const { CookieJar } = require('tough-cookie');
|
||||
|
||||
const cookieJar = new CookieJar();
|
||||
|
||||
const categories = {
|
||||
index: {
|
||||
|
|
@ -57,16 +58,13 @@ module.exports = async (ctx) => {
|
|||
const cat = categories[category];
|
||||
const baseUrl = 'https://www2.hkej.com';
|
||||
|
||||
dayjs.extend(utc);
|
||||
const yesterday = dayjs().utcOffset(8).subtract(1, 'day').format('YYYY-MM-DD');
|
||||
const today = dayjs().utcOffset(8).format('YYYY-MM-DD');
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: baseUrl + cat.link,
|
||||
headers: {
|
||||
Referer: baseUrl,
|
||||
},
|
||||
cookieJar,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
|
@ -102,6 +100,7 @@ module.exports = async (ctx) => {
|
|||
headers: {
|
||||
Referer: cat.link,
|
||||
},
|
||||
cookieJar,
|
||||
});
|
||||
const content = cheerio.load(article.data);
|
||||
|
||||
|
|
@ -123,19 +122,13 @@ module.exports = async (ctx) => {
|
|||
})
|
||||
.get();
|
||||
|
||||
const pubDate = content('p.info span.date')
|
||||
.text()
|
||||
.trim()
|
||||
.replace('日', '')
|
||||
.replace('今', today)
|
||||
.replace('昨', yesterday)
|
||||
.replace(/[年月]/g, '-');
|
||||
const pubDate = content('p.info span.date').text().trim();
|
||||
|
||||
item.category = content('p.info span.cate a')
|
||||
.toArray()
|
||||
.map((e) => content(e).text().trim());
|
||||
item.description = renderDesc(articleImg, content('div#article-content').html());
|
||||
item.pubDate = timezone(parseDate(pubDate), +8);
|
||||
item.pubDate = timezone(/(今|昨)/.test(pubDate) ? parseRelativeDate(pubDate) : parseDate(pubDate, 'YYYY M D'), +8);
|
||||
|
||||
return item;
|
||||
})
|
||||
|
|
@ -156,5 +149,6 @@ module.exports = async (ctx) => {
|
|||
description: `信報網站(www.hkej.com)即時新聞${cat.name},提供${cat.description}。`,
|
||||
item: items,
|
||||
language: 'zh-hk',
|
||||
cookieJar,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -195,4 +195,12 @@ module.exports = async (ctx) => {
|
|||
language: 'zh-hk',
|
||||
item: items,
|
||||
};
|
||||
|
||||
ctx.state.json = {
|
||||
title: feedTitle,
|
||||
link: `https://www.hkepc.com/${category}`,
|
||||
description: '電腦領域 HKEPC Hardware - 全港 No.1 PC網站',
|
||||
language: 'zh-hk',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -105,9 +105,17 @@ module.exports = async (ctx) => {
|
|||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: String($('head meta[name=title]').attr('content').trim()),
|
||||
title: $('head meta[name=title]').attr('content').trim(),
|
||||
link: baseUrl + '/' + category,
|
||||
description: String($('head meta[name=description]').attr('content').trim()),
|
||||
description: $('head meta[name=description]').attr('content').trim(),
|
||||
item: items,
|
||||
language: 'zh-hk',
|
||||
};
|
||||
|
||||
ctx.state.json = {
|
||||
title: $('head meta[name=title]').attr('content').trim(),
|
||||
link: baseUrl + '/' + category,
|
||||
description: $('head meta[name=description]').attr('content').trim(),
|
||||
item: items,
|
||||
language: 'zh-hk',
|
||||
};
|
||||
|
|
|
|||
|
|
@ -50,4 +50,10 @@ module.exports = async (ctx) => {
|
|||
link: `${baseUrl}/news.php`,
|
||||
item,
|
||||
};
|
||||
|
||||
ctx.state.json = {
|
||||
title: 'qBittorrent News',
|
||||
link: `${baseUrl}/news.php`,
|
||||
item,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue