mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-16 02:42:57 +08:00
feat: add miui update (#318)
This commit is contained in:
@@ -161,6 +161,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
|
||||
- 杭州市
|
||||
- 萧山区
|
||||
- 大连市
|
||||
- MIUI
|
||||
- 更新
|
||||
|
||||
## 鸣谢
|
||||
|
||||
|
||||
@@ -1317,3 +1317,23 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到
|
||||
路由: `/tingshuitz/dalian`
|
||||
|
||||
参数: 无
|
||||
|
||||
### MIUI 更新
|
||||
|
||||
举例: [https://rsshub.app/miui/aries/](https://rsshub.app/miui/aries/)
|
||||
|
||||
路由: `/miui/:device/:type?`
|
||||
|
||||
参数
|
||||
|
||||
**device**
|
||||
|
||||
你的设备的 `codename` 例如 小米 2s 为 `aries`
|
||||
|
||||
**type**
|
||||
|
||||
可选参数
|
||||
|
||||
| 稳定版 | 开发版 |
|
||||
| ------- | ------ |
|
||||
| release | dev |
|
||||
|
||||
@@ -314,4 +314,7 @@ router.get('/tingshuitz/hangzhou', require('./routes/tingshuitz/hangzhou'));
|
||||
router.get('/tingshuitz/xiaoshan', require('./routes/tingshuitz/xiaoshan'));
|
||||
router.get('/tingshuitz/dalian', require('./routes/tingshuitz/dalian'));
|
||||
|
||||
// MIUI 更新
|
||||
router.get('/miui/:device/:type?', require('./routes/miui/index'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
58
routes/miui/index.js
Normal file
58
routes/miui/index.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const axios = require('../../utils/axios');
|
||||
const config = require('../../config');
|
||||
|
||||
const cacheLength = 5;
|
||||
const cacheDays = 30;
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { type = 'release', device } = ctx.params;
|
||||
const releaseType = type === 'release' ? 'F' : 'X';
|
||||
const localeTypeName = type === 'release' ? '稳定版' : '开发版';
|
||||
const cacheName = `RSSHubMIUIUpdate|${device}|${releaseType}`;
|
||||
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
baseURL: 'http://update.miui.com',
|
||||
url: '/updates/miota-fullrom.php',
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
},
|
||||
params: {
|
||||
d: device,
|
||||
b: releaseType,
|
||||
r: 'cn',
|
||||
l: 'zh_CN',
|
||||
n: '',
|
||||
},
|
||||
});
|
||||
|
||||
const responseData = response.data;
|
||||
let oldPosts = [];
|
||||
try {
|
||||
oldPosts = JSON.parse(await ctx.cache.get(cacheName));
|
||||
} catch (_e) {
|
||||
/** no need handle here: parseError */
|
||||
}
|
||||
|
||||
let item = oldPosts;
|
||||
|
||||
if (oldPosts.length === 0 || oldPosts[0].description !== responseData.LatestFullRom.filename) {
|
||||
item = [
|
||||
{
|
||||
title: `${device} 有新的 ${localeTypeName}本: ${responseData.LatestFullRom.version}`,
|
||||
guid: responseData.LatestFullRom.md5,
|
||||
description: responseData.LatestFullRom.filename,
|
||||
link: responseData.LatestFullRom.descriptionUrl,
|
||||
},
|
||||
...oldPosts,
|
||||
];
|
||||
|
||||
await ctx.cache.set(cacheName, item.slice(0, cacheLength), cacheDays * 24 * 60 * 60);
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: `MIUI 更新 - ${device} - ${type === 'release' ? '稳定版' : '开发版'}`,
|
||||
link: 'http://www.miui.com/download.html',
|
||||
item,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user