feat: database indexing support (#14181)

This commit is contained in:
DarkSky
2025-12-30 05:23:09 +08:00
committed by GitHub
parent 95a5e941e7
commit ff2e96d847
7 changed files with 339 additions and 194 deletions

View File

@@ -50,6 +50,16 @@ export interface NativeMarkdownResult {
markdown: string
}
export interface NativePageDocContent {
title: string
summary: string
}
export interface NativeWorkspaceDocContent {
name: string
avatarKey: string
}
export interface ParsedDoc {
name: string
chunks: Array<Chunk>
@@ -61,6 +71,10 @@ export declare function parseDocFromBinary(docBin: Buffer, docId: string): Nativ
export declare function parseDocToMarkdown(docBin: Buffer, docId: string, aiEditable?: boolean | undefined | null, docUrlPrefix?: string | undefined | null): NativeMarkdownResult
export declare function parsePageDoc(docBin: Buffer, maxSummaryLength?: number | undefined | null): NativePageDocContent | null
export declare function parseWorkspaceDoc(docBin: Buffer): NativeWorkspaceDocContent | null
export declare function readAllDocIdsFromRootDoc(docBin: Buffer, includeTrash?: boolean | undefined | null): Array<string>
export declare function verifyChallengeResponse(response: string, bits: number, resource: string): Promise<boolean>

View File

@@ -1,4 +1,6 @@
use affine_common::doc_parser::{self, BlockInfo, CrawlResult, MarkdownResult};
use affine_common::doc_parser::{
self, BlockInfo, CrawlResult, MarkdownResult, PageDocContent, WorkspaceDocContent,
};
use napi::bindgen_prelude::*;
use napi_derive::napi;
@@ -17,6 +19,36 @@ impl From<MarkdownResult> for NativeMarkdownResult {
}
}
#[napi(object)]
pub struct NativePageDocContent {
pub title: String,
pub summary: String,
}
impl From<PageDocContent> for NativePageDocContent {
fn from(result: PageDocContent) -> Self {
Self {
title: result.title,
summary: result.summary,
}
}
}
#[napi(object)]
pub struct NativeWorkspaceDocContent {
pub name: String,
pub avatar_key: String,
}
impl From<WorkspaceDocContent> for NativeWorkspaceDocContent {
fn from(result: WorkspaceDocContent) -> Self {
Self {
name: result.name,
avatar_key: result.avatar_key,
}
}
}
#[napi(object)]
pub struct NativeBlockInfo {
pub block_id: String,
@@ -70,6 +102,23 @@ pub fn parse_doc_from_binary(doc_bin: Buffer, doc_id: String) -> Result<NativeCr
Ok(result.into())
}
#[napi]
pub fn parse_page_doc(
doc_bin: Buffer,
max_summary_length: Option<i32>,
) -> Result<Option<NativePageDocContent>> {
let result = doc_parser::parse_page_doc(doc_bin.into(), max_summary_length.map(|v| v as isize))
.map_err(|e| Error::new(Status::GenericFailure, e.to_string()))?;
Ok(result.map(Into::into))
}
#[napi]
pub fn parse_workspace_doc(doc_bin: Buffer) -> Result<Option<NativeWorkspaceDocContent>> {
let result = doc_parser::parse_workspace_doc(doc_bin.into())
.map_err(|e| Error::new(Status::GenericFailure, e.to_string()))?;
Ok(result.map(Into::into))
}
#[napi]
pub fn parse_doc_to_markdown(
doc_bin: Buffer,