feat: implement IPC handlers, database services and Extractor UI

- Add SqlServerService and MySqlService for database persistence
- Implement IPC handlers for file, extractor, cleaner, and database operations
- Define IPC API types and update preload script
- Create ExtractorPage UI with OrderNumberInput component
- Add unit and integration tests for MySQL and SQL Server
- Update vitest config with path aliases
This commit is contained in:
Misaka
2026-03-01 15:46:01 +08:00
parent c39e1504aa
commit 5760b56f70
23 changed files with 2156 additions and 33 deletions

View File

@@ -0,0 +1,55 @@
import { ipcMain } from 'electron'
import * as fs from 'fs/promises'
import * as path from 'path'
/**
* Register IPC handlers for file operations
*/
export function registerFileHandlers(): void {
// Read file content
ipcMain.handle('file:read', async (_event, filePath: string): Promise<string> => {
try {
return await fs.readFile(filePath, 'utf-8')
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to read file'
throw new Error(message)
}
})
// Write content to file
ipcMain.handle('file:write', async (_event, filePath: string, content: string): Promise<void> => {
try {
// Ensure directory exists
const dir = path.dirname(filePath)
await fs.mkdir(dir, { recursive: true })
await fs.writeFile(filePath, content, 'utf-8')
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to write file'
throw new Error(message)
}
})
// Check if file exists
ipcMain.handle('file:exists', async (_event, filePath: string): Promise<boolean> => {
try {
await fs.access(filePath)
return true
} catch {
return false
}
})
// List files in directory
ipcMain.handle('file:list', async (_event, dirPath: string): Promise<string[]> => {
try {
const entries = await fs.readdir(dirPath, { withFileTypes: true })
return entries
.filter((entry) => entry.isFile())
.map((entry) => entry.name)
.sort()
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to list directory'
throw new Error(message)
}
})
}