mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-07 08:27:13 +08:00
save boss info(except encryptCompanyId) when it not exist when find some boss in chat list
This commit is contained in:
@@ -28,6 +28,7 @@ import { ChatStartupFrom } from '@geekgeekrun/sqlite-plugin/dist/entity/ChatStar
|
|||||||
import gtag from '../../utils/gtag'
|
import gtag from '../../utils/gtag'
|
||||||
import attachListenerForKillSelfOnParentExited from '../../utils/attachListenerForKillSelfOnParentExited'
|
import attachListenerForKillSelfOnParentExited from '../../utils/attachListenerForKillSelfOnParentExited'
|
||||||
import { type ChatMessageRecord } from '@geekgeekrun/sqlite-plugin/src/entity/ChatMessageRecord'
|
import { type ChatMessageRecord } from '@geekgeekrun/sqlite-plugin/src/entity/ChatMessageRecord'
|
||||||
|
import { BossInfo } from '@geekgeekrun/sqlite-plugin/dist/entity/BossInfo'
|
||||||
|
|
||||||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
|
||||||
const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE)
|
const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE)
|
||||||
@@ -180,9 +181,25 @@ const attachRequestsListener = async (target: Target) => {
|
|||||||
const url = new URL(request)
|
const url = new URL(request)
|
||||||
const encryptBossIdInAddFriendUrl = url.searchParams.get('bossId')
|
const encryptBossIdInAddFriendUrl = url.searchParams.get('bossId')
|
||||||
|
|
||||||
const bossInfo = await page.evaluate(
|
const bossInfo: any = await page.evaluate(
|
||||||
'document.querySelector(".chat-conversation").__vue__.bossInfo$'
|
'document.querySelector(".chat-conversation").__vue__.bossInfo$'
|
||||||
)
|
)
|
||||||
|
const ds = await dbInitPromise
|
||||||
|
// save boss info
|
||||||
|
const bossInfoRepository = ds.getRepository(BossInfo)
|
||||||
|
let targetBossInfo = await bossInfoRepository.findOneBy({
|
||||||
|
encryptBossId: bossInfo.encryptBossId
|
||||||
|
})
|
||||||
|
if (!targetBossInfo) {
|
||||||
|
targetBossInfo = new BossInfo()
|
||||||
|
Object.assign(targetBossInfo, {
|
||||||
|
encryptBossId: bossInfo.encryptBossId,
|
||||||
|
name: bossInfo.name,
|
||||||
|
title: bossInfo.title,
|
||||||
|
date: new Date()
|
||||||
|
})
|
||||||
|
await bossInfoRepository.save(targetBossInfo)
|
||||||
|
}
|
||||||
if (encryptBossIdInAddFriendUrl !== bossInfo.encryptBossId) {
|
if (encryptBossIdInAddFriendUrl !== bossInfo.encryptBossId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -210,7 +227,7 @@ const attachRequestsListener = async (target: Target) => {
|
|||||||
|
|
||||||
return mappedItem
|
return mappedItem
|
||||||
})
|
})
|
||||||
await saveChatMessageRecord(await dbInitPromise, chatRecordList)
|
await saveChatMessageRecord(ds, chatRecordList)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { saveChatMessageRecord } from '@geekgeekrun/sqlite-plugin/dist/handlers'
|
|||||||
import { writeStorageFile } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
import { writeStorageFile } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import { pipeWriteRegardlessError } from '../utils/pipe'
|
import { pipeWriteRegardlessError } from '../utils/pipe'
|
||||||
|
import { BossInfo } from '@geekgeekrun/sqlite-plugin/dist/entity/BossInfo'
|
||||||
|
|
||||||
const dbInitPromise = initDb(getPublicDbFilePath())
|
const dbInitPromise = initDb(getPublicDbFilePath())
|
||||||
|
|
||||||
@@ -26,6 +27,24 @@ async function saveCurrentChatRecord(page) {
|
|||||||
const bossInfo = await page.evaluate(
|
const bossInfo = await page.evaluate(
|
||||||
'document.querySelector(".chat-conversation").__vue__.bossInfo$'
|
'document.querySelector(".chat-conversation").__vue__.bossInfo$'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const ds = await dbInitPromise
|
||||||
|
// save boss info
|
||||||
|
const bossInfoRepository = ds.getRepository(BossInfo)
|
||||||
|
let targetBossInfo = await bossInfoRepository.findOneBy({
|
||||||
|
encryptBossId: bossInfo.encryptBossId
|
||||||
|
})
|
||||||
|
if (!targetBossInfo) {
|
||||||
|
targetBossInfo = new BossInfo()
|
||||||
|
Object.assign(targetBossInfo, {
|
||||||
|
encryptBossId: bossInfo.encryptBossId,
|
||||||
|
name: bossInfo.name,
|
||||||
|
title: bossInfo.title,
|
||||||
|
date: new Date()
|
||||||
|
})
|
||||||
|
await bossInfoRepository.save(targetBossInfo)
|
||||||
|
}
|
||||||
|
|
||||||
const rawChatRecordList =
|
const rawChatRecordList =
|
||||||
(
|
(
|
||||||
await page.evaluate(
|
await page.evaluate(
|
||||||
@@ -60,7 +79,7 @@ async function saveCurrentChatRecord(page) {
|
|||||||
return mappedItem
|
return mappedItem
|
||||||
})
|
})
|
||||||
|
|
||||||
await saveChatMessageRecord(await dbInitPromise, chatRecordList)
|
await saveChatMessageRecord(ds, chatRecordList)
|
||||||
}
|
}
|
||||||
|
|
||||||
let browser: null | Browser = null
|
let browser: null | Browser = null
|
||||||
|
|||||||
Reference in New Issue
Block a user