chore: rename Dirs

This commit is contained in:
2023-01-20 11:30:04 +00:00
parent ab1efc2e2e
commit 3533f26e4e
90 changed files with 0 additions and 0 deletions

34
src/Db/User.ts Normal file
View File

@ -0,0 +1,34 @@
import { HexKey, TaggedRawEvent, UserMetadata } from "Nostr";
import { hexToBech32 } from "../Util";
export interface MetadataCache extends UserMetadata {
/**
* When the object was saved in cache
*/
loaded: number,
/**
* When the source metadata event was created
*/
created: number,
/**
* The pubkey of the owner of this metadata
*/
pubkey: HexKey
};
export function mapEventToProfile(ev: TaggedRawEvent) {
try {
let data: UserMetadata = JSON.parse(ev.content);
return {
pubkey: ev.pubkey,
npub: hexToBech32("npub", ev.pubkey),
created: ev.created_at,
loaded: new Date().getTime(),
...data
} as MetadataCache;
} catch (e) {
console.error("Failed to parse JSON", ev, e);
}
}

21
src/Db/index.ts Normal file
View File

@ -0,0 +1,21 @@
import Dexie, { Table } from "dexie";
import { MetadataCache } from "Db/User";
import { hexToBech32 } from "Util";
export class SnortDB extends Dexie {
users!: Table<MetadataCache>;
constructor() {
super('snortDB');
this.version(2).stores({
users: '++pubkey, name, display_name, picture, nip05, npub'
}).upgrade(tx => {
return tx.table("users").toCollection().modify(user => {
user.npub = hexToBech32("npub", user.pubkey)
})
});
}
}
export const db = new SnortDB();