expose search api

This commit is contained in:
Nikita Galaiko 2023-03-06 09:32:45 +01:00
parent 3f65a3e72f
commit 41842ee356
4 changed files with 35 additions and 3 deletions

View File

@ -137,6 +137,24 @@ fn proxy_image(handle: tauri::AppHandle, src: &str) -> Result<String> {
Ok(build_asset_url(&save_to.display().to_string()))
}
#[tauri::command]
fn search(
handle: tauri::AppHandle,
project_id: &str,
query: &str,
) -> Result<Vec<search::SearchResult>, Error> {
let app_state = handle.state::<App>();
let deltas = app_state
.deltas_searcher
.lock()
.unwrap()
.search(project_id, query)
.with_context(|| format!("Failed to search for {}", query))?;
Ok(deltas)
}
#[tauri::command]
fn list_sessions(
handle: tauri::AppHandle,
@ -444,7 +462,8 @@ fn main() {
list_session_files,
set_user,
delete_user,
get_user
get_user,
search
]);
let tauri_context = generate_context!();

View File

@ -1,5 +1,6 @@
use crate::{deltas, projects, sessions, storage};
use anyhow::{Context, Result};
use serde::Serialize;
use std::{
fs,
path::{Path, PathBuf},
@ -161,7 +162,7 @@ fn build_schema() -> schema::Schema {
const WRITE_BUFFER_SIZE: usize = 10_000_000; // 10MB
#[derive(Debug)]
#[derive(Debug, Serialize)]
pub struct SearchResult {
pub project_id: String,
pub session_id: String,

View File

@ -1,6 +1,6 @@
mod deltas;
pub use deltas::Deltas;
pub use deltas::{Deltas, SearchResult};
#[cfg(test)]
mod deltas_test;

12
src/lib/search.ts Normal file
View File

@ -0,0 +1,12 @@
import { invoke } from '@tauri-apps/api';
export type SearchResult = {
project_id: string;
session_id: string;
file_id: string;
// index of the delta in the session.
index: number;
};
export const search = (params: { project_id: string; query: string }) =>
invoke<SearchResult>('search', params);