feat: use rsshub api as radar rules url
This commit is contained in:
parent
caaabc478a
commit
5a97647f90
|
|
@ -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: {
|
||||
|
|
@ -45,8 +36,6 @@ export const defaultConfig = {
|
|||
local: true,
|
||||
},
|
||||
refreshTimeout: 2 * 60 * 60,
|
||||
enableFullRemoteRules,
|
||||
remoteRulesUrl,
|
||||
}
|
||||
|
||||
export async function getConfig() {
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -42,3 +42,7 @@ export async function fetchRSSContent(url: string) {
|
|||
}
|
||||
return content
|
||||
}
|
||||
|
||||
export function getRadarRulesUrl(rsshubDomain: string) {
|
||||
return `${rsshubDomain}/api/radar/rules`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
@ -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">
|
||||
|
|
|
|||
Loading…
Reference in New Issue