From b808cdb78fdf2e508eb3f690fba6f70ffa788835 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 8 Mar 2022 21:55:40 +0800 Subject: [PATCH] feat(route): add 35PHOTO (#9267) --- docs/en/picture.md | 26 +++++++++++++++++++++ docs/picture.md | 26 +++++++++++++++++++++ lib/v2/35photo/actual.js | 7 ++++++ lib/v2/35photo/author.js | 9 ++++++++ lib/v2/35photo/genre.js | 9 ++++++++ lib/v2/35photo/interesting.js | 7 ++++++ lib/v2/35photo/maintainer.js | 8 +++++++ lib/v2/35photo/map.js | 7 ++++++ lib/v2/35photo/new.js | 7 ++++++ lib/v2/35photo/radar.js | 43 +++++++++++++++++++++++++++++++++++ lib/v2/35photo/router.js | 8 +++++++ lib/v2/35photo/utils.js | 42 ++++++++++++++++++++++++++++++++++ 12 files changed, 199 insertions(+) create mode 100644 lib/v2/35photo/actual.js create mode 100644 lib/v2/35photo/author.js create mode 100644 lib/v2/35photo/genre.js create mode 100644 lib/v2/35photo/interesting.js create mode 100644 lib/v2/35photo/maintainer.js create mode 100644 lib/v2/35photo/map.js create mode 100644 lib/v2/35photo/new.js create mode 100644 lib/v2/35photo/radar.js create mode 100644 lib/v2/35photo/router.js create mode 100644 lib/v2/35photo/utils.js diff --git a/docs/en/picture.md b/docs/en/picture.md index ce403ab7e..651408c0a 100644 --- a/docs/en/picture.md +++ b/docs/en/picture.md @@ -38,6 +38,32 @@ pageClass: routes +## 35PHOTO + +### New photos + + + +### Featured photos + + + +### New interesting + + + +### Photos on the world map + + + +### Genre + + + +### Author + + + ## Asian to lick ### Home diff --git a/docs/picture.md b/docs/picture.md index 1c60f18a9..bcc7e0068 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -38,6 +38,32 @@ pageClass: routes +## 35PHOTO + +### New photos + + + +### Featured photos + + + +### New interesting + + + +### Photos on the world map + + + +### Genre + + + +### Author + + + ## 8KCosplay ### 最新 diff --git a/lib/v2/35photo/actual.js b/lib/v2/35photo/actual.js new file mode 100644 index 000000000..c9c132fd7 --- /dev/null +++ b/lib/v2/35photo/actual.js @@ -0,0 +1,7 @@ +const { rootUrl, ProcessItems } = require('./utils'); + +module.exports = async (ctx) => { + const currentUrl = `${rootUrl}/new/actual`; + + ctx.state.data = await ProcessItems(currentUrl); +}; diff --git a/lib/v2/35photo/author.js b/lib/v2/35photo/author.js new file mode 100644 index 000000000..10bdbaf8b --- /dev/null +++ b/lib/v2/35photo/author.js @@ -0,0 +1,9 @@ +const { rootUrl, ProcessItems } = require('./utils'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const currentUrl = `${rootUrl}/${id}`; + + ctx.state.data = await ProcessItems(currentUrl); +}; diff --git a/lib/v2/35photo/genre.js b/lib/v2/35photo/genre.js new file mode 100644 index 000000000..3ed068b86 --- /dev/null +++ b/lib/v2/35photo/genre.js @@ -0,0 +1,9 @@ +const { rootUrl, ProcessItems } = require('./utils'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const currentUrl = `${rootUrl}/genre_${id}`; + + ctx.state.data = await ProcessItems(currentUrl); +}; diff --git a/lib/v2/35photo/interesting.js b/lib/v2/35photo/interesting.js new file mode 100644 index 000000000..be4c36d6a --- /dev/null +++ b/lib/v2/35photo/interesting.js @@ -0,0 +1,7 @@ +const { rootUrl, ProcessItems } = require('./utils'); + +module.exports = async (ctx) => { + const currentUrl = `${rootUrl}/new/interesting`; + + ctx.state.data = await ProcessItems(currentUrl); +}; diff --git a/lib/v2/35photo/maintainer.js b/lib/v2/35photo/maintainer.js new file mode 100644 index 000000000..4d0902933 --- /dev/null +++ b/lib/v2/35photo/maintainer.js @@ -0,0 +1,8 @@ +module.exports = { + '/actual': ['nczitzk'], + '/author/:id': ['nczitzk'], + '/genre/:id': ['nczitzk'], + '/interesting': ['nczitzk'], + '/map': ['nczitzk'], + '/new': ['nczitzk'], +}; diff --git a/lib/v2/35photo/map.js b/lib/v2/35photo/map.js new file mode 100644 index 000000000..8e2550ec0 --- /dev/null +++ b/lib/v2/35photo/map.js @@ -0,0 +1,7 @@ +const { rootUrl, ProcessItems } = require('./utils'); + +module.exports = async (ctx) => { + const currentUrl = `${rootUrl}/new/map`; + + ctx.state.data = await ProcessItems(currentUrl); +}; diff --git a/lib/v2/35photo/new.js b/lib/v2/35photo/new.js new file mode 100644 index 000000000..ff962b546 --- /dev/null +++ b/lib/v2/35photo/new.js @@ -0,0 +1,7 @@ +const { rootUrl, ProcessItems } = require('./utils'); + +module.exports = async (ctx) => { + const currentUrl = `${rootUrl}/new`; + + ctx.state.data = await ProcessItems(currentUrl); +}; diff --git a/lib/v2/35photo/radar.js b/lib/v2/35photo/radar.js new file mode 100644 index 000000000..f3871bad0 --- /dev/null +++ b/lib/v2/35photo/radar.js @@ -0,0 +1,43 @@ +module.exports = { + '35photo.pro': { + _name: '35PHOTO', + '.': [ + { + title: 'New photos', + docs: 'https://docs.rsshub.app/picture.html#35photo-new-photos', + source: ['/new', '/'], + target: '/35photo/new', + }, + { + title: 'Featured photos', + docs: 'https://docs.rsshub.app/picture.html#35photo-featured-photos', + source: ['/new/actual', '/'], + target: '/35photo/actual', + }, + { + title: 'New interesting', + docs: 'https://docs.rsshub.app/picture.html#35photo-new-interesting', + source: ['/new/interesting', '/'], + target: '/35photo/interesting', + }, + { + title: 'Photos on the world map', + docs: 'https://docs.rsshub.app/picture.html#35photo-photos-on-the-world-map', + source: ['/new/map', '/'], + target: '/35photo/map', + }, + { + title: 'Genre', + docs: 'https://docs.rsshub.app/picture.html#35photo-genre', + source: ['/'], + target: (params, url) => `/35photo/genre/${url.match(/genre_(\d+)/)[1]}`, + }, + { + title: 'Author', + docs: 'https://docs.rsshub.app/picture.html#35photo-author', + source: ['/:id', '/'], + target: '/35photo/author/:id', + }, + ], + }, +}; diff --git a/lib/v2/35photo/router.js b/lib/v2/35photo/router.js new file mode 100644 index 000000000..0975e35a3 --- /dev/null +++ b/lib/v2/35photo/router.js @@ -0,0 +1,8 @@ +module.exports = function (router) { + router.get('/actual', require('./actual')); + router.get('/author/:id', require('./author')); + router.get('/genre/:id', require('./genre')); + router.get('/interesting', require('./interesting')); + router.get('/map', require('./map')); + router.get('/new', require('./new')); +}; diff --git a/lib/v2/35photo/utils.js b/lib/v2/35photo/utils.js new file mode 100644 index 000000000..9b53ca809 --- /dev/null +++ b/lib/v2/35photo/utils.js @@ -0,0 +1,42 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const rootUrl = 'https://35photo.pro'; + +module.exports = { + rootUrl, + ProcessItems: async (currentUrl) => { + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const items = $('.item') + .toArray() + .map((item) => { + item = $(item); + + const image = item.find('.showPrevPhoto'); + + return { + title: image.attr('title').replace(/Photographer\\'s photo - /, ''), + link: image.parent().attr('href'), + author: item.next().find('.userName').text().replace(/© /, ''), + category: image + .attr('alt') + .replace(/photo preview/g, '') + .split(/,|#/) + .map((c) => c.trim()), + description: ``, + }; + }); + + return { + title: `${$('h1').text()} - 35PHOTO`, + link: currentUrl, + item: items, + }; + }, +};