MVP
This commit is contained in:
@@ -1,19 +1,47 @@
|
||||
import { nip19 } from "@nostr/tools";
|
||||
import { NEvent } from "../nostr.ts";
|
||||
import { render as renderMarkdown } from "@deno/gfm";
|
||||
|
||||
export default class Article {
|
||||
private event: NEvent;
|
||||
event: NEvent;
|
||||
|
||||
constructor(event: NEvent) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
get identifier(): string | null {
|
||||
get identifier(): string {
|
||||
const tag = this.event.tags.find((t) => t[0] === "d");
|
||||
return tag ? tag[1] : null;
|
||||
return tag ? tag[1] : "";
|
||||
}
|
||||
|
||||
get title(): string {
|
||||
const tag = this.event.tags.find((t) => t[0] === "title");
|
||||
return tag ? tag[1] : "Untitled";
|
||||
}
|
||||
|
||||
get summary(): string {
|
||||
const tag = this.event.tags.find((t) => t[0] === "summary");
|
||||
return tag ? tag[1] : "";
|
||||
}
|
||||
|
||||
get publishedAt(): number {
|
||||
const tag = this.event.tags.find((t) => t[0] === "published_at");
|
||||
return tag ? parseInt(tag[1]) : this.event.created_at;
|
||||
}
|
||||
|
||||
get updatedAt(): number {
|
||||
return this.event.created_at;
|
||||
}
|
||||
|
||||
get html(): string {
|
||||
return renderMarkdown(this.event.content);
|
||||
}
|
||||
|
||||
get naddr(): string {
|
||||
return nip19.naddrEncode({
|
||||
identifier: this.identifier,
|
||||
pubkey: this.event.pubkey,
|
||||
kind: this.event.kind,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
54
models/profile.ts
Normal file
54
models/profile.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { nip19 } from "@nostr/tools";
|
||||
import { NEvent } from "../nostr.ts";
|
||||
|
||||
export interface ProfileData {
|
||||
name: string;
|
||||
about?: string;
|
||||
picture?: string;
|
||||
nip05?: string;
|
||||
lud16?: string;
|
||||
}
|
||||
|
||||
export default class Profile {
|
||||
event: NEvent;
|
||||
private data: ProfileData;
|
||||
username?: string;
|
||||
|
||||
constructor(event: NEvent, username?: string) {
|
||||
this.event = event;
|
||||
this.data = JSON.parse(event.content);
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
get updatedAt(): number {
|
||||
return this.event.created_at;
|
||||
}
|
||||
|
||||
get name(): string {
|
||||
return this.data.name || "Anonymous";
|
||||
}
|
||||
|
||||
get about(): string {
|
||||
return this.data.about || "";
|
||||
}
|
||||
|
||||
get picture(): string | undefined {
|
||||
return this.data.picture;
|
||||
}
|
||||
|
||||
get nip05(): string | undefined {
|
||||
return this.data.nip05;
|
||||
}
|
||||
|
||||
get lud16(): string | undefined {
|
||||
return this.data.lud16;
|
||||
}
|
||||
|
||||
get pubkey(): string {
|
||||
return this.event.pubkey;
|
||||
}
|
||||
|
||||
get npub(): string {
|
||||
return nip19.npubEncode(this.pubkey);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user