mirror of
https://github.com/lumehq/lume.git
synced 2025-10-06 20:24:28 +02:00
clean up
This commit is contained in:
@@ -27,7 +27,6 @@
|
|||||||
"emoji-mart": "^5.5.2",
|
"emoji-mart": "^5.5.2",
|
||||||
"framer-motion": "^9.1.7",
|
"framer-motion": "^9.1.7",
|
||||||
"jotai": "^2.0.3",
|
"jotai": "^2.0.3",
|
||||||
"jotai-cache": "^0.3.0",
|
|
||||||
"next": "^13.2.4",
|
"next": "^13.2.4",
|
||||||
"nostr-relaypool": "^0.5.18",
|
"nostr-relaypool": "^0.5.18",
|
||||||
"nostr-tools": "^1.8.1",
|
"nostr-tools": "^1.8.1",
|
||||||
@@ -37,7 +36,6 @@
|
|||||||
"react-player": "^2.12.0",
|
"react-player": "^2.12.0",
|
||||||
"react-string-replace": "^1.1.0",
|
"react-string-replace": "^1.1.0",
|
||||||
"react-virtuoso": "^4.1.1",
|
"react-virtuoso": "^4.1.1",
|
||||||
"tauri-plugin-sql-api": "github:tauri-apps/tauri-plugin-sql",
|
|
||||||
"unique-names-generator": "^4.7.1",
|
"unique-names-generator": "^4.7.1",
|
||||||
"ws": "^8.13.0"
|
"ws": "^8.13.0"
|
||||||
},
|
},
|
||||||
|
24
pnpm-lock.yaml
generated
24
pnpm-lock.yaml
generated
@@ -32,7 +32,6 @@ specifiers:
|
|||||||
framer-motion: ^9.1.7
|
framer-motion: ^9.1.7
|
||||||
husky: ^8.0.3
|
husky: ^8.0.3
|
||||||
jotai: ^2.0.3
|
jotai: ^2.0.3
|
||||||
jotai-cache: ^0.3.0
|
|
||||||
lint-staged: ^13.2.0
|
lint-staged: ^13.2.0
|
||||||
next: ^13.2.4
|
next: ^13.2.4
|
||||||
nostr-relaypool: ^0.5.18
|
nostr-relaypool: ^0.5.18
|
||||||
@@ -48,7 +47,6 @@ specifiers:
|
|||||||
react-string-replace: ^1.1.0
|
react-string-replace: ^1.1.0
|
||||||
react-virtuoso: ^4.1.1
|
react-virtuoso: ^4.1.1
|
||||||
tailwindcss: ^3.3.1
|
tailwindcss: ^3.3.1
|
||||||
tauri-plugin-sql-api: github:tauri-apps/tauri-plugin-sql
|
|
||||||
typescript: ^4.9.5
|
typescript: ^4.9.5
|
||||||
unique-names-generator: ^4.7.1
|
unique-names-generator: ^4.7.1
|
||||||
ws: ^8.13.0
|
ws: ^8.13.0
|
||||||
@@ -69,7 +67,6 @@ dependencies:
|
|||||||
emoji-mart: 5.5.2
|
emoji-mart: 5.5.2
|
||||||
framer-motion: 9.1.7_biqbaboplfbrettd7655fr4n2y
|
framer-motion: 9.1.7_biqbaboplfbrettd7655fr4n2y
|
||||||
jotai: 2.0.3_react@18.2.0
|
jotai: 2.0.3_react@18.2.0
|
||||||
jotai-cache: 0.3.0_jotai@2.0.3
|
|
||||||
next: 13.2.4_biqbaboplfbrettd7655fr4n2y
|
next: 13.2.4_biqbaboplfbrettd7655fr4n2y
|
||||||
nostr-relaypool: 0.5.18_ws@8.13.0
|
nostr-relaypool: 0.5.18_ws@8.13.0
|
||||||
nostr-tools: 1.8.1
|
nostr-tools: 1.8.1
|
||||||
@@ -79,7 +76,6 @@ dependencies:
|
|||||||
react-player: 2.12.0_react@18.2.0
|
react-player: 2.12.0_react@18.2.0
|
||||||
react-string-replace: 1.1.0
|
react-string-replace: 1.1.0
|
||||||
react-virtuoso: 4.1.1_biqbaboplfbrettd7655fr4n2y
|
react-virtuoso: 4.1.1_biqbaboplfbrettd7655fr4n2y
|
||||||
tauri-plugin-sql-api: github.com/tauri-apps/tauri-plugin-sql/3a8b9a6b244df7512bc5ef8692cebdedbab3ccce
|
|
||||||
unique-names-generator: 4.7.1
|
unique-names-generator: 4.7.1
|
||||||
ws: 8.13.0
|
ws: 8.13.0
|
||||||
|
|
||||||
@@ -3231,15 +3227,6 @@ packages:
|
|||||||
hasBin: true
|
hasBin: true
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/jotai-cache/0.3.0_jotai@2.0.3:
|
|
||||||
resolution:
|
|
||||||
{ integrity: sha512-hV6DUD1frRpW0EN8Ss7n4KNaMZRBokQw6KPT3seA4P35QRXctMNUn4pHRlg3hzO+KBPpEZw+fyKlWAqagmuIwQ== }
|
|
||||||
peerDependencies:
|
|
||||||
jotai: '>=1.11.0'
|
|
||||||
dependencies:
|
|
||||||
jotai: 2.0.3_react@18.2.0
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/jotai/2.0.3_react@18.2.0:
|
/jotai/2.0.3_react@18.2.0:
|
||||||
resolution:
|
resolution:
|
||||||
{ integrity: sha512-MMjhSPAL3RoeZD9WbObufRT2quThEAEknHHridf2ma8Ml7ZVQmUiHk0ssdbR3F0h3kcwhYqSGJ59OjhPge7RRg== }
|
{ integrity: sha512-MMjhSPAL3RoeZD9WbObufRT2quThEAEknHHridf2ma8Ml7ZVQmUiHk0ssdbR3F0h3kcwhYqSGJ59OjhPge7RRg== }
|
||||||
@@ -4995,14 +4982,3 @@ packages:
|
|||||||
{ integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== }
|
{ integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== }
|
||||||
engines: { node: '>=10' }
|
engines: { node: '>=10' }
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
github.com/tauri-apps/tauri-plugin-sql/3a8b9a6b244df7512bc5ef8692cebdedbab3ccce:
|
|
||||||
resolution:
|
|
||||||
{
|
|
||||||
tarball: https://codeload.github.com/tauri-apps/tauri-plugin-sql/tar.gz/3a8b9a6b244df7512bc5ef8692cebdedbab3ccce,
|
|
||||||
}
|
|
||||||
name: tauri-plugin-sql-api
|
|
||||||
version: 0.0.0
|
|
||||||
dependencies:
|
|
||||||
'@tauri-apps/api': 1.2.0
|
|
||||||
dev: false
|
|
||||||
|
@@ -2,12 +2,11 @@ import EmojiPicker from '@components/form/emojiPicker';
|
|||||||
import ImagePicker from '@components/form/imagePicker';
|
import ImagePicker from '@components/form/imagePicker';
|
||||||
import { RelayContext } from '@components/relaysProvider';
|
import { RelayContext } from '@components/relaysProvider';
|
||||||
|
|
||||||
import { activeAccountAtom } from '@stores/account';
|
|
||||||
import { noteContentAtom } from '@stores/note';
|
import { noteContentAtom } from '@stores/note';
|
||||||
|
|
||||||
import { dateToUnix } from '@utils/getDate';
|
import { dateToUnix } from '@utils/getDate';
|
||||||
|
|
||||||
import { useAtom, useAtomValue } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
import { useResetAtom } from 'jotai/utils';
|
import { useResetAtom } from 'jotai/utils';
|
||||||
import { getEventHash, signEvent } from 'nostr-tools';
|
import { getEventHash, signEvent } from 'nostr-tools';
|
||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
@@ -15,23 +14,21 @@ import { useContext } from 'react';
|
|||||||
export default function FormBase() {
|
export default function FormBase() {
|
||||||
const [pool, relays]: any = useContext(RelayContext);
|
const [pool, relays]: any = useContext(RelayContext);
|
||||||
|
|
||||||
const activeAccount: any = useAtomValue(activeAccountAtom);
|
|
||||||
const [value, setValue] = useAtom(noteContentAtom);
|
const [value, setValue] = useAtom(noteContentAtom);
|
||||||
const resetValue = useResetAtom(noteContentAtom);
|
const resetValue = useResetAtom(noteContentAtom);
|
||||||
|
|
||||||
const pubkey = activeAccount.id;
|
|
||||||
const privkey = activeAccount.privkey;
|
|
||||||
|
|
||||||
const submitEvent = () => {
|
const submitEvent = () => {
|
||||||
|
const activeAccount = JSON.parse(localStorage.getItem('activeAccount'));
|
||||||
|
|
||||||
const event: any = {
|
const event: any = {
|
||||||
content: value,
|
content: value,
|
||||||
created_at: dateToUnix(),
|
created_at: dateToUnix(),
|
||||||
kind: 1,
|
kind: 1,
|
||||||
pubkey: pubkey,
|
pubkey: activeAccount.pubkey,
|
||||||
tags: [],
|
tags: [],
|
||||||
};
|
};
|
||||||
event.id = getEventHash(event);
|
event.id = getEventHash(event);
|
||||||
event.sig = signEvent(event, privkey);
|
event.sig = signEvent(event, activeAccount.privkey);
|
||||||
|
|
||||||
// publish note
|
// publish note
|
||||||
pool.publish(event, relays);
|
pool.publish(event, relays);
|
||||||
|
@@ -23,7 +23,7 @@ export default function FormComment({ eventID }: { eventID: any }) {
|
|||||||
content: value,
|
content: value,
|
||||||
created_at: dateToUnix(),
|
created_at: dateToUnix(),
|
||||||
kind: 1,
|
kind: 1,
|
||||||
pubkey: activeAccount.id,
|
pubkey: activeAccount.pubkey,
|
||||||
tags: [['e', eventID]],
|
tags: [['e', eventID]],
|
||||||
};
|
};
|
||||||
event.id = getEventHash(event);
|
event.id = getEventHash(event);
|
||||||
@@ -42,7 +42,7 @@ export default function FormComment({ eventID }: { eventID: any }) {
|
|||||||
<div className="relative h-11 w-11 shrink-0 overflow-hidden rounded-md border border-white/10">
|
<div className="relative h-11 w-11 shrink-0 overflow-hidden rounded-md border border-white/10">
|
||||||
<ImageWithFallback
|
<ImageWithFallback
|
||||||
src={profile?.picture}
|
src={profile?.picture}
|
||||||
alt={activeAccount.id}
|
alt={activeAccount.pubkey}
|
||||||
fill={true}
|
fill={true}
|
||||||
className="rounded-md object-cover"
|
className="rounded-md object-cover"
|
||||||
/>
|
/>
|
||||||
|
@@ -19,11 +19,11 @@ export const ActiveAccount = memo(function ActiveAccount({ user }: { user: any }
|
|||||||
const userData = JSON.parse(user.metadata);
|
const userData = JSON.parse(user.metadata);
|
||||||
|
|
||||||
const openProfilePage = () => {
|
const openProfilePage = () => {
|
||||||
router.push(`/users/${user.id}`);
|
router.push(`/users/${user.pubkey}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const copyPublicKey = async () => {
|
const copyPublicKey = async () => {
|
||||||
await writeText(nip19.npubEncode(user.id));
|
await writeText(nip19.npubEncode(user.pubkey));
|
||||||
};
|
};
|
||||||
|
|
||||||
const insertFollowsToStorage = useCallback(
|
const insertFollowsToStorage = useCallback(
|
||||||
@@ -46,7 +46,7 @@ export const ActiveAccount = memo(function ActiveAccount({ user }: { user: any }
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
kinds: [3],
|
kinds: [3],
|
||||||
authors: [user.id],
|
authors: [user.pubkey],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
relays,
|
relays,
|
||||||
@@ -65,7 +65,7 @@ export const ActiveAccount = memo(function ActiveAccount({ user }: { user: any }
|
|||||||
return () => {
|
return () => {
|
||||||
unsubscribe;
|
unsubscribe;
|
||||||
};
|
};
|
||||||
}, [insertFollowsToStorage, pool, relays, user.id]);
|
}, [insertFollowsToStorage, pool, relays, user.pubkey]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu.Root>
|
<DropdownMenu.Root>
|
||||||
|
@@ -12,13 +12,13 @@ import { useCallback, useEffect, useState } from 'react';
|
|||||||
export default function MultiAccounts() {
|
export default function MultiAccounts() {
|
||||||
const [users, setUsers] = useState([]);
|
const [users, setUsers] = useState([]);
|
||||||
|
|
||||||
const renderAccount = useCallback((user: { id: string }) => {
|
const renderAccount = useCallback((user: { pubkey: string }) => {
|
||||||
const activeAccount = JSON.parse(localStorage.getItem('activeAccount'));
|
const activeAccount = JSON.parse(localStorage.getItem('activeAccount'));
|
||||||
|
|
||||||
if (user.id === activeAccount.id) {
|
if (user.pubkey === activeAccount.pubkey) {
|
||||||
return <ActiveAccount key={user.id} user={user} />;
|
return <ActiveAccount key={user.pubkey} user={user} />;
|
||||||
} else {
|
} else {
|
||||||
return <InactiveAccount key={user.id} user={user} />;
|
return <InactiveAccount key={user.pubkey} user={user} />;
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
@@ -3,7 +3,6 @@ import { RelayContext } from '@components/relaysProvider';
|
|||||||
import { UserExtend } from '@components/user/extend';
|
import { UserExtend } from '@components/user/extend';
|
||||||
|
|
||||||
import { activeAccountAtom } from '@stores/account';
|
import { activeAccountAtom } from '@stores/account';
|
||||||
import { relaysAtom } from '@stores/relays';
|
|
||||||
|
|
||||||
import { dateToUnix } from '@utils/getDate';
|
import { dateToUnix } from '@utils/getDate';
|
||||||
|
|
||||||
@@ -33,11 +32,10 @@ export const NoteComment = memo(function NoteComment({
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [pool, relays]: any = useContext(RelayContext);
|
const [pool, relays]: any = useContext(RelayContext);
|
||||||
|
|
||||||
const activeAccount: any = useAtomValue(activeAccountAtom);
|
|
||||||
|
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [value, setValue] = useState('');
|
const [value, setValue] = useState('');
|
||||||
|
|
||||||
|
const activeAccount: any = useAtomValue(activeAccountAtom);
|
||||||
const profile = destr(activeAccount.metadata);
|
const profile = destr(activeAccount.metadata);
|
||||||
|
|
||||||
const openThread = () => {
|
const openThread = () => {
|
||||||
@@ -49,7 +47,7 @@ export const NoteComment = memo(function NoteComment({
|
|||||||
content: value,
|
content: value,
|
||||||
created_at: dateToUnix(),
|
created_at: dateToUnix(),
|
||||||
kind: 1,
|
kind: 1,
|
||||||
pubkey: activeAccount.id,
|
pubkey: activeAccount.pubkey,
|
||||||
tags: [['e', eventID]],
|
tags: [['e', eventID]],
|
||||||
};
|
};
|
||||||
event.id = getEventHash(event);
|
event.id = getEventHash(event);
|
||||||
|
@@ -38,7 +38,7 @@ export const NoteReaction = memo(function NoteReaction({
|
|||||||
['p', eventPubkey],
|
['p', eventPubkey],
|
||||||
],
|
],
|
||||||
created_at: dateToUnix(),
|
created_at: dateToUnix(),
|
||||||
pubkey: activeAccount.id,
|
pubkey: activeAccount.pubkey,
|
||||||
};
|
};
|
||||||
event.id = getEventHash(event);
|
event.id = getEventHash(event);
|
||||||
event.sig = signEvent(event, activeAccount.privkey);
|
event.sig = signEvent(event, activeAccount.privkey);
|
||||||
|
@@ -2,8 +2,6 @@ import { NoteComment } from '@components/note/meta/comment';
|
|||||||
import { NoteReaction } from '@components/note/meta/reaction';
|
import { NoteReaction } from '@components/note/meta/reaction';
|
||||||
import { RelayContext } from '@components/relaysProvider';
|
import { RelayContext } from '@components/relaysProvider';
|
||||||
|
|
||||||
import { createCacheCommentNote } from '@utils/storage';
|
|
||||||
|
|
||||||
import { useContext, useEffect, useState } from 'react';
|
import { useContext, useEffect, useState } from 'react';
|
||||||
|
|
||||||
export default function NoteMetadata({
|
export default function NoteMetadata({
|
||||||
@@ -39,7 +37,7 @@ export default function NoteMetadata({
|
|||||||
// update state
|
// update state
|
||||||
setComments((comments) => (comments += 1));
|
setComments((comments) => (comments += 1));
|
||||||
// save comment to database
|
// save comment to database
|
||||||
createCacheCommentNote(event, eventID);
|
// createCacheCommentNote(event, eventID);
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
if (event.content === '🤙' || event.content === '+') {
|
if (event.content === '🤙' || event.content === '+') {
|
||||||
|
@@ -45,7 +45,7 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
|
|||||||
parent_id: parentID,
|
parent_id: parentID,
|
||||||
parent_comment_id: '',
|
parent_comment_id: '',
|
||||||
created_at: event.created_at,
|
created_at: event.created_at,
|
||||||
account_id: activeAccount.id,
|
account_id: activeAccount.pubkey,
|
||||||
}).catch(console.error);
|
}).catch(console.error);
|
||||||
},
|
},
|
||||||
undefined,
|
undefined,
|
||||||
|
@@ -41,7 +41,7 @@ export const NoteRepost = memo(function NoteRepost({ id }: { id: string }) {
|
|||||||
parent_id: parentID,
|
parent_id: parentID,
|
||||||
parent_comment_id: '',
|
parent_comment_id: '',
|
||||||
created_at: event.created_at,
|
created_at: event.created_at,
|
||||||
account_id: activeAccount.id,
|
account_id: activeAccount.pubkey,
|
||||||
}).catch(console.error);
|
}).catch(console.error);
|
||||||
},
|
},
|
||||||
undefined,
|
undefined,
|
||||||
|
@@ -6,8 +6,6 @@ import { NoteComment } from '@components/note/comment';
|
|||||||
import { NoteExtend } from '@components/note/extend';
|
import { NoteExtend } from '@components/note/extend';
|
||||||
import { RelayContext } from '@components/relaysProvider';
|
import { RelayContext } from '@components/relaysProvider';
|
||||||
|
|
||||||
import { getAllCommentNotes, getNoteByID } from '@utils/storage';
|
|
||||||
|
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import {
|
import {
|
||||||
JSXElementConstructor,
|
JSXElementConstructor,
|
||||||
@@ -29,12 +27,12 @@ export default function Page() {
|
|||||||
const [comments, setComments] = useState([]);
|
const [comments, setComments] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getNoteByID(id)
|
/*getNoteByID(id)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
setRootEvent(res);
|
setRootEvent(res);
|
||||||
getAllCommentNotes(id).then((res: any) => setComments(res));
|
getAllCommentNotes(id).then((res: any) => setComments(res));
|
||||||
})
|
})
|
||||||
.catch(console.error);
|
.catch(console.error);*/
|
||||||
}, [id, pool, relays]);
|
}, [id, pool, relays]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@@ -1,175 +0,0 @@
|
|||||||
import { getParentID } from '@utils/transform';
|
|
||||||
|
|
||||||
import Database from 'tauri-plugin-sql-api';
|
|
||||||
|
|
||||||
let db: null | Database = null;
|
|
||||||
|
|
||||||
// connect database (sqlite)
|
|
||||||
// path: tauri::api::path::BaseDirectory::App
|
|
||||||
export async function connect(): Promise<Database> {
|
|
||||||
if (db) {
|
|
||||||
return db;
|
|
||||||
}
|
|
||||||
db = await Database.load('sqlite:lume.db');
|
|
||||||
return db;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get all relays
|
|
||||||
export async function getAllRelays() {
|
|
||||||
const db = await connect();
|
|
||||||
const result: any = await db.select('SELECT relay_url FROM relays WHERE relay_status = "1";');
|
|
||||||
return result.reduce((relays, { relay_url }) => {
|
|
||||||
relays.push(relay_url);
|
|
||||||
return relays;
|
|
||||||
}, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get active account
|
|
||||||
export async function getActiveAccount() {
|
|
||||||
const db = await connect();
|
|
||||||
const result = await db.select(`SELECT * FROM accounts LIMIT 1;`);
|
|
||||||
return result[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// get all accounts
|
|
||||||
export async function getAccounts() {
|
|
||||||
const db = await connect();
|
|
||||||
return await db.select(`SELECT * FROM accounts`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get all follows by account id
|
|
||||||
export async function getAllFollowsByID(id) {
|
|
||||||
const db = await connect();
|
|
||||||
return await db.select(`SELECT pubkey FROM follows WHERE account = "${id}";`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// create account
|
|
||||||
export async function createAccount(data) {
|
|
||||||
const db = await connect();
|
|
||||||
return await db.execute(
|
|
||||||
'INSERT OR IGNORE INTO accounts (id, privkey, npub, nsec, metadata) VALUES (?, ?, ?, ?, ?);',
|
|
||||||
[data.pubkey, data.privkey, data.npub, data.nsec, data.metadata]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// create follow
|
|
||||||
export async function createFollow(pubkey, account, kind) {
|
|
||||||
const db = await connect();
|
|
||||||
return await db.execute('INSERT OR IGNORE INTO follows (pubkey, account, kind) VALUES (?, ?, ?);', [
|
|
||||||
pubkey,
|
|
||||||
account,
|
|
||||||
kind || 0,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// create follow
|
|
||||||
export async function createFollows(data, account, kind) {
|
|
||||||
const db = await connect();
|
|
||||||
data.forEach(async (item) => {
|
|
||||||
await db.execute('INSERT OR IGNORE INTO follows (pubkey, account, kind) VALUES (?, ?, ?);', [
|
|
||||||
item,
|
|
||||||
account,
|
|
||||||
kind || 0,
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
return 'ok';
|
|
||||||
}
|
|
||||||
|
|
||||||
// create cache profile
|
|
||||||
export async function createCacheProfile(id, metadata) {
|
|
||||||
const db = await connect();
|
|
||||||
return await db.execute('INSERT OR IGNORE INTO cache_profiles (id, metadata) VALUES (?, ?);', [id, metadata]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get cache profile
|
|
||||||
export async function getCacheProfile(id) {
|
|
||||||
const db = await connect();
|
|
||||||
const result = await db.select(`SELECT metadata FROM cache_profiles WHERE id = "${id}"`);
|
|
||||||
return result[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// get all notes
|
|
||||||
export async function getNotes(time, limit, offset) {
|
|
||||||
const db = await connect();
|
|
||||||
return await db.select(
|
|
||||||
`SELECT * FROM cache_notes WHERE created_at <= "${time}" GROUP BY parent_id ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}"`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get all latest notes
|
|
||||||
export async function getLatestNotes(time) {
|
|
||||||
const db = await connect();
|
|
||||||
return await db.select(
|
|
||||||
`SELECT * FROM cache_notes WHERE created_at > "${time}" GROUP BY parent_id ORDER BY created_at DESC`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get note by id
|
|
||||||
export async function getNoteByID(id) {
|
|
||||||
const db = await connect();
|
|
||||||
const result = await db.select(`SELECT * FROM cache_notes WHERE id = "${id}"`);
|
|
||||||
return result[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// create cache note
|
|
||||||
export async function createCacheNote(data) {
|
|
||||||
const db = await connect();
|
|
||||||
return await db.execute(
|
|
||||||
'INSERT OR IGNORE INTO cache_notes (id, pubkey, created_at, kind, content, tags, parent_id) VALUES (?, ?, ?, ?, ?, ?, ?);',
|
|
||||||
[
|
|
||||||
data.id,
|
|
||||||
data.pubkey,
|
|
||||||
data.created_at,
|
|
||||||
data.kind,
|
|
||||||
data.content,
|
|
||||||
JSON.stringify(data.tags),
|
|
||||||
getParentID(data.tags, data.id),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get all comment notes
|
|
||||||
export async function getAllCommentNotes(eid) {
|
|
||||||
const db = await connect();
|
|
||||||
return await db.select(
|
|
||||||
`SELECT * FROM cache_notes WHERE parent_comment_id = "${eid}" ORDER BY created_at DESC LIMIT 500`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// create cache comment note
|
|
||||||
export async function createCacheCommentNote(data, eid) {
|
|
||||||
const db = await connect();
|
|
||||||
return await db.execute(
|
|
||||||
'INSERT OR IGNORE INTO cache_notes (id, pubkey, created_at, kind, content, tags, parent_id, parent_comment_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?);',
|
|
||||||
[
|
|
||||||
data.id,
|
|
||||||
data.pubkey,
|
|
||||||
data.created_at,
|
|
||||||
data.kind,
|
|
||||||
data.content,
|
|
||||||
JSON.stringify(data.tags),
|
|
||||||
getParentID(data.tags, data.id),
|
|
||||||
eid,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// create cache comment note
|
|
||||||
export async function countTotalNotes() {
|
|
||||||
const db = await connect();
|
|
||||||
const result = await db.select('SELECT COUNT(*) AS "total" FROM cache_notes;');
|
|
||||||
return result[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// get last login time
|
|
||||||
export async function getLastLoginTime() {
|
|
||||||
const db = await connect();
|
|
||||||
const result = await db.select('SELECT setting_value FROM settings WHERE setting_key = "last_login"');
|
|
||||||
return result[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// update last login time
|
|
||||||
export async function updateLastLoginTime(time) {
|
|
||||||
const db = await connect();
|
|
||||||
return await db.execute(`UPDATE settings SET setting_value = "${time}" WHERE setting_key = "last_login"`);
|
|
||||||
}
|
|
Reference in New Issue
Block a user