feat: rsshubAccessControl url

This commit is contained in:
DIYgod 2023-12-12 14:55:15 +08:00
parent b412f859cf
commit 2b5291080d
No known key found for this signature in database
5 changed files with 62 additions and 24 deletions

View File

@ -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",

View File

@ -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

View File

@ -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 (
<li className="flex mb-4 items-center space-x-2 w-max min-w-full">
<img className="w-8 h-8" src={item.image || RSSHubIcon} />
<a
target="_blank"
href={item.url}
href={url}
className="w-48 cursor-pointer flex flex-col justify-between text-black flex-1">
<span className="text-[13px] truncate">{item.title}</span>
<span className="text-xs truncate text-zinc-400">
{item.url.replace("https://", "").replace("http://", "")}
{url.replace("https://", "").replace("http://", "")}
</span>
</a>
{item.isDocs && (
<Button variant="rss" size="sm">
<a target="_blank" href={item.url}>
<a target="_blank" href={url}>
{chrome.i18n.getMessage("document")}
</a>
</Button>
)}
{!item.isDocs && (
<Button variant="rss" size="sm" className="w-[60px]" onClick={() => {
copy(item.url)
copy(url)
setCopied(true)
}}>
{chrome.i18n.getMessage(copied ? "copied" : "copy")}
@ -55,7 +72,7 @@ function RSSItem({ item }: { item: RSSData }) {
""
)}/index.html#/check/add?title=${encodeURI(
item.title
)}&url=${encodeURI(item.url)}&type=rss&icon=${encodeURI(
)}&url=${encodeURI(url)}&type=rss&icon=${encodeURI(
item.image
)}`}
>
@ -70,7 +87,7 @@ function RSSItem({ item }: { item: RSSData }) {
<a
target="_blank"
href={`{config.submitto.ttrssDomain.replace(/\/$/, '')}/public.php?op=bookmarklets--subscribe&feed_url=${encodeURI(
item.url
url
)}`}
>
{chrome.i18n.getMessage("subscribe to")} TTRSS
@ -86,7 +103,7 @@ function RSSItem({ item }: { item: RSSData }) {
href={`${config.submitto.minifluxDomain.replace(
/\/$/,
""
)}/bookmarklet?uri=${encodeURI(item.url)}`}
)}/bookmarklet?uri=${encodeURI(url)}`}
>
{chrome.i18n.getMessage("subscribe to")} Miniflux
</a>
@ -101,7 +118,7 @@ function RSSItem({ item }: { item: RSSData }) {
href={`${config.submitto.freshrssDomain.replace(
/\/$/,
""
)}/i/?c=feed&a=add&url_rss=${encodeURI(item.url)}`}
)}/i/?c=feed&a=add&url_rss=${encodeURI(url)}`}
>
{chrome.i18n.getMessage("subscribe to")} FreshRSS
</a>
@ -116,7 +133,7 @@ function RSSItem({ item }: { item: RSSData }) {
href={`${config.submitto.nextcloudnewsDomain.replace(
/\/$/,
""
)}/?subscribe_to=${encodeURI(item.url)}`}
)}/?subscribe_to=${encodeURI(url)}`}
>
{chrome.i18n.getMessage("subscribe to")} Nextcloud News
</a>
@ -129,7 +146,7 @@ function RSSItem({ item }: { item: RSSData }) {
<a
target="_blank"
href={`https://feedly.com/i/subscription/feed/${encodeURI(
item.url
url
)}`}
className="rss-action rss-submitto-feedly">
{chrome.i18n.getMessage("subscribe to")} Feedly
@ -145,7 +162,7 @@ function RSSItem({ item }: { item: RSSData }) {
href={`${config.submitto.inoreaderDomain.replace(
/\/$/,
""
)}/?add_feed=${encodeURI(item.url)}`}
)}/?add_feed=${encodeURI(url)}`}
>
{chrome.i18n.getMessage("subscribe to")} Inoreader
</a>
@ -160,7 +177,7 @@ function RSSItem({ item }: { item: RSSData }) {
href={`${config.submitto.feedbinDomain.replace(
/\/$/,
""
)}/?subscribe=${encodeURI(item.url)}`}
)}/?subscribe=${encodeURI(url)}`}
>
{chrome.i18n.getMessage("subscribe to")} Feedbin
</a>
@ -173,7 +190,7 @@ function RSSItem({ item }: { item: RSSData }) {
<a
target="_blank"
href={`https://theoldreader.com/feeds/subscribe?url=${encodeURI(
item.url
url
)}`}
>
{chrome.i18n.getMessage("subscribe to")} The Old Reader
@ -186,7 +203,7 @@ function RSSItem({ item }: { item: RSSData }) {
<Button variant="rss" size="sm" className="border-[#61af4b] text-[#61af4b] hover:bg-[#61af4b]">
<a
target="_blank"
href={`https://feeds.pub/feed/${encodeURIComponent(item.url)}`}
href={`https://feeds.pub/feed/${encodeURIComponent(url)}`}
>
{chrome.i18n.getMessage("subscribe to")} Feeds.Pub
</a>
@ -198,7 +215,7 @@ function RSSItem({ item }: { item: RSSData }) {
<Button variant="rss" size="sm" className="border-[#00af00] text-[#00af00] hover:bg-[#00af00]">
<a
target="_blank"
href={`https://bazqux.com/add?url=${encodeURIComponent(item.url)}`}
href={`https://bazqux.com/add?url=${encodeURIComponent(url)}`}
>
{chrome.i18n.getMessage("subscribe to")} BazQux Reader
</a>
@ -210,7 +227,7 @@ function RSSItem({ item }: { item: RSSData }) {
<Button variant="rss" size="sm">
<a
target="_blank"
href={`feed://${item.url}`}
href={`feed://${url}`}
className="rss-action rss-submitto-local">
{chrome.i18n.getMessage("subscribe to local reader")}
</a>

View File

@ -2,10 +2,10 @@ import RSSItem from './RSSItem'
import type { RSSData } from '~/lib/types'
function RSSList({
title,
type,
list,
}: {
title: string
type: string
list: RSSData[]
}) {
if (list.length === 0) {
@ -13,10 +13,10 @@ function RSSList({
}
return (
<div className="space-y-4">
<h2 className="text-base font-bold">{chrome.i18n.getMessage(title)}</h2>
<h2 className="text-base font-bold">{chrome.i18n.getMessage(type)}</h2>
<ul>
{list.map((item) => (
<RSSItem key={item.url + item.title} item={item} />
<RSSItem key={item.url + item.title} item={item} type={type} />
))}
</ul>
</div>

View File

@ -33,9 +33,9 @@ function IndexPopup() {
}}></p>
</div>
)}
<RSSList title="currentPageRSS" list={data.pageRSS} />
<RSSList title="currentPageRSSHub" list={data.pageRSSHub} />
<RSSList title="currentSiteRSSHub" list={data.websiteRSSHub} />
<RSSList type="currentPageRSS" list={data.pageRSS} />
<RSSList type="currentPageRSSHub" list={data.pageRSSHub} />
<RSSList type="currentSiteRSSHub" list={data.websiteRSSHub} />
</div>
)
}