const axios = require('@/utils/axios'); const qs = require('querystring'); module.exports = async (ctx) => { const link = 'https://www.icourse163.org/category/all'; const homePage = await axios({ method: 'get', url: link, }); const csrfKey = homePage.headers['set-cookie'][0].split(';')[0].split('=')[1]; const response = await axios({ method: 'post', url: `https://www.icourse163.org/web/j/courseBean.getCoursePanelListByFrontCategory.rpc?csrfKey=${csrfKey}`, headers: { 'Content-Type': 'application/x-www-form-urlencoded', Cookie: `NTESSTUDYSI=${csrfKey};`, }, data: qs.stringify({ categoryId: -1, type: 30, orderBy: 10, pageIndex: 1, pageSize: 20, }), }); const items = response.data.result.result.map((item) => { const title = item.name; const link = `https://www.icourse163.org/course/${item.schoolPanel.shortName}-${item.id}`; const lectors = item.termPanel.lectorPanels.reduce((lectors, lector) => { lectors += `${lector.realName || lector.nickName}、`; return lectors; }, ''); const tags = (item.mocTagDtos || []).reduce((tags, tag) => { tags += `${tag.name}、`; return tags; }, ''); const startTime = new Date(item.termPanel.startTime); const startYear = startTime.getFullYear(); const startMonth = (startTime.getMonth() + 1).toString().padStart(2, '0'); const startDate = startTime.getDate(); const startTimeString = item.termPanel.startTime === 32503651201000 ? '待定' : `${startYear}-${startMonth}-${startDate}`; const media = item.VideoUrl ? `
` : `