-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: worker-relay insert replacable events duplicate
- Loading branch information
Showing
15 changed files
with
272 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { NostrEvent, TaggedNostrEvent } from "@snort/system"; | ||
import { SnortContext } from "@snort/system-react"; | ||
import { useContext, useState } from "react"; | ||
|
||
import AsyncButton from "@/Components/Button/AsyncButton"; | ||
|
||
export function DebugPage() { | ||
const system = useContext(SnortContext); | ||
const [filter, setFilter] = useState(""); | ||
const [event, setEvent] = useState(""); | ||
const [results, setResult] = useState<Array<TaggedNostrEvent>>([]); | ||
|
||
async function search() { | ||
if (filter && system.cacheRelay) { | ||
const r = await system.cacheRelay.query(["REQ", "test", JSON.parse(filter)]); | ||
setResult(r.map(a => ({ ...a, relays: [] }))); | ||
} | ||
} | ||
|
||
async function insert() { | ||
if (event && system.cacheRelay) { | ||
const r = await system.cacheRelay.event(JSON.parse(event) as NostrEvent); | ||
setResult([ | ||
{ | ||
content: JSON.stringify(r), | ||
} as unknown as TaggedNostrEvent, | ||
]); | ||
} | ||
} | ||
|
||
async function removeEvents() { | ||
if (filter && system.cacheRelay) { | ||
const r = await system.cacheRelay.delete(["REQ", "delete-events", JSON.parse(filter)]); | ||
setResult(r.map(a => ({ id: a }) as TaggedNostrEvent)); | ||
} | ||
} | ||
return ( | ||
<div className="flex flex-col gap-2"> | ||
<h3>Cache Query</h3> | ||
<textarea value={filter} onChange={e => setFilter(e.target.value)} placeholder="nostr filter" /> | ||
<AsyncButton onClick={() => search()}>Query</AsyncButton> | ||
<AsyncButton onClick={() => removeEvents()} className="!bg-red-500"> | ||
Delete | ||
</AsyncButton> | ||
|
||
<h3>Manual Insert</h3> | ||
<textarea value={event} onChange={e => setEvent(e.target.value)} placeholder="nostr event" /> | ||
<AsyncButton onClick={() => insert()}>Insert</AsyncButton> | ||
<div className="p-4 overflow-hidden"> | ||
<h4>Results: {results.length}</h4> | ||
{results?.map(a => ( | ||
<pre key={a.id} className="text-mono text-xs text-pretty"> | ||
{JSON.stringify(a, undefined, 2)} | ||
</pre> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.