Skip to content

Commit 391b6c1

Browse files
authored
fix: Prevent MD5 code errors & improve access key handling for RSSHub URLs (#1048)
* feat: Add access key support for /api/radar/rules fetching * fix: Prevent MD5 code mismatch due to trailing slashes in RSSHub URLs
1 parent cf4030d commit 391b6c1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/lib/rules.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import _ from "lodash"
22

3+
import MD5 from "md5.js"
34
import { getConfig } from "./config"
45
import { defaultRules } from "./radar-rules"
56
import type { Rules } from "./types"
@@ -40,10 +41,18 @@ export function getRemoteRules() {
4041
return new Promise<string>(async (resolve, reject) => {
4142
const config = await getConfig()
4243
try {
43-
const res = await fetch(getRadarRulesUrl(config.rsshubDomain))
44+
let url = getRadarRulesUrl(config.rsshubDomain)
45+
46+
if (config.rsshubAccessControl.accessKey) {
47+
const path = new URL(url).pathname
48+
const code = new MD5().update(path + config.rsshubAccessControl.accessKey).digest("hex")
49+
url = `${url}?code=${code}`
50+
}
51+
52+
const res = await fetch(url)
4453
resolve(res.text())
4554
} catch (error) {
4655
reject(error)
4756
}
4857
})
49-
}
58+
}

src/popup/RSSItem.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ function RSSItem({
3535
let url = item.url.replace(
3636
"{rsshubDomain}",
3737
config.rsshubDomain.replace(/\/$/, ""),
38-
)
38+
).replace(/\/$/, "")
39+
3940
if (type === "currentPageRSSHub" && config.rsshubAccessControl.accessKey) {
40-
url = `${url}?code=${new MD5().update(item.path + config.rsshubAccessControl.accessKey).digest("hex")}`
41+
url = `${url}?code=${new MD5().update(item.path.replace(/\/$/, "") + config.rsshubAccessControl.accessKey).digest("hex")}`
4142
}
4243
if (type === "currentPageRSSHub") {
4344
item.title = item.title.replace(

0 commit comments

Comments
 (0)