fix(route): update url & fix a typo (#8185)
Co-authored-by: SettingDust <settingdust@gmail.com> Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
1cbe9f2a21
commit
eb7d33dd89
|
|
@ -1,7 +1,8 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const url = 'http://jwc.njfu.edu.cn//sy/';
|
||||
const url = 'http://jwc.njfu.edu.cn/sy/';
|
||||
let link = '';
|
||||
const map = {
|
||||
xjfw: '校级发文',
|
||||
tzgg: '通知公告',
|
||||
|
|
@ -10,26 +11,35 @@ const map = {
|
|||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = map.hasOwnProperty(ctx.params.category) ? ctx.params.category : 'tzgg';
|
||||
let response;
|
||||
const category = ctx.params.category ?? 'tzgg';
|
||||
if (category === 'xzzq') {
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: 'http://jwc.njfu.edu.cn//xzzq/index.html',
|
||||
});
|
||||
link = 'http://jwc.njfu.edu.cn/xzzq/';
|
||||
} else {
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: url + category + '/index.html',
|
||||
});
|
||||
link = `${url}${category}/`;
|
||||
}
|
||||
|
||||
const response = await got(link, {
|
||||
method: 'get',
|
||||
hooks: {
|
||||
beforeRedirect: [
|
||||
(options, response) => {
|
||||
const cookie = response.headers['set-cookie'];
|
||||
if (cookie) {
|
||||
const cook = cookie.map((c) => c.split(';')[0]).join('; ');
|
||||
options.headers.Cookie = cook;
|
||||
options.headers.Referer = response.url;
|
||||
}
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('.List_R4');
|
||||
|
||||
ctx.state.data = {
|
||||
title: '南京林业大学教务处-' + map[category],
|
||||
link: url + category + '/index.html',
|
||||
description: '南京林业大学教务处-' + map[category] + 'Rss源',
|
||||
link,
|
||||
description: `南京林业大学教务处-${map[category]}`,
|
||||
item: list
|
||||
.map((index, item) => ({
|
||||
title: $(item).find('a').attr('title'),
|
||||
|
|
|
|||
Loading…
Reference in New Issue