diff options
Diffstat (limited to 'front/src/logic')
-rw-r--r-- | front/src/logic/api.ts | 2 | ||||
-rw-r--r-- | front/src/logic/nostrill.ts | 21 | ||||
-rw-r--r-- | front/src/logic/requests/nostrill.ts | 16 |
3 files changed, 31 insertions, 8 deletions
diff --git a/front/src/logic/api.ts b/front/src/logic/api.ts index cf44073..148d255 100644 --- a/front/src/logic/api.ts +++ b/front/src/logic/api.ts @@ -1,6 +1,6 @@ import Urbit from "urbit-api"; -export const URL = import.meta.env.PROD ? "" : "http://localhost:8083"; +export const URL = import.meta.env.PROD ? "" : "http://localhost:8081"; export async function start(): Promise<Urbit> { const airlock = new Urbit(URL, ""); diff --git a/front/src/logic/nostrill.ts b/front/src/logic/nostrill.ts index bf9212d..bd5fc9c 100644 --- a/front/src/logic/nostrill.ts +++ b/front/src/logic/nostrill.ts @@ -1,6 +1,9 @@ import type { Event } from "@/types/nostr"; import type { Content, FC, Poast } from "@/types/trill"; import { engagementBunt, openLock } from "./bunts"; +import type { UserType } from "@/types/nostrill"; +import type { Result } from "@/types/ui"; +import { isValidPatp } from "urbit-ob"; export function eventsToFc(postEvents: Event[]): FC { const fc = postEvents.reduce( (acc: FC, event: Event) => { @@ -66,6 +69,24 @@ export function eventToPoast(event: Event): Poast | null { return poast; } +export function userToString(user: UserType): Result<string> { + if ("urbit" in user) { + const isValid = isValidPatp(user.urbit); + if (isValid) return { ok: user.urbit }; + else return { error: "invalid @p" }; + } else if ("nostr" in user) return { ok: user.nostr }; + else return { error: "unknown user" }; +} +export function isValidNostrPubkey(pubkey: string): boolean { + // TODO + if (pubkey.length !== 64) return false; + try { + BigInt("0x" + pubkey); + return true; + } catch (_e) { + return false; + } +} // NOTE common tags: // imeta // client diff --git a/front/src/logic/requests/nostrill.ts b/front/src/logic/requests/nostrill.ts index 74fcb87..4147e35 100644 --- a/front/src/logic/requests/nostrill.ts +++ b/front/src/logic/requests/nostrill.ts @@ -2,7 +2,7 @@ import type Urbit from "urbit-api"; import type { Cursor, FC, PostID } from "@/types/trill"; import type { Ship } from "@/types/urbit"; import { FeedPostCount } from "../constants"; -import type { UserProfile } from "@/types/nostrill"; +import type { UserProfile, UserType } from "@/types/nostrill"; import type { AsyncRes } from "@/types/ui"; // Subscribe @@ -121,13 +121,13 @@ export default class IO { } // follows - async follow(ship: Ship) { - const json = { add: ship }; + async follow(user: UserType) { + const json = { add: user }; return this.poke({ fols: json }); } - async unfollow(ship: Ship) { - const json = { del: ship }; + async unfollow(user: UserType) { + const json = { del: user }; return await this.poke({ fols: json }); } // profiles @@ -162,7 +162,9 @@ export default class IO { } // threads // - async peekFeed(host: string): AsyncRes<FC> { + async peekFeed( + host: string, + ): AsyncRes<{ feed: FC; profile: UserProfile | null }> { try { const json = { begs: { feed: host } }; const res: any = await this.thread("beg", json); @@ -170,7 +172,7 @@ export default class IO { if (!("begs" in res)) return { error: "wrong request" }; if ("ng" in res.begs) return { error: res.begs.ng }; if (!("feed" in res.begs.ok)) return { error: "wrong request" }; - else return { ok: res.begs.ok.feed }; + else return { ok: res.begs.ok }; } catch (e) { return { error: `${e}` }; } |