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:
Kyouya 2021-09-23 12:36:19 +08:00 committed by GitHub
parent 1cbe9f2a21
commit eb7d33dd89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 13 deletions

View File

@ -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'),