feat: move database access to rust

This commit is contained in:
PandaDEV 2024-12-11 14:29:05 +10:00
parent 4b3b6eaf21
commit a94496dbdb
No known key found for this signature in database
GPG key ID: 13EFF9BAF70EE75C
5 changed files with 687 additions and 317 deletions

47
plugins/history.ts Normal file
View file

@ -0,0 +1,47 @@
import { invoke } from "@tauri-apps/api/core";
import type { HistoryItem } from "~/types/types";
export default defineNuxtPlugin(() => {
return {
provide: {
history: {
async getHistory(): Promise<HistoryItem[]> {
return await invoke<HistoryItem[]>("get_history");
},
async addHistoryItem(item: HistoryItem): Promise<void> {
await invoke<void>("add_history_item", { item });
},
async searchHistory(query: string): Promise<HistoryItem[]> {
return await invoke<HistoryItem[]>("search_history", { query });
},
async loadHistoryChunk(
offset: number,
limit: number
): Promise<HistoryItem[]> {
return await invoke<HistoryItem[]>("load_history_chunk", {
offset,
limit,
});
},
async getImagePath(path: string): Promise<string> {
return await invoke<string>("get_image_path", { path });
},
async writeAndPaste(data: {
content: string;
contentType: string;
}): Promise<void> {
await invoke<void>("write_and_paste", data);
},
async readImage(data: { filename: string }): Promise<string> {
return await invoke<string>("read_image", data);
},
},
},
};
});