mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-25 17:54:34 +08:00
feat(sync): add option to delete imported chats when removing subscription
- Show confirmation dialog with two choices: keep data or delete imported chats - Backend supports deleteData param across CLI routes and Electron IPC - DataSourceManager.removeSession now returns the removed session info - Add i18n strings for the delete confirmation dialog (zh-CN/en-US/ja-JP/zh-TW)
This commit is contained in:
1 parent
31fc9be1ed
commit
7d5c541933
12 files changed
+228
-50
No files matched your search
@@ -15,6 +15,7 @@ import { registerAutomationRoutes } from './routes'
|
||||
export interface SyncRouteContext {
|
||||
dsManager: DataSourceManager
|
||||
pullEngine: PullEngine
|
||||
dbManager: DatabaseManager
|
||||
serverInfo: { port: number; host: string; token: string }
|
||||
}
|
||||
|
||||
@@ -49,7 +50,7 @@ export function initSync(
|
||||
logger: syncLogger,
|
||||
})
|
||||
|
||||
registerAutomationRoutes(server, { dsManager, pullEngine, serverInfo })
|
||||
registerAutomationRoutes(server, { dsManager, pullEngine, dbManager, serverInfo })
|
||||
|
||||
initScheduler({
|
||||
dsManager,
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
import type { SyncRouteContext } from './index'
|
||||
|
||||
export function registerAutomationRoutes(server: FastifyInstance, ctx: SyncRouteContext): void {
|
||||
const { dsManager, pullEngine, serverInfo } = ctx
|
||||
const { dsManager, pullEngine, dbManager, serverInfo } = ctx
|
||||
|
||||
// ==================== Config (read-only in CLI mode) ====================
|
||||
|
||||
@@ -85,10 +85,17 @@ export function registerAutomationRoutes(server: FastifyInstance, ctx: SyncRoute
|
||||
|
||||
server.delete<{
|
||||
Params: { id: string; sessId: string }
|
||||
Querystring: { deleteData?: string }
|
||||
}>('/_web/automation/data-sources/:id/sessions/:sessId', async (request, reply) => {
|
||||
const ok = dsManager.removeSession(request.params.id, request.params.sessId)
|
||||
if (!ok) return reply.code(404).send({ error: 'Session not found' })
|
||||
const removed = dsManager.removeSession(request.params.id, request.params.sessId)
|
||||
if (!removed) return reply.code(404).send({ error: 'Session not found' })
|
||||
reloadTimer(request.params.id)
|
||||
if (request.query.deleteData === 'true' && removed.targetSessionId) {
|
||||
dbManager.close(removed.targetSessionId)
|
||||
const dbPath = dbManager.getDbPath(removed.targetSessionId)
|
||||
const fs = await import('node:fs')
|
||||
if (fs.existsSync(dbPath)) fs.unlinkSync(dbPath)
|
||||
}
|
||||
return { success: true }
|
||||
})
|
||||
|
||||
@@ -105,6 +112,12 @@ export function registerAutomationRoutes(server: FastifyInstance, ctx: SyncRoute
|
||||
return pullEngine.triggerPullAll(request.params.id)
|
||||
})
|
||||
|
||||
// ==================== Sync Progress ====================
|
||||
|
||||
server.get('/_web/automation/sync-progress', async () => {
|
||||
return pullEngine.getProgress()
|
||||
})
|
||||
|
||||
// ==================== Remote Session Discovery ====================
|
||||
|
||||
server.get<{
|
||||
|
||||
Reference in new issue
Block a user