From 2b5291080dd6200204840af4e93f5b5017ae9352 Mon Sep 17 00:00:00 2001
From: DIYgod
Date: Tue, 12 Dec 2023 14:55:15 +0800
Subject: [PATCH] feat: rsshubAccessControl url
---
package.json | 1 +
pnpm-lock.yaml | 20 +++++++++++++++++
src/popup/RSSItem.tsx | 51 ++++++++++++++++++++++++++++---------------
src/popup/RSSList.tsx | 8 +++----
src/popup/index.tsx | 6 ++---
5 files changed, 62 insertions(+), 24 deletions(-)
diff --git a/package.json b/package.json
index 0c55ba7..dc7d7e6 100644
--- a/package.json
+++ b/package.json
@@ -18,6 +18,7 @@
"clsx": "^2.0.0",
"lodash": "^4.17.21",
"lucide-react": "^0.294.0",
+ "md5.js": "^1.3.5",
"plasmo": "0.84.0",
"psl": "^1.9.0",
"react": "18.2.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index c72184b..e1018fb 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -29,6 +29,9 @@ dependencies:
lucide-react:
specifier: ^0.294.0
version: 0.294.0(react@18.2.0)
+ md5.js:
+ specifier: ^1.3.5
+ version: 1.3.5
plasmo:
specifier: 0.84.0
version: 0.84.0(lodash@4.17.21)(postcss@8.4.32)(react-dom@18.2.0)(react@18.2.0)
@@ -4068,6 +4071,15 @@ packages:
has-symbols: 1.0.3
dev: true
+ /hash-base@3.1.0:
+ resolution: {integrity: sha512-1nmYp/rhMDiE7AYkDw+lLwlAzz0AntGIe51F3RfFfEqyQ3feY2eI/NcwC6umIQVOASPMsWJLJScWKSSvzL9IVA==}
+ engines: {node: '>=4'}
+ dependencies:
+ inherits: 2.0.4
+ readable-stream: 3.6.2
+ safe-buffer: 5.2.1
+ dev: false
+
/hasown@2.0.0:
resolution: {integrity: sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==}
engines: {node: '>= 0.4'}
@@ -4781,6 +4793,14 @@ packages:
dev: false
optional: true
+ /md5.js@1.3.5:
+ resolution: {integrity: sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==}
+ dependencies:
+ hash-base: 3.1.0
+ inherits: 2.0.4
+ safe-buffer: 5.2.1
+ dev: false
+
/mdn-data@2.0.14:
resolution: {integrity: sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==}
dev: false
diff --git a/src/popup/RSSItem.tsx b/src/popup/RSSItem.tsx
index e3a2925..4340150 100644
--- a/src/popup/RSSItem.tsx
+++ b/src/popup/RSSItem.tsx
@@ -5,8 +5,15 @@ import { defaultConfig, getConfig } from "~/lib/config"
import type { RSSData } from "~/lib/types"
import RSSHubIcon from "data-base64:~/assets/icon.png"
import { useCopyToClipboard } from 'usehooks-ts'
+import MD5 from 'md5.js';
-function RSSItem({ item }: { item: RSSData }) {
+function RSSItem({
+ item,
+ type,
+}: {
+ item: RSSData
+ type: string
+}) {
const [config, setConfig] = useState(defaultConfig)
getConfig().then(setConfig)
const [_, copy] = useCopyToClipboard()
@@ -19,28 +26,38 @@ function RSSItem({ item }: { item: RSSData }) {
}
}, [copied])
+ let url = item.url.replace('{rsshubDomain}', config.rsshubDomain);
+ if (type === 'currentPageRSS' && config.rsshubAccessControl.enabled) {
+ if (config.rsshubAccessControl.useCode) {
+ url = `${url}?code=${new MD5().update(item.path + config.rsshubAccessControl.accessKey).digest('hex')}`
+ } else {
+ url = `${url}?key=${config.rsshubAccessControl.accessKey}`
+ }
+ }
+ url = encodeURI(url);
+
return (
{item.title}
- {item.url.replace("https://", "").replace("http://", "")}
+ {url.replace("https://", "").replace("http://", "")}
{item.isDocs && (
)}
{!item.isDocs && (