mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-10-07 18:53:52 +02:00
remove legacy local relay config
This commit is contained in:
@@ -12,7 +12,6 @@ import { logger } from "../helpers/debug";
|
|||||||
import db from "./db";
|
import db from "./db";
|
||||||
import createDefer, { Deferred } from "../classes/deferred";
|
import createDefer, { Deferred } from "../classes/deferred";
|
||||||
import { getChannelPointer } from "../helpers/nostr/channel";
|
import { getChannelPointer } from "../helpers/nostr/channel";
|
||||||
import { LOCAL_CACHE_RELAY, LOCAL_CACHE_RELAY_ENABLED } from "./local-relay";
|
|
||||||
|
|
||||||
type Pubkey = string;
|
type Pubkey = string;
|
||||||
type Relay = string;
|
type Relay = string;
|
||||||
@@ -232,9 +231,6 @@ class ChannelMetadataService {
|
|||||||
const sub = this.metadata.get(channelId);
|
const sub = this.metadata.get(channelId);
|
||||||
|
|
||||||
const relayUrls = Array.from(relays);
|
const relayUrls = Array.from(relays);
|
||||||
if (LOCAL_CACHE_RELAY_ENABLED) {
|
|
||||||
relayUrls.unshift(LOCAL_CACHE_RELAY);
|
|
||||||
}
|
|
||||||
for (const relay of relayUrls) {
|
for (const relay of relayUrls) {
|
||||||
const request = this.loaders.get(relay).requestMetadata(channelId);
|
const request = this.loaders.get(relay).requestMetadata(channelId);
|
||||||
|
|
||||||
|
@@ -4,8 +4,17 @@ import { logger } from "../helpers/debug";
|
|||||||
import _throttle from "lodash.throttle";
|
import _throttle from "lodash.throttle";
|
||||||
import { safeRelayUrl } from "../helpers/relay";
|
import { safeRelayUrl } from "../helpers/relay";
|
||||||
|
|
||||||
export const NOSTR_RELAY_TRAY_URL = "ws://localhost:4869/";
|
// save the local relay from query params to localStorage
|
||||||
|
const params = new URLSearchParams(location.search);
|
||||||
|
const paramRelay = params.get("localRelay");
|
||||||
|
// save the cache relay to localStorage
|
||||||
|
if (paramRelay) {
|
||||||
|
localStorage.setItem("localRelay", paramRelay);
|
||||||
|
params.delete("localRelay");
|
||||||
|
if (params.size === 0) location.search = params.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
export const NOSTR_RELAY_TRAY_URL = "ws://localhost:4869/";
|
||||||
export async function checkNostrRelayTray() {
|
export async function checkNostrRelayTray() {
|
||||||
return new Promise((res) => {
|
return new Promise((res) => {
|
||||||
const test = new Relay(NOSTR_RELAY_TRAY_URL);
|
const test = new Relay(NOSTR_RELAY_TRAY_URL);
|
||||||
@@ -20,48 +29,26 @@ export async function checkNostrRelayTray() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const log = logger.extend(`LocalRelay`);
|
const log = logger.extend(`LocalRelay`);
|
||||||
|
|
||||||
const params = new URLSearchParams(location.search);
|
|
||||||
const paramRelay = params.get("localRelay");
|
|
||||||
// save the cache relay to localStorage
|
|
||||||
if (paramRelay) {
|
|
||||||
localStorage.setItem("localRelay", paramRelay);
|
|
||||||
params.delete("localRelay");
|
|
||||||
if (params.size === 0) location.search = params.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
const storedCacheRelayURL = localStorage.getItem("localRelay");
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
const localRelayURL = (storedCacheRelayURL && new URL(storedCacheRelayURL)) || new URL("/local-relay", location.href);
|
|
||||||
localRelayURL.protocol = localRelayURL.protocol === "https:" ? "wss:" : "ws:";
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
export const LOCAL_CACHE_RELAY_ENABLED = !!window.CACHE_RELAY_ENABLED || !!localStorage.getItem("localRelay");
|
|
||||||
/** @deprecated */
|
|
||||||
export const LOCAL_CACHE_RELAY = localRelayURL.toString();
|
|
||||||
|
|
||||||
export const localDatabase = await openDB();
|
export const localDatabase = await openDB();
|
||||||
|
|
||||||
function createRelay() {
|
// Setup relay
|
||||||
const stored = localStorage.getItem("localRelay");
|
function createInternalRelay() {
|
||||||
if (!stored || stored.startsWith("nostr-idb://")) {
|
|
||||||
return new CacheRelay(localDatabase, { maxEvents: 10000 });
|
|
||||||
} else if (safeRelayUrl(stored)) {
|
|
||||||
return new Relay(safeRelayUrl(stored)!);
|
|
||||||
} else if (window.CACHE_RELAY_ENABLED) {
|
|
||||||
return new Relay(new URL("/local-relay", location.href).toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CacheRelay(localDatabase, { maxEvents: 10000 });
|
return new CacheRelay(localDatabase, { maxEvents: 10000 });
|
||||||
|
}
|
||||||
|
function createRelay() {
|
||||||
|
const localRelayURL = localStorage.getItem("localRelay");
|
||||||
|
|
||||||
// if (LOCAL_CACHE_RELAY_ENABLED) {
|
if (localRelayURL) {
|
||||||
// log(`Using ${LOCAL_CACHE_RELAY}`);
|
if (localRelayURL.startsWith("nostr-idb://")) {
|
||||||
// return new Relay(LOCAL_CACHE_RELAY);
|
return createInternalRelay();
|
||||||
// } else {
|
} else if (safeRelayUrl(localRelayURL)) {
|
||||||
// log(`Using IndexedDB`);
|
return new Relay(safeRelayUrl(localRelayURL)!);
|
||||||
// return new CacheRelay(localDatabase, { maxEvents: 10000 });
|
}
|
||||||
// }
|
} else if (window.CACHE_RELAY_ENABLED) {
|
||||||
|
const protocol = location.protocol === "https:" ? "wss:" : "ws:";
|
||||||
|
return new Relay(new URL(protocol + location.host + "/local-relay").toString());
|
||||||
|
}
|
||||||
|
return createInternalRelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function connectRelay() {
|
async function connectRelay() {
|
||||||
@@ -72,7 +59,7 @@ async function connectRelay() {
|
|||||||
return relay;
|
return relay;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("Failed to connect to local relay, falling back to internal");
|
log("Failed to connect to local relay, falling back to internal");
|
||||||
return new CacheRelay(localDatabase, { maxEvents: 10000 });
|
return createInternalRelay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
src/views/relays/cache/index.tsx
vendored
25
src/views/relays/cache/index.tsx
vendored
@@ -69,6 +69,30 @@ function NostrRelayTray() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function HostedRelay() {
|
||||||
|
const enabled = localRelay.url.includes(location.host + "/local-relay");
|
||||||
|
const enable = () => {
|
||||||
|
localStorage.removeItem("localRelay");
|
||||||
|
location.reload();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card borderColor={enabled ? "primary.500" : undefined} variant="outline">
|
||||||
|
<CardHeader p="4" display="flex" gap="2" alignItems="center">
|
||||||
|
<Heading size="md">Hosted Relay</Heading>
|
||||||
|
<Button size="sm" colorScheme="primary" ml="auto" onClick={enable} isDisabled={enabled}>
|
||||||
|
{enabled ? "Enabled" : "Enable"}
|
||||||
|
</Button>
|
||||||
|
</CardHeader>
|
||||||
|
<CardBody p="4" pt="0">
|
||||||
|
<Text mb="2">Your installation of noStrudel is setup with a local relay that can be used as a cache</Text>
|
||||||
|
<Text>Maximum capacity: Unknown</Text>
|
||||||
|
<Text>Performance: Unknown, but probably fast...</Text>
|
||||||
|
</CardBody>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default function CacheRelayView() {
|
export default function CacheRelayView() {
|
||||||
return (
|
return (
|
||||||
<Flex gap="2" direction="column" flex={1}>
|
<Flex gap="2" direction="column" flex={1}>
|
||||||
@@ -78,6 +102,7 @@ export default function CacheRelayView() {
|
|||||||
</Flex>
|
</Flex>
|
||||||
<InternalRelay />
|
<InternalRelay />
|
||||||
<NostrRelayTray />
|
<NostrRelayTray />
|
||||||
|
{window.CACHE_RELAY_ENABLED && <HostedRelay />}
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user