From 77f3e710fa8181ca9d6e91c7cb0ee8edc10e31f4 Mon Sep 17 00:00:00 2001
From: Fatpandac <1779196284@qq.com>
Date: Fri, 25 Feb 2022 00:14:13 +0800
Subject: [PATCH] fix(route): appstore refactor to V2 (#9177)
* fix(route): appstore refactor to V2
* fix(route): add radar.js
* fix: remove legacy url.resolve
---
lib/router.js | 7 ----
lib/{routes/apple => v2}/appstore/gofans.js | 6 +--
.../apple => v2}/appstore/in-app-purchase.js | 0
lib/v2/appstore/maintainer.js | 7 ++++
lib/{routes/apple => v2}/appstore/price.js | 0
lib/v2/appstore/radar.js | 41 +++++++++++++++++++
lib/v2/appstore/router.js | 7 ++++
lib/{routes/apple => v2}/appstore/update.js | 0
lib/{routes/apple => v2}/appstore/xianmian.js | 5 ++-
9 files changed, 61 insertions(+), 12 deletions(-)
rename lib/{routes/apple => v2}/appstore/gofans.js (87%)
rename lib/{routes/apple => v2}/appstore/in-app-purchase.js (100%)
create mode 100644 lib/v2/appstore/maintainer.js
rename lib/{routes/apple => v2}/appstore/price.js (100%)
create mode 100644 lib/v2/appstore/radar.js
create mode 100644 lib/v2/appstore/router.js
rename lib/{routes/apple => v2}/appstore/update.js (100%)
rename lib/{routes/apple => v2}/appstore/xianmian.js (81%)
diff --git a/lib/router.js b/lib/router.js
index d9e2c44f2..35b4dfc00 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -488,13 +488,6 @@ router.get('/nvidia/webdriverupdate', lazyloadRouteHandler('./routes/nvidia/webd
// 每日环球展览 iMuseum
router.get('/imuseum/:city/:type?', lazyloadRouteHandler('./routes/imuseum'));
-// AppStore
-router.get('/appstore/update/:country/:id', lazyloadRouteHandler('./routes/apple/appstore/update'));
-router.get('/appstore/price/:country/:type/:id', lazyloadRouteHandler('./routes/apple/appstore/price'));
-router.get('/appstore/iap/:country/:id', lazyloadRouteHandler('./routes/apple/appstore/in-app-purchase'));
-router.get('/appstore/xianmian', lazyloadRouteHandler('./routes/apple/appstore/xianmian'));
-router.get('/appstore/gofans', lazyloadRouteHandler('./routes/apple/appstore/gofans'));
-
// Hopper
router.get('/hopper/:lowestOnly/:from/:to?', lazyloadRouteHandler('./routes/hopper/index'));
diff --git a/lib/routes/apple/appstore/gofans.js b/lib/v2/appstore/gofans.js
similarity index 87%
rename from lib/routes/apple/appstore/gofans.js
rename to lib/v2/appstore/gofans.js
index 022d41171..bec61bb1d 100644
--- a/lib/routes/apple/appstore/gofans.js
+++ b/lib/v2/appstore/gofans.js
@@ -1,5 +1,5 @@
const got = require('@/utils/got');
-const url = require('url');
+const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const prefix = 'https://gofans.cn/app/';
@@ -27,8 +27,8 @@ module.exports = async (ctx) => {
${item.description}
`,
- pubDate: new Date(item.updated_at * 1000).toUTCString(),
- link: url.resolve(prefix, item.uuid),
+ pubDate: parseDate(item.updated_at * 1000),
+ link: new URL(item.uuid, prefix),
})),
};
};
diff --git a/lib/routes/apple/appstore/in-app-purchase.js b/lib/v2/appstore/in-app-purchase.js
similarity index 100%
rename from lib/routes/apple/appstore/in-app-purchase.js
rename to lib/v2/appstore/in-app-purchase.js
diff --git a/lib/v2/appstore/maintainer.js b/lib/v2/appstore/maintainer.js
new file mode 100644
index 000000000..33d8b2e2f
--- /dev/null
+++ b/lib/v2/appstore/maintainer.js
@@ -0,0 +1,7 @@
+module.exports = {
+ '/update/:country/:id': ['HenryQW'],
+ '/price/:country/:type/:id': ['HenryQW'],
+ '/iap/:country/:id': ['HenryQW'],
+ '/xianmian': ['Andiedie'],
+ '/gofans': ['HenryQW'],
+};
diff --git a/lib/routes/apple/appstore/price.js b/lib/v2/appstore/price.js
similarity index 100%
rename from lib/routes/apple/appstore/price.js
rename to lib/v2/appstore/price.js
diff --git a/lib/v2/appstore/radar.js b/lib/v2/appstore/radar.js
new file mode 100644
index 000000000..9b71ac65d
--- /dev/null
+++ b/lib/v2/appstore/radar.js
@@ -0,0 +1,41 @@
+module.exports = {
+ 'apple.com': {
+ _name: 'Apple',
+ apps: [
+ {
+ title: '应用更新',
+ docs: 'https://docs.rsshub.app/program-update.html#app-store-mac-app-store',
+ source: ['/:contry/app/:id'],
+ target: '/appstore/update/:country/:id',
+ },
+ {
+ title: '价格更新',
+ docs: 'https://docs.rsshub.app/program-update.html#app-store-mac-app-store',
+ source: ['/'],
+ target: '/appstore/price/:country/:type/:id',
+ },
+ ],
+ },
+ 'app.so': {
+ _name: '鲜面连线',
+ '.': [
+ {
+ title: '限免应用',
+ docs: 'https://docs.rsshub.app/program-update.html#app-store-mac-app-store',
+ source: ['/xianmian'],
+ target: '/appstore/xianmian',
+ },
+ ],
+ },
+ 'gofans.cn': {
+ _name: 'GoFans',
+ '.': [
+ {
+ title: '最新限免',
+ docs: 'https://docs.rsshub.app/program-update.html#app-store-mac-app-store',
+ source: ['/'],
+ target: '/appstore/gofans',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/appstore/router.js b/lib/v2/appstore/router.js
new file mode 100644
index 000000000..9575545c3
--- /dev/null
+++ b/lib/v2/appstore/router.js
@@ -0,0 +1,7 @@
+module.exports = function (router) {
+ router.get('/gofans', require('./gofans'));
+ router.get('/xianmian', require('./xianmian'));
+ router.get('/iap/:country/:id', require('./in-app-purchase'));
+ router.get('/price/:country/:type/:id', require('./price'));
+ router.get('/update/:country/:id', require('./update'));
+};
diff --git a/lib/routes/apple/appstore/update.js b/lib/v2/appstore/update.js
similarity index 100%
rename from lib/routes/apple/appstore/update.js
rename to lib/v2/appstore/update.js
diff --git a/lib/routes/apple/appstore/xianmian.js b/lib/v2/appstore/xianmian.js
similarity index 81%
rename from lib/routes/apple/appstore/xianmian.js
rename to lib/v2/appstore/xianmian.js
index 8e3d4ad9e..a34adc6bd 100644
--- a/lib/routes/apple/appstore/xianmian.js
+++ b/lib/v2/appstore/xianmian.js
@@ -1,9 +1,10 @@
const got = require('@/utils/got');
+const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const {
data: { objects: data },
- } = await got.get('http://app.so/api/v5/appso/discount/?platform=web&limit=10');
+ } = await got.get('https://app.so/api/v5/appso/discount/?platform=web&limit=10');
ctx.state.data = {
title: '每日精品限免 / 促销应用',
@@ -20,7 +21,7 @@ module.exports = async (ctx) => {
${item.content}
`,
- pubDate: new Date(item.updated_at * 1000).toUTCString(),
+ pubDate: parseDate(item.updated_at * 1000),
link: item.app.download_link[0].link,
})),
};