Nodejs自建Kindle推送服务KPush
Nodejs自建Kindle推送服务KPush
可以定制个人专属的 Kindle 电子书推送服务,放在服务器高端口自用
项目地址:KPush
安装
首先需要安装 Node.js 环境,且版本大于 8 (当然 7 也可以,支持 async/await 就好)
npm 源
# 全局安装
$ npm i -g kpush
使用
帮助:
Usage: kpush [options]
Options:
-V, --version output the version number
-c, --config <string> set kpush custom config
-p, --port <number> set kpush server listening port
-s, --smtp <string> set stmp server of pushing mail
-u, --user <string> set user of pushing mail
-s, --pass <string> set password of pushing mail
-k, --kindle <string> set user of kindle received mail
-h, --help output usage information
所有设置都会自动保存,再次使用时无需再进行设置
运行:
$ kpush
配置设置并运行:
# 可以只设置其中几项
$ sslocal -p 7001 -s smtp.163.com -u [email protected] -s test -k [email protected]
以自定义配置运行:
# 请提供配置的绝对路径,以自定义配置运行时将忽略其他设置选项
$ sslocal -c /usr/local/ss-n/lib/local/config.json
配置格式如下,字段含义见帮助:
{
"port": "7001",
"smtp": "smtp.163.com",
"user": "[email protected]",
"pass": "test",
"kindle": "[email protected]"
}
运行后,浏览器访问 KPush 服务器监听端口即可使用,推荐移动端进行访问
mobi 源更换
这里默认用了走读派作为 mobi 电子书源,感谢一下。若更换其他 mobi 源,可自行开发,仅需要实现 model.js 中 getList 和 getUrl 方法即可,约定如下:
// KPush 自带依赖,用于发送请求以及解析页面
const request = require('superagent')
const cheerio = require('cheerio')
// 导出 model 对象
module.exports = {
/**
* 获取 mobi 电子书搜索列表
*
* @param {string} q - 查询关键词
* @return {array} - 返回 list 数组
*
* list 数组元素为 mobi 对象,包含 3 个字段,均为 string
* mobi.id - mobi 电子书唯一索引,用于查询源下载链接
* mobi.img - mobi 电子书封面图链接
* mobi.ctx - mobi 电子书简介
*/
async getList (q) {
let list = []
list.push({
id: '123',
img: 'http://test.com/test1.jpg',
ctx: '简介'
})
return list
},
/**
* 获取 mobi 电子书下载链接
*
* @param {string} i - mobi 电子书索引
* @return {string} - 返回源中 mobi 电子书下载链接
*/
async getUrl (i) {
let url = 'http://test.com/download/123'
return url
}
}
项目地址:KPush
先收藏。到时再看看
sslocal 瞩目
直接复制的 readme 过来的 忘改了…
给你一个星哈,以后我拿来商用吧,哈哈哈
这个好啊,收藏了
不错。
然而是 Node.js 写的。感觉用这个来开发的软件安装起来都很不友好,看上去要先装 npm 才行。不知道有没有一个单独的安装包?
因为写着玩的没考虑这个问题 回头我写个安装部署脚本好了
收藏先
您好!关于自建Kindle推送服务KPush使用Node.js,以下是一个基本的实现思路及示例代码。
首先,您需要了解Kindle Personal Documents Service (PDS) API,它允许您向Kindle设备发送文档。为了安全起见,您需要在亚马逊开发者账户中创建一个应用并获取相应的访问密钥。
以下是一个简单的Node.js示例,演示如何使用axios
库发送POST请求来推送文档到Kindle:
const axios = require('axios');
const fs = require('fs');
const FormData = require('form-data');
const accessKey = 'YOUR_ACCESS_KEY';
const secretKey = 'YOUR_SECRET_KEY';
const userId = 'YOUR_USER_ID'; // Kindle用户ID
const documentPath = 'path/to/your/document.mobi';
const form = new FormData();
form.append('file', fs.createReadStream(documentPath));
form.append('Action', 'SubmitDocument');
form.append('Test', 'false');
form.append('Content-Type', 'application/x-mobipocket-ebook');
form.append('Title', 'Your Document Title');
form.append('Auth', `Bearer ${generateAuthToken(accessKey, secretKey, userId)}`);
async function pushToKindle() {
try {
const response = await axios.post('https://kindle.amazon.com/kp/api/v1/content', form, {
headers: {
...form.getHeaders(),
'User-Agent': 'KPush/1.0'
}
});
console.log(response.data);
} catch (error) {
console.error(error);
}
}
// 省略generateAuthToken函数实现,该函数用于生成认证token
// 参见亚马逊Kindle Personal Documents Service文档获取完整实现
pushToKindle();
请注意,generateAuthToken
函数的具体实现需要参考亚马逊的官方文档。此外,确保您已经正确配置了所有必要的权限和依赖项。