mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 22:19:40 +08:00
feat(route): pixabay (#11956)
This commit is contained in:
@@ -709,6 +709,10 @@ See docs of the specified route and `lib/config.js` for detailed information.
|
||||
- `NHENTAI_USERNAME`: nhentai username or email
|
||||
- `NHENTAI_PASSWORD`: nhentai password
|
||||
|
||||
- Pixabay: [Documentation](https://pixabay.com/api/docs/)
|
||||
|
||||
- `PIXABAY_KEY`: Pixabay API key
|
||||
|
||||
- pixiv: [Registration](https://accounts.pixiv.net/signup)
|
||||
|
||||
- `PIXIV_REFRESHTOKEN`: Please refer to [this article](https://gist.github.com/ZipFile/c9ebedb224406f4f11845ab700124362) to get a `refresh_token`
|
||||
|
||||
@@ -298,6 +298,12 @@ For example:
|
||||
|
||||
<RouteEn author="MegrezZhu hoilc" example="/nhentai/search/language%3Ajapanese+-scat+-yaoi+-guro+-%22mosaic+censorship%22" path="/nhentai/search/:keyword/:mode?" :paramsDesc="['Keywords for search. You can copy the content after `q=` after searching on the original website, or you can enter it directly. See the [official website](https://nhentai.net/info/) for details', 'mode, `simple` to only cover,`detail` to all content, `torrent` to include Magnet URI, need login, refer to [Route-specific Configurations](/en/install/#route-specific-configurations), default to `simple`']" anticrawler="1" supportBT="1"/>
|
||||
|
||||
## Pixabay
|
||||
|
||||
### Search
|
||||
|
||||
<RouteEn author="TonyRL" example="/pixabay/search/cat" path="/pixabay/search/:q/:order?" :paramsDesc="['Search term', 'Order, `popular` or `latest`, `latest` by default']" radar="1" selfhost="1"/>
|
||||
|
||||
## Rare Historical Photos
|
||||
|
||||
### Home
|
||||
|
||||
@@ -222,6 +222,9 @@ const calculateValue = () => {
|
||||
pianyuan: {
|
||||
cookie: envs.PIANYUAN_COOKIE,
|
||||
},
|
||||
pixabay: {
|
||||
key: envs.PIXABAY_KEY,
|
||||
},
|
||||
pixiv: {
|
||||
refreshToken: envs.PIXIV_REFRESHTOKEN,
|
||||
bypassCdn: envs.PIXIV_BYPASS_CDN !== '0' && envs.PIXIV_BYPASS_CDN !== 'false',
|
||||
|
||||
3
lib/v2/pixabay/maintainer.js
Normal file
3
lib/v2/pixabay/maintainer.js
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/search/:q/:order?': ['TonyRL'],
|
||||
};
|
||||
13
lib/v2/pixabay/radar.js
Normal file
13
lib/v2/pixabay/radar.js
Normal file
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'pixabay.com': {
|
||||
_name: 'Pixabay',
|
||||
'.': [
|
||||
{
|
||||
title: 'Search',
|
||||
docs: 'https://docs.rsshub.app/en/picture.html#pixabay',
|
||||
source: ['/:searchType/search/:q'],
|
||||
target: '/pixabay/search/:q',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
3
lib/v2/pixabay/router.js
Normal file
3
lib/v2/pixabay/router.js
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/search/:q/:order?', require('./search'));
|
||||
};
|
||||
50
lib/v2/pixabay/search.js
Normal file
50
lib/v2/pixabay/search.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const got = require('@/utils/got');
|
||||
const config = require('@/config').value;
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { q, order = 'latest' } = ctx.params;
|
||||
const key = config.pixabay?.key ?? '7329690-bbadad6d872ba577d5a358679';
|
||||
const baseUrl = 'https://pixabay.com';
|
||||
|
||||
const data = await ctx.cache.tryGet(
|
||||
`pixabay:search:${q}:${order}`,
|
||||
async () => {
|
||||
const { data } = await got(`${baseUrl}/api/`, {
|
||||
searchParams: {
|
||||
key,
|
||||
q,
|
||||
order,
|
||||
per_page: ctx.query.limit ?? 200,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
},
|
||||
Math.max(config.cache.contentExpire, 24 * 60 * 60), // required by Pixabay API
|
||||
false
|
||||
);
|
||||
|
||||
const items = data.hits.map((item) => {
|
||||
const { pageURL, tags, user } = item;
|
||||
return {
|
||||
title: pageURL
|
||||
.substring(pageURL.lastIndexOf('/', pageURL.lastIndexOf('/') - 1) + 1, pageURL.lastIndexOf('/'))
|
||||
.replace(/(-\d+)$/, '')
|
||||
.replace(/-/g, ' '),
|
||||
description: art(path.join(__dirname, 'templates/img.art'), { item }),
|
||||
link: pageURL,
|
||||
category: tags.split(', '),
|
||||
author: user,
|
||||
};
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: `Search ${q} - Pixabay`,
|
||||
description: 'Download & use free nature stock photos in high resolution ✓ New free images everyday ✓ HD to 4K ✓ Best nature pictures for all devices on Pixabay',
|
||||
link: `${baseUrl}/images/search/${q}/${order === 'latest' ? '?order=latest' : ''}`,
|
||||
image: `https://pixabay.com/apple-touch-icon.png`,
|
||||
language: 'en',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
1
lib/v2/pixabay/templates/img.art
Normal file
1
lib/v2/pixabay/templates/img.art
Normal file
@@ -0,0 +1 @@
|
||||
<img src="{{ item.largeImageURL || item.webformatURL || item.previewURL }}">
|
||||
Reference in New Issue
Block a user