Skip to content

Commit

Permalink
feat(route): kindle software updates (DIYgod#12041)
Browse files Browse the repository at this point in the history
* feat(route): kindle software updates

* Update lib/v2/kindle/radar.js

* Update lib/v2/kindle/radar.js

* fix: kindle route config

* chore(route): change path to amazon

* fix: typo

---------
  • Loading branch information
EthanWng97 authored Mar 6, 2023
1 parent dae0b25 commit 75901af
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/en/program-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ pageClass: routes

# Application Updates

## Amazon

### Kindle Software Updates

<RouteEn author="NavePnow" example="/amazon/kindle/software-updates" path="/amazon/kindle/software-updates" radar="1"/>

## Android

### SDK Platform Tools release notes
Expand Down
6 changes: 6 additions & 0 deletions docs/program-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ pageClass: routes

# 程序更新

## Amazon

### Kindle 软件更新

<Route author="NavePnow" example="/amazon/kindle/software-updates" path="/amazon/kindle/software-updates" radar="1"/>

## AMD

### 显卡驱动更新
Expand Down
47 changes: 47 additions & 0 deletions lib/v2/amazon/kindle-software-updates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const cheerio = require('cheerio');
const host = 'https://www.amazon.com';
module.exports = async (ctx) => {
const url = host + '/gp/help/customer/display.html';
const nodeIdValue = 'GKMQC26VQQMM8XSW';
const response = await got({
method: 'get',
url,
searchParams: {
nodeId: nodeIdValue,
},
});
const data = response.data;

const $ = cheerio.load(data);
const list = $('.a-row.cs-help-landing-section.help-display-cond')
.map(function () {
const data = {};
data.title = $(this).find('.sectiontitle').text();
data.link = $(this).find('a').eq(0).attr('href');
data.version = $(this).find('li').first().text();
data.website = `${url}?nodeId=${nodeIdValue}`;
data.description = $(this)
.find('.a-column.a-span8')
.html()
.replace(/[\n\t]/g, '');
return data;
})
.get();
ctx.state.data = {
title: 'Kindle E-Reader Software Updates',
link: `${url}?nodeId=${nodeIdValue}`,
description: 'Kindle E-Reader Software Updates',
item: list.map((item) => ({
title: item.title + ' - ' + item.version,
description:
item.description +
art(path.join(__dirname, 'templates/software-description.art'), {
item,
}),
link: item.link,
})),
};
};
3 changes: 3 additions & 0 deletions lib/v2/amazon/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/kindle/software-updates': ['NavePnow'],
};
18 changes: 18 additions & 0 deletions lib/v2/amazon/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
'amazon.com': {
_name: 'Amazon',
'.': [
{
title: 'Kindle 软件更新',
docs: 'https://docs.rsshub.app/program-update.html#amazon',
source: ['/gp/help/customer/display.html'],
target: (_, url) => {
const nodeId = new URL(url).searchParams.get('nodeId');
if (nodeId === 'GKMQC26VQQMM8XSW') {
return '/amazon/kindle/software-updates';
}
},
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/amazon/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/kindle/software-updates', require('./kindle-software-updates'));
};
4 changes: 4 additions & 0 deletions lib/v2/amazon/templates/software-description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>
<br><br>
<a href={{item.website}}>Kindle Website</a>
</div>

0 comments on commit 75901af

Please sign in to comment.