bug: dont add duplicate tags
This commit is contained in:
parent
445fedcb43
commit
c294f5f0bd
@ -63,14 +63,11 @@ export default class SnortApi {
|
||||
throw new Error("Publisher not set");
|
||||
}
|
||||
const auth = await this.#publisher.generic(eb => {
|
||||
eb.kind(EventKind.HttpAuthentication);
|
||||
eb.tag(["url", `${this.#url}${path}`]);
|
||||
eb.tag(["method", method ?? "GET"]);
|
||||
return eb;
|
||||
return eb
|
||||
.kind(EventKind.HttpAuthentication)
|
||||
.tag(["url", `${this.#url}${path}`])
|
||||
.tag(["method", method ?? "GET"]);
|
||||
});
|
||||
if (!auth) {
|
||||
throw new Error("Failed to create auth event");
|
||||
}
|
||||
|
||||
return this.#getJson<T>(path, method, body, {
|
||||
...headers,
|
||||
|
17
packages/app/src/System/EventBuilder.test.ts
Normal file
17
packages/app/src/System/EventBuilder.test.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { EventKind } from "@snort/nostr";
|
||||
import { EventBuilder } from "./EventBuilder";
|
||||
|
||||
const PubKey = "test-key";
|
||||
|
||||
describe("EventBuilder", () => {
|
||||
it("should not add duplicate tags", () => {
|
||||
const eb = new EventBuilder();
|
||||
eb.pubKey(PubKey);
|
||||
eb.kind(EventKind.TextNote);
|
||||
|
||||
eb.tag(["p", PubKey]);
|
||||
eb.tag(["p", PubKey]);
|
||||
const out = eb.build();
|
||||
expect(out.tags.length).toBe(1);
|
||||
});
|
||||
});
|
@ -30,7 +30,9 @@ export class EventBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
tag(t: Array<string>) {
|
||||
tag(t: Array<string>): EventBuilder {
|
||||
const duplicate = this.#tags.some(a => a.length === t.length && a.every((b, i) => b !== a[i]));
|
||||
if (duplicate) return this;
|
||||
this.#tags.push(t);
|
||||
return this;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user