Skip to content

Commit

Permalink
Merge branch 'DIYgod:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0501 authored Aug 14, 2024
2 parents 96014f7 + 9c24b9d commit c4b585e
Show file tree
Hide file tree
Showing 11 changed files with 744 additions and 546 deletions.
11 changes: 11 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default [{
'**/.vscode',
'**/docker-compose.yml',
'!.github',
'assets/build/radar-rules.js',
'lib/routes-deprecated',
'lib/router.js',
'**/babel.config.js',
Expand Down Expand Up @@ -123,6 +124,11 @@ export default [{
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',

'@typescript-eslint/no-unused-expressions': ['error', {
allowShortCircuit: true,
allowTernary: true,
}],

// unicorn
'unicorn/consistent-destructuring': 'warn',
'unicorn/consistent-function-scoping': 'warn',
Expand Down Expand Up @@ -246,6 +252,11 @@ export default [{

'yml/no-empty-mapping-value': 'off',
},
}, {
files: ['.puppeteerrc.cjs', 'api/vercel.ts'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
}
}, {
files: ['**/*.yaml', '**/*.yml'],

Expand Down
1 change: 1 addition & 0 deletions lib/routes/bilibili/api-interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface Generalspec {
render_spec: Renderspec;
size_spec: Containersize;
}
/* eslint-disable-next-line @typescript-eslint/no-empty-object-type */
interface AVATARLAYER {}
interface Webcssstyle {
borderRadius: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/buaa/jiaowu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function getArticleUrl(onclick?: string) {
async function getList(url: string | URL, form: Record<string, string> = {}) {
const { body } = await got.post(url, { form });
const $ = load(body);
const title = $('#main > div.dqwz > a').last().text();
const title = $('#main > div.dqwz > a').last().text() || '北京航空航天大学教务部';
const list = $('#main div.news_list > ul > li')
.toArray()
.map((item) => {
Expand Down
171 changes: 171 additions & 0 deletions lib/routes/buaa/lib/space/newbook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import { Data, DataItem, Route } from '@/types';
import { Context } from 'hono';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
import cache from '@/utils/cache';
import { art } from '@/utils/render';
import path from 'path';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);

interface Book {
bibId: string;
inBooklist: number;
thumb: string;
holdingTypes: string[];
author: string;
callno: string[];
docType: string;
onSelfDate: string;
groupId: string;
isbn: string;
inDate: number;
language: string;
bibNo: string;
abstract: string;
docTypeDesc: string;
title: string;
itemCount: number;
tags: string[];
circCount: number;
pub_year: string;
classno: string;
publisher: string;
holdings: string;
}

interface Holding {
classMethod: string;
callNo: string;
inDate: number;
shelfMark: string;
itemsCount: number;
barCode: string;
tempLocation: string;
circStatus: number;
itemId: number;
vol: string;
library: string;
itemStatus: string;
itemsAvailable: number;
location: string;
extenStatus: number;
donatorId: null;
status: string;
locationName: string;
}

interface Info {
_id: string;
imageUrl: string | null;
authorInfo: string;
catalog: string | null;
content: string;
title: string;
}

export const route: Route = {
path: String.raw`/lib/space/:path{newbook.*}`,
name: '图书馆 - 新书速递',
url: 'space.lib.buaa.edu.cn/mspace/newBook',
maintainers: ['OverflowCat'],
example: '/buaa/lib/space/newbook/',
handler,
description: `可通过参数进行筛选:\`/buaa/lib/space/newbook/key1=value1&key2=value2...\`
- \`dcpCode\`:学科分类代码
- 例:
- 工学:\`08\`
- 工学 > 计算机 > 计算机科学与技术:\`080901\`
- 默认值:\`nolimit\`
- 注意事项:不可与 \`clsNo\` 同时使用。
- \`clsNo\`:中图分类号
- 例:
- 计算机科学:\`TP3\`
- 默认值:无
- 注意事项
- 不可与 \`dcpCode\` 同时使用。
- 此模式下获取不到上架日期。
- \`libCode\`:图书馆代码
- 例:
- 本馆:\`00000\`
- 默认值:无
- 注意事项:只有本馆一个可选值。
- \`locaCode\`:馆藏地代码
- 例:
- 五层西-中文新书借阅室(A-Z类):\`02503\`
- 默认值:无
- 注意事项:必须与 \`libCode\` 同时使用。
示例:
- \`buaa/lib/space/newbook\` 为所有新书
- \`buaa/lib/space/newbook/clsNo=U&libCode=00000&locaCode=60001\` 为沙河教2图书馆所有中图分类号为 U(交通运输)的书籍
`,
categories: ['university'],

features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
};

async function handler(ctx: Context): Promise<Data> {
const path = ctx.req.param('path');
const i = path.indexOf('/');
const params = i === -1 ? '' : path.slice(i + 1);
const searchParams = new URLSearchParams(params);
const dcpCode = searchParams.get('dcpCode'); // Filter by subject (discipline code)
const clsNo = searchParams.get('clsNo'); // Filter by class (Chinese Library Classification)
if (dcpCode && clsNo) {
throw new Error('dcpCode and clsNo cannot be used at the same time');
}
searchParams.set('pageSize', '100'); // Max page size. Any larger value will be ignored
searchParams.set('page', '1');
!dcpCode && !clsNo && searchParams.set('dcpCode', 'nolimit'); // No classification filter
const url = `https://space.lib.buaa.edu.cn/meta-local/opac/new/100/${clsNo ? 'byclass' : 'bysubject'}?${searchParams.toString()}`;
const { data } = await got(url);
const list = (data?.data?.dataList || []) as Book[];
const item = await Promise.all(list.map(async (item: Book) => await getItem(item)));
const res: Data = {
title: '北航图书馆 - 新书速递',
item,
description: '北京航空航天大学图书馆新书速递',
language: 'zh-CN',
link: 'https://space.lib.buaa.edu.cn/space/newBook',
author: '北京航空航天大学图书馆',
allowEmpty: true,
image: 'https://lib.buaa.edu.cn/apple-touch-icon.png',
};
return res;
}

async function getItem(item: Book): Promise<DataItem> {
return (await cache.tryGet(item.isbn, async () => {
const info = await getItemInfo(item.isbn);
const holdings = JSON.parse(item.holdings) as Holding[];
const link = `https://space.lib.buaa.edu.cn/space/searchDetailLocal/${item.bibId}`;
const content = art(path.join(__dirname, 'templates/newbook.art'), {
item,
info,
holdings,
});
return {
language: item.language === 'eng' ? 'en' : 'zh-CN',
title: item.title,
pubDate: item.onSelfDate ? timezone(parseDate(item.onSelfDate), +8) : undefined,
description: content,
link,
};
})) as DataItem;
}

async function getItemInfo(isbn: string): Promise<Info | null> {
const url = `https://space.lib.buaa.edu.cn/meta-local/opac/third_api/douban/${isbn}/info`;
const response = await got(url);
return JSON.parse(response.body).data;
}
44 changes: 44 additions & 0 deletions lib/routes/buaa/lib/space/templates/newbook.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{if info.imageUrl}}
<aside><img src="{{info.imageUrl}}" alt="封面"></aside>
{{/if}}
<h2>书籍信息</h2>
<div>
<span class="call-no" style="font-family: JetBrainsMono, monospace; font-style: italic; font-weight: 700; color: #458f57;">{{item.callno.at(0) || '无'}}</span> /
<span class="author">{{item.author}}</span> /
<span class="publisher">{{item.publisher}}</span> /
<span class="pub-year">{{item.pub_year}}</span>
</div>
<h3>简介</h3>
<div itemprop="description">{{info?.content}}</div>
<table>
<tr><th>ISBN</th><td itemprop="isbn">{{item.isbn}}</td></tr>
<tr><th>语言</th><td itemprop="language">{{item.language}}</td></tr>
<tr><th>类型</th><td itemprop="docType">{{item.docTypeDesc}}</td></tr>
</table>
{{if info.authorInfo}}
<h3>作者简介</h3>
<div itemprop="authorInfo">{{info.authorInfo}}</div>
{{/if}}
<h2>馆藏信息</h2>
{{if item.onSelfDate}}
<strong>上架时间</strong>:
<date datetime="{{item.onSelfDate}}">{{item.onSelfDate}}</date>
{{/if}}
<br>
<h3>馆藏地点</h3>
<table>
{{each holdings holding}}
<tr><th>所属馆藏地</th><td>{{holding.location}}</td></tr>
<tr><th>索书号</th><td>{{holding.callNo}}</td></tr>
<tr><th>条码号</th><td>{{holding.barCode}}</td></tr>
<tr><th>编号</th><td>{{holding.itemId}}</td></tr>
<tr>
<th>书刊状态</th>
<td style="color: {{holding.status === '可借' ? '#458f57' : '#d86d02'}}">{{holding.status}}</td>
</tr>
{{/each}}
</table>
{{if info.catalog}}
<h2>目录</h2>
<div itemprop="catalog">{{@ info.catalog}}</div>
{{/if}}
2 changes: 1 addition & 1 deletion lib/routes/fediverse/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async function handler(ctx) {
item: resolvedItems.map((item) => ({
title: item.object.content,
description: `${item.object.content}\n${item.object.attachment?.map((attachment) => `<img src="${attachment.url}" width="${attachment.width}" height="${attachment.height}" />`).join('\n') || ''}`,
link: item.url,
link: item.object.url,
pubDate: parseDate(item.published),
guid: item.id,
})),
Expand Down
29 changes: 12 additions & 17 deletions lib/routes/gdut/oa-news.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import wait from '@/utils/wait';
import { load } from 'cheerio';
import { CookieJar } from 'tough-cookie';
import { parseDate } from '@/utils/parse-date';
Expand Down Expand Up @@ -81,7 +80,7 @@ export const route: Route = {
},
],
name: 'Unknown',
maintainers: ['Jim Kirisame'],
maintainers: ['jim-kirisame'],
handler,
url: 'oas.gdut.edu.cn/seeyon',
};
Expand Down Expand Up @@ -115,18 +114,16 @@ async function handler(ctx) {
}

// 构造文章数组
const articles = [];
for (const item of resp.data.list) {
articles.push({
title: item.title,
guid: item.id,
link: site + '/newsData.do?method=newsView&newsId=' + item.id,
pubDate: timezone(parseDate(item.publishDate1), +8),
author: item.publishUserDepart,
category: item.typeName,
});
}
const articles = resp.data.list.map((item) => ({
title: item.title,
guid: item.id,
link: site + '/newsData.do?method=newsView&newsId=' + item.id,
pubDate: timezone(parseDate(item.publishDate1), +8),
author: item.publishUserDepart,
category: item.typeName,
}));

const results = [];
// 获取实际的文章内容
for await (const data of asyncPool(2, articles, async (data) => {
const link = data.link;
Expand Down Expand Up @@ -209,18 +206,16 @@ async function handler(ctx) {
}
});

// 防止太快被Ban
await wait(500);
return node.html();
});
})) {
data;
results.push(data);
}

return {
title: `广东工业大学新闻通知网 - ` + type.name,
link: site,
description: `广东工业大学新闻通知网`,
item: articles,
item: results,
};
}
Loading

0 comments on commit c4b585e

Please sign in to comment.