Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from diygod:master #818

Merged
merged 4 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": ["eslint:recommended", "plugin:prettier/recommended", "plugin:yml/recommended"],
"plugins": ["prettier"],
"parserOptions": {
"ecmaVersion": 2020,
"ecmaVersion": "latest",
"sourceType": "module"
},
"env": {
Expand Down Expand Up @@ -65,6 +65,7 @@
"no-prototype-builtins": 0,
"no-new-func": 2,
"require-await": 2,
"no-return-await": 2,
"prefer-arrow-callback": 2,
"object-shorthand": 2,
"yml/quotes": [
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pr-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
10 changes: 10 additions & 0 deletions docs/picture.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ pageClass: routes

<Route author="nczitzk" example="/35photo/author/mariuszsix" path="/35photo/author/:id" :paramsDesc="['id,可在对应作者页 URL 中找到']"/>

## 500px 摄影社区

### 部落影集

<Route author="TonyRL" example="/500px/tribe/set/f5de0b8aa6d54ec486f5e79616418001" path="/500px/tribe/set/:id" :paramsDesc="['部落 ID']" radar="1"/>

### 摄影师作品

<Route author="TonyRL" example="/500px/user/works/hujunli" path="/500px/user/works/:id" :paramsDesc="['摄影师 ID']" radar="1"/>

## 8KCosplay

### 最新
Expand Down
25 changes: 12 additions & 13 deletions lib/routes/fanxinzhui/latest.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ module.exports = async (ctx) => {
.get();

const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);

item.description = content('.middle_box').html();

return item;
})
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);

item.description = content('.middle_box').html();

return item;
})
)
);

Expand Down
23 changes: 11 additions & 12 deletions lib/routes/fashionnetwork/headline.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,20 @@ module.exports = async (ctx) => {
.get();

const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);

content('.newsTitle, .ads').remove();
content('.newsTitle, .ads').remove();

item.description = content('div[itemprop="text"]').html();
item.description = content('div[itemprop="text"]').html();

return item;
})
return item;
})
)
);

Expand Down
23 changes: 11 additions & 12 deletions lib/routes/fashionnetwork/news.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,20 @@ module.exports = async (ctx) => {
.get();

const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);

content('.newsTitle, .ads').remove();
content('.newsTitle, .ads').remove();

item.description = content('div[itemprop="text"]').html();
item.description = content('div[itemprop="text"]').html();

return item;
})
return item;
})
)
);

Expand Down
4 changes: 2 additions & 2 deletions lib/routes/ncm/djradio.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const path = require('path');
module.exports = async (ctx) => {
const id = ctx.params.id;

const ProcessFeed = async (limit, offset) =>
await got({
const ProcessFeed = (limit, offset) =>
got({
method: 'post',
url: 'https://music.163.com/api/dj/program/byradio',
headers: {
Expand Down
27 changes: 13 additions & 14 deletions lib/routes/questmobile/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,22 @@ module.exports = async (ctx) => {
}));

const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);

content('img[_ngcontent-c11]').each(function () {
content(this).attr('alt', '');
});
content('img[_ngcontent-c11]').each(function () {
content(this).attr('alt', '');
});

item.description = content('.text').html();
item.description = content('.text').html();

return item;
})
return item;
})
)
);

Expand Down
23 changes: 11 additions & 12 deletions lib/routes/rss3/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ module.exports = async (ctx) => {
.get();

const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);

item.description = content('.post-content').html();
item.pubDate = Date.parse(content('small time').attr('datetime'));
item.description = content('.post-content').html();
item.pubDate = Date.parse(content('small time').attr('datetime'));

return item;
})
return item;
})
)
);

Expand Down
4 changes: 2 additions & 2 deletions lib/utils/wechat-mp.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ const normalizeUrl = (url, bypassHostCheck = false) => {
* @param {boolean} bypassHostCheck - Whether to bypass host check.
* @return {Promise<object>} - An object containing the article and its metadata.
*/
const fetchArticle = async (ctx, url, bypassHostCheck = false) => {
const fetchArticle = (ctx, url, bypassHostCheck = false) => {
url = normalizeUrl(url, bypassHostCheck);
return await ctx.cache.tryGet(url, async () => {
return ctx.cache.tryGet(url, async () => {
const response = await got(url);
const $ = cheerio.load(response.data);

Expand Down
4 changes: 4 additions & 0 deletions lib/v2/500px/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/tribe/set/:id': ['TonyRL'],
'/user/works/:id': ['TonyRL'],
};
19 changes: 19 additions & 0 deletions lib/v2/500px/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'500px.com.cn': {
_name: '500px 摄影社区',
'.': [
{
title: '部落影集',
docs: 'https://docs.rsshub.app/picture.html#_500px-she-ying-she-qu',
source: ['/page/tribe/detail'],
target: (_, url) => `/500px/tribe/set/${url.searchParams.get('tribeId')}`,
},
{
title: '摄影师作品',
docs: 'https://docs.rsshub.app/picture.html#_500px-she-ying-she-qu',
source: ['/:id', '/community/user-details/:id', '/community/user-details/:id/*'],
target: '/500px/user/works/:id',
},
],
},
};
4 changes: 4 additions & 0 deletions lib/v2/500px/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/tribe/set/:id', require('./tribeSet'));
router.get('/user/works/:id', require('./user'));
};
6 changes: 6 additions & 0 deletions lib/v2/500px/templates/tribeSet.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{ if item.description }}<p>{{ item.description }}</p>{{ /if }}
{{ if item.photos }}
{{ each item.photos p }}
<img src="{{ p.url.baseUrl }}!p5">
{{ /each }}
{{ /if }}
3 changes: 3 additions & 0 deletions lib/v2/500px/templates/user.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ if item.url }}
<img src="{{ item.url.baseUrl }}!p5">
{{ /if }}
29 changes: 29 additions & 0 deletions lib/v2/500px/tribeSet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');

const { baseUrl, getTribeDetail, getTribeSets } = require('./utils');

module.exports = async (ctx) => {
const { id } = ctx.params;
const limit = parseInt(ctx.query.limit) || 100;

const { tribe } = await getTribeDetail(id, ctx.cache.tryGet);
const tribeSets = await getTribeSets(id, limit, ctx.cache.tryGet);

const items = tribeSets.map((item) => ({
title: item.title,
description: art(path.join(__dirname, 'templates/tribeSet.art'), { item }),
author: item.uploaderInfo.nickName,
pubDate: parseDate(item.createdTime, 'x'),
link: `${baseUrl}/community/set/${item.id}/details`,
}));

ctx.state.data = {
title: tribe.name,
description: `${tribe.watchword} - ${tribe.introduce}`,
link: `${baseUrl}/page/tribe/detail?tribeId=${id}&pagev=set`,
image: tribe.avatar.a1,
item: items,
};
};
32 changes: 32 additions & 0 deletions lib/v2/500px/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { art } = require('@/utils/render');
const { parseDate } = require('@/utils/parse-date');
const path = require('path');
const { baseUrl, getUserInfoFromUsername, getUserInfoFromId, getUserWorks } = require('./utils');

module.exports = async (ctx) => {
let { id } = ctx.params;
const limit = parseInt(ctx.query.limit) || 100;

if (id.length !== 33) {
id = (await getUserInfoFromUsername(id, ctx.cache.tryGet)).id;
}

const userInfo = await getUserInfoFromId(id, ctx.cache.tryGet);
const userWorks = await getUserWorks(id, limit, ctx.cache.tryGet);

const items = userWorks.map((item) => ({
title: item.title || '无题',
description: art(path.join(__dirname, 'templates/user.art'), { item }),
author: item.uploaderInfo.nickName,
pubDate: parseDate(item.createdTime, 'x'),
link: `${baseUrl}/community/photo-details/${item.id}`,
}));

ctx.state.data = {
title: userInfo.nickName,
description: userInfo.about,
image: userInfo.avatar.a1,
link: `${baseUrl}/${id}`,
item: items,
};
};
Loading