Skip to content

Commit ad302d8

Browse files
authored
fix: honor RSSHub access control for rule updates (#1180)
1 parent b15b9e1 commit ad302d8

6 files changed

Lines changed: 27 additions & 36 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
"@radix-ui/react-slot": "^1.1.2",
2929
"@radix-ui/react-switch": "^1.1.3",
3030
"async-lock": "^1.4.1",
31+
"blueimp-md5": "^2.19.0",
3132
"class-variance-authority": "^0.7.1",
3233
"clsx": "^2.1.1",
3334
"foxact": "^0.2.44",
3435
"he": "1.2.0",
3536
"lodash": "^4.17.21",
3637
"lucide-react": "^0.475.0",
37-
"md5.js": "^1.3.5",
3838
"react": "18.3.1",
3939
"react-dom": "18.3.1",
4040
"react-hot-toast": "^2.5.1",

pnpm-lock.yaml

Lines changed: 8 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/blueimp-md5.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "blueimp-md5" {
2+
export default function md5(value: string): string
3+
}

src/lib/rules.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import md5 from "blueimp-md5"
12
import _ from "lodash"
2-
import MD5 from "md5.js"
33

44
import { getConfig } from "./config"
55
import { defaultRules } from "./radar-rules"
@@ -47,12 +47,14 @@ export async function getRemoteRules() {
4747
const config = await getConfig()
4848
let url = getRadarRulesUrl(config.rsshubDomain)
4949

50-
if (config.rsshubAccessControl.accessKey) {
51-
const path = new URL(url).pathname
52-
const code = new MD5()
53-
.update(path + config.rsshubAccessControl.accessKey)
54-
.digest("hex")
55-
url = `${url}?code=${code}`
50+
if (config.rsshubAccessControl.accessKey?.trim()) {
51+
const accessKey = config.rsshubAccessControl.accessKey.trim()
52+
53+
if (config.rsshubAccessControl.accessKeyType === "key") {
54+
url = `${url}?key=${encodeURIComponent(accessKey)}`
55+
} else {
56+
url = `${url}?code=${md5(new URL(url).pathname + accessKey)}`
57+
}
5658
}
5759

5860
const res = await fetch(url)

src/lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ export async function fetchRSSContent(url: string) {
4444
}
4545

4646
export function getRadarRulesUrl(rsshubDomain: string) {
47-
return `${rsshubDomain}/api/radar/rules`
47+
return `${rsshubDomain.replace(/\/+$/, "")}/api/radar/rules`
4848
}

src/popup/RSSItem.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import MD5 from "md5.js"
1+
import md5 from "blueimp-md5"
22
import { useEffect, useState } from "react"
33
import { useCopyToClipboard } from "usehooks-ts"
44

@@ -43,10 +43,10 @@ function RSSItem({
4343
if (config.rsshubAccessControl.accessKeyType === "key") {
4444
urlObj.searchParams.append("key", config.rsshubAccessControl.accessKey)
4545
} else {
46-
const md5 = new MD5()
47-
.update(urlObj.pathname + config.rsshubAccessControl.accessKey)
48-
.digest("hex")
49-
urlObj.searchParams.append("code", md5)
46+
urlObj.searchParams.append(
47+
"code",
48+
md5(urlObj.pathname + config.rsshubAccessControl.accessKey),
49+
)
5050
}
5151

5252
url = urlObj.toString()

0 commit comments

Comments
 (0)