mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix state strings new api
This commit is contained in:
@@ -2,13 +2,26 @@ import { useMemo } from "react"
|
|||||||
|
|
||||||
const useFeedStateString = (subplebbits) => {
|
const useFeedStateString = (subplebbits) => {
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
|
const getClientHost = (clientUrl) => {
|
||||||
|
try {
|
||||||
|
clientUrl = new URL(clientUrl).hostname || clientUrl
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
return clientUrl
|
||||||
|
}
|
||||||
const getClientUrls = (regex) => {
|
const getClientUrls = (regex) => {
|
||||||
const clientUrls = new Set()
|
const clientUrls = new Set()
|
||||||
for (const clientType in subplebbits.clients) {
|
const addClientUrl = (client, clientUrl) => client?.state?.match?.(regex) && clientUrls.add(getClientHost(clientUrl))
|
||||||
for (const clientUrl in subplebbits.clients[clientType]) {
|
for (const subplebbit of subplebbits) {
|
||||||
const client = subplebbits.clients[clientType][clientUrl]
|
for (const clientUrl in subplebbit?.clients?.ipfsGateways) {
|
||||||
if (client.state.match(regex)) {
|
addClientUrl(subplebbit.clients.ipfsGateways[clientUrl], clientUrl)
|
||||||
clientUrls.add(clientUrl)
|
}
|
||||||
|
for (const clientUrl in subplebbit?.clients?.ipfsClients) {
|
||||||
|
addClientUrl(subplebbit.clients.ipfsClients[clientUrl], clientUrl)
|
||||||
|
}
|
||||||
|
for (const chainTicker in subplebbit?.clients?.chainProviders) {
|
||||||
|
for (const clientUrl in subplebbit.clients.chainProviders[chainTicker]) {
|
||||||
|
addClientUrl(subplebbit.clients.chainProviders[chainTicker][clientUrl], clientUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,27 +8,34 @@ const useStateString = (commentOrSubplebbit) => {
|
|||||||
const clients = commentOrSubplebbit?.clients
|
const clients = commentOrSubplebbit?.clients
|
||||||
|
|
||||||
const states = {}
|
const states = {}
|
||||||
for (const clientType in clients) {
|
const addState = (state, clientUrl) => {
|
||||||
for (const clientUrl in clients[clientType]) {
|
if (!state || state === 'stopped') {
|
||||||
const state = clients[clientType][clientUrl].state
|
return
|
||||||
if (state === 'stopped') {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
if (!states[state]) {
|
if (!states[state]) {
|
||||||
states[state] = []
|
states[state] = []
|
||||||
}
|
}
|
||||||
states[state].push(clientUrl)
|
states[state].push(clientUrl)
|
||||||
}
|
}
|
||||||
|
for (const clientUrl in clients?.ipfsGateways) {
|
||||||
|
addState(clients.ipfsGateways[clientUrl]?.state, clientUrl)
|
||||||
|
}
|
||||||
|
for (const clientUrl in clients?.ipfsClients) {
|
||||||
|
addState(clients.ipfsClients[clientUrl]?.state, clientUrl)
|
||||||
|
}
|
||||||
|
for (const chainTicker in clients?.chainProviders) {
|
||||||
|
for (const clientUrl in clients.chainProviders[chainTicker]) {
|
||||||
|
addState(clients.chainProviders[chainTicker][clientUrl]?.state, clientUrl)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getClientHost = (clientUrl) => {
|
const getClientHost = (clientUrl) => {
|
||||||
try {
|
try {
|
||||||
return new URL(clientUrl).hostname || clientUrl
|
clientUrl = new URL(clientUrl).hostname || clientUrl
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {}
|
||||||
return clientUrl
|
return clientUrl
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let stateString = ''
|
let stateString = ''
|
||||||
for (const state in states) {
|
for (const state in states) {
|
||||||
|
|||||||
Reference in New Issue
Block a user