mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-05-27 01:01:51 +08:00
feat: 新增指定格式导入
This commit is contained in:
@@ -73,6 +73,15 @@ export function getSupportedFormats(): FormatFeature[] {
|
||||
return sniffer.getSupportedFormats()
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据格式 ID 获取格式特征
|
||||
* 用于手动指定格式时跳过嗅探
|
||||
*/
|
||||
export function getFormatFeatureById(formatId: string): FormatFeature | null {
|
||||
const all = sniffer.getSupportedFormats()
|
||||
return all.find((f) => f.id === formatId) ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取格式的预处理器(如果有)
|
||||
*/
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
streamParseFile,
|
||||
detectFormat,
|
||||
detectAllFormats,
|
||||
getFormatFeatureById,
|
||||
getPreprocessor,
|
||||
needsPreprocess,
|
||||
type ParsedMeta,
|
||||
@@ -144,6 +145,16 @@ export async function streamImport(
|
||||
requestId: string,
|
||||
formatOptions?: Record<string, unknown>
|
||||
): Promise<StreamImportResult> {
|
||||
// 用户手动指定格式时,跳过自动检测直接使用指定的 Parser
|
||||
if (formatOptions?.formatId) {
|
||||
const formatId = formatOptions.formatId as string
|
||||
const feature = getFormatFeatureById(formatId)
|
||||
if (!feature) {
|
||||
return { success: false, error: 'error.unknown_format_id' }
|
||||
}
|
||||
return streamImportSingle(filePath, requestId, feature, formatOptions)
|
||||
}
|
||||
|
||||
// 检测所有匹配的格式(按优先级排序)
|
||||
const candidates = detectAllFormats(filePath)
|
||||
if (candidates.length === 0) {
|
||||
|
||||
@@ -226,7 +226,9 @@ export const chatApi = {
|
||||
/**
|
||||
* 获取支持的格式列表
|
||||
*/
|
||||
getSupportedFormats: (): Promise<Array<{ name: string; platform: string }>> => {
|
||||
getSupportedFormats: (): Promise<
|
||||
Array<{ id: string; name: string; platform: string; extensions: string[] }>
|
||||
> => {
|
||||
return ipcRenderer.invoke('chat:getSupportedFormats')
|
||||
},
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -135,7 +135,7 @@ interface ChatApi {
|
||||
) => Promise<Array<{ type: MessageType; count: number }>>
|
||||
getTimeRange: (sessionId: string) => Promise<{ start: number; end: number } | null>
|
||||
getDbDirectory: () => Promise<string | null>
|
||||
getSupportedFormats: () => Promise<Array<{ name: string; platform: string }>>
|
||||
getSupportedFormats: () => Promise<Array<{ id: string; name: string; platform: string; extensions: string[] }>>
|
||||
onImportProgress: (callback: (progress: ImportProgress) => void) => () => void
|
||||
getCatchphraseAnalysis: (sessionId: string, filter?: TimeFilter) => Promise<CatchphraseAnalysis>
|
||||
getMentionAnalysis: (sessionId: string, filter?: TimeFilter) => Promise<MentionAnalysis>
|
||||
|
||||
Reference in New Issue
Block a user