chore: Update .gitignore and add .idea folder, update npm dependencies, and improve code logic for chat history and knowledge export/import

This commit is contained in:
n4ze3m
2024-05-11 19:32:36 +05:30
parent 677aa6ef51
commit f9f621c920
18 changed files with 448 additions and 261 deletions

View File

@@ -2,6 +2,7 @@ import {
type ChatHistory as ChatHistoryType,
type Message as MessageType
} from "~/store/option"
import { Storage, browser } from "wxt/browser"
type HistoryInfo = {
id: string
@@ -57,15 +58,18 @@ type ChatHistory = HistoryInfo[]
type Prompts = Prompt[]
export class PageAssitDatabase {
db: chrome.storage.StorageArea
db: Storage.LocalStorageArea
constructor() {
this.db = chrome.storage.local
this.db = browser.storage.local
}
async getChatHistory(id: string): Promise<MessageHistory> {
return new Promise((resolve, reject) => {
this.db.get(id, (result) => {
// this.db.get(id, (result) => {
// resolve(result[id] || [])
// })
this.db.get(id).then((result) => {
resolve(result[id] || [])
})
})
@@ -73,7 +77,10 @@ export class PageAssitDatabase {
async getChatHistories(): Promise<ChatHistory> {
return new Promise((resolve, reject) => {
this.db.get("chatHistories", (result) => {
// this.db.get("chatHistories", (result) => {
// resolve(result.chatHistories || [])
// })
this.db.get("chatHistories").then((result) => {
resolve(result.chatHistories || [])
})
})
@@ -126,7 +133,10 @@ export class PageAssitDatabase {
async getAllPrompts(): Promise<Prompts> {
return new Promise((resolve, reject) => {
this.db.get("prompts", (result) => {
// this.db.get("prompts", (result) => {
// resolve(result.prompts || [])
// })
this.db.get("prompts").then((result) => {
resolve(result.prompts || [])
})
})
@@ -169,7 +179,10 @@ export class PageAssitDatabase {
async getWebshare(id: string) {
return new Promise((resolve, reject) => {
this.db.get(id, (result) => {
// this.db.get(id, (result) => {
// resolve(result[id] || [])
// })
this.db.get(id).then((result) => {
resolve(result[id] || [])
})
})
@@ -177,7 +190,10 @@ export class PageAssitDatabase {
async getAllWebshares(): Promise<Webshare[]> {
return new Promise((resolve, reject) => {
this.db.get("webshares", (result) => {
// this.db.get("webshares", (result) => {
// resolve(result.webshares || [])
// })
this.db.get("webshares").then((result) => {
resolve(result.webshares || [])
})
})
@@ -197,7 +213,10 @@ export class PageAssitDatabase {
async getUserID() {
return new Promise((resolve, reject) => {
this.db.get("user_id", (result) => {
// this.db.get("user_id", (result) => {
// resolve(result.user_id || "")
// })
this.db.get("user_id").then((result) => {
resolve(result.user_id || "")
})
})