Skip to content

Commit

Permalink
feat: use rsshub api as radar rules url
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Mar 14, 2024
1 parent caaabc4 commit 5a97647
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 26 deletions.
11 changes: 0 additions & 11 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ import { Storage } from "@plasmohq/storage"

const storage = new Storage()

const enableFullRemoteRules = !(
navigator.userAgent.match(/firefox/i) ||
(navigator.userAgent.match(/safari/i) &&
!navigator.userAgent.match(/chrome/i))
)
const remoteRulesUrl = enableFullRemoteRules
? "https://rsshub.js.org/build/radar-rules.js"
: "https://rsshub.js.org/build/radar-rules.json"

export const defaultConfig = {
rsshubDomain: "https://rsshub.app",
rsshubAccessControl: {
Expand Down Expand Up @@ -45,8 +36,6 @@ export const defaultConfig = {
local: true,
},
refreshTimeout: 2 * 60 * 60,
enableFullRemoteRules,
remoteRulesUrl,
}

export async function getConfig() {
Expand Down
15 changes: 6 additions & 9 deletions src/lib/rules.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import _ from "lodash"

import { defaultConfig, getConfig } from "./config"
import { getConfig } from "./config"
import { defaultRules } from "./radar-rules"
import type { Rules } from "./types"
import { getRadarRulesUrl } from "./utils"

export function parseRules(rules: string, forceJSON?: boolean) {
let incomeRules = rules
if (incomeRules) {
if (typeof rules === "string") {
if (defaultConfig.enableFullRemoteRules && !forceJSON) {
incomeRules = window["lave".split("").reverse().join("")](rules)
} else {
try {
incomeRules = JSON.parse(rules)
} catch (error) {}
}
try {
incomeRules = JSON.parse(rules)
} catch (error) {}
}
}
return _.mergeWith(defaultRules, incomeRules, (objValue, srcValue) => {
Expand Down Expand Up @@ -43,7 +40,7 @@ export function getRemoteRules() {
return new Promise<string>(async (resolve, reject) => {
const config = await getConfig()
try {
const res = await fetch(config.remoteRulesUrl)
const res = await fetch(getRadarRulesUrl(config.rsshubDomain))
resolve(res.text())
} catch (error) {
reject(error)
Expand Down
4 changes: 4 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ export async function fetchRSSContent(url: string) {
}
return content
}

export function getRadarRulesUrl(rsshubDomain: string) {
return `${rsshubDomain}/api/radar/rules`
}
9 changes: 3 additions & 6 deletions src/options/routes/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { quickSubscriptions } from "~/lib/quick-subscriptions"
import report from "~/lib/report"
import { getRulesCount, parseRules } from "~/lib/rules"
import type { Rules as IRules } from "~/lib/types"
import { getRadarRulesUrl } from "~/lib/utils"

function General() {
let [config] = useStorage("config")
Expand Down Expand Up @@ -133,12 +134,8 @@ function General() {
</Label>
<Input
id="remoteRulesUrl"
value={config.remoteRulesUrl}
onChange={(e) =>
setConfig({
remoteRulesUrl: e.target.value,
})
}
disabled
value={getRadarRulesUrl(config.rsshubDomain)}
/>
</div>
<div className="grid w-full items-center gap-2">
Expand Down

0 comments on commit 5a97647

Please sign in to comment.