mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-28 04:47:42 +03:00
expose search api
This commit is contained in:
parent
3f65a3e72f
commit
41842ee356
@ -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!();
|
||||
|
@ -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,
|
||||
|
@ -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
12
src/lib/search.ts
Normal 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);
|
Loading…
Reference in New Issue
Block a user