mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-07 08:27:13 +08:00
add the feature when startup chat in LAUNCH_BOSS_SITE recommend, save the startup record
This commit is contained in:
@@ -4,6 +4,7 @@ import { BossInfo } from "./entity/BossInfo";
|
|||||||
import { CompanyInfo } from "./entity/CompanyInfo";
|
import { CompanyInfo } from "./entity/CompanyInfo";
|
||||||
import { JobInfo } from "./entity/JobInfo";
|
import { JobInfo } from "./entity/JobInfo";
|
||||||
import { parseCompanyScale, parseSalary } from "./utils/parser";
|
import { parseCompanyScale, parseSalary } from "./utils/parser";
|
||||||
|
import { ChatStartupLog } from "./entity/ChatStartupLog";
|
||||||
|
|
||||||
export async function saveJobInfoFromRecommendPage(ds: DataSource, _jobInfo) {
|
export async function saveJobInfoFromRecommendPage(ds: DataSource, _jobInfo) {
|
||||||
const { bossInfo, brandComInfo, jobInfo } = _jobInfo;
|
const { bossInfo, brandComInfo, jobInfo } = _jobInfo;
|
||||||
@@ -86,3 +87,21 @@ export async function saveJobInfoFromRecommendPage(ds: DataSource, _jobInfo) {
|
|||||||
//#endregion
|
//#endregion
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function saveChatStartupRecord(ds: DataSource, _jobInfo, { encryptUserId }) {
|
||||||
|
const { jobInfo } = _jobInfo;
|
||||||
|
|
||||||
|
//#region chat-startup-log
|
||||||
|
const chatStartupLog = new ChatStartupLog()
|
||||||
|
const chatStartupLogPayload: Partial<ChatStartupLog> = {
|
||||||
|
date: new Date(),
|
||||||
|
encryptCurrentUserId: encryptUserId,
|
||||||
|
encryptJobId: jobInfo.encryptId,
|
||||||
|
}
|
||||||
|
Object.assign(chatStartupLog, chatStartupLogPayload)
|
||||||
|
|
||||||
|
const chatStartupLogRepository = ds.getRepository(ChatStartupLog);
|
||||||
|
await chatStartupLogRepository.save(chatStartupLog);
|
||||||
|
//#endregion
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { VChatStartupLog } from "./entity/VChatStartupLog";
|
|||||||
|
|
||||||
import sqlite3 from 'sqlite3';
|
import sqlite3 from 'sqlite3';
|
||||||
import * as cliHighlight from 'cli-highlight';
|
import * as cliHighlight from 'cli-highlight';
|
||||||
import { saveJobInfoFromRecommendPage } from "./handlers";
|
import { saveChatStartupRecord, saveJobInfoFromRecommendPage } from "./handlers";
|
||||||
Boolean(cliHighlight);
|
Boolean(cliHighlight);
|
||||||
|
|
||||||
export function initDb(dbFilePath) {
|
export function initDb(dbFilePath) {
|
||||||
@@ -76,26 +76,12 @@ export default class SqlitePlugin {
|
|||||||
|
|
||||||
hooks.jobDetailIsGetFromRecommendList.tapPromise("SqlitePlugin", async (_jobInfo) => {
|
hooks.jobDetailIsGetFromRecommendList.tapPromise("SqlitePlugin", async (_jobInfo) => {
|
||||||
const ds = await this.initPromise;
|
const ds = await this.initPromise;
|
||||||
saveJobInfoFromRecommendPage(ds, _jobInfo);
|
await saveJobInfoFromRecommendPage(ds, _jobInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
hooks.newChatStartup.tapPromise("SqlitePlugin", async (_jobInfo) => {
|
hooks.newChatStartup.tapPromise("SqlitePlugin", async (_jobInfo) => {
|
||||||
const { jobInfo } = _jobInfo;
|
|
||||||
|
|
||||||
//#region chat-startup-log
|
|
||||||
const chatStartupLog = new ChatStartupLog()
|
|
||||||
const chatStartupLogPayload: Partial<ChatStartupLog> = {
|
|
||||||
date: new Date(),
|
|
||||||
encryptCurrentUserId: this.userInfo.encryptUserId,
|
|
||||||
encryptJobId: jobInfo.encryptId,
|
|
||||||
}
|
|
||||||
Object.assign(chatStartupLog, chatStartupLogPayload)
|
|
||||||
|
|
||||||
const ds = await this.initPromise;
|
const ds = await this.initPromise;
|
||||||
const chatStartupLogRepository = ds.getRepository(ChatStartupLog);
|
return await saveChatStartupRecord(ds, _jobInfo, this.userInfo);
|
||||||
await chatStartupLogRepository.save(chatStartupLog);
|
|
||||||
//#endregion
|
|
||||||
return
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ import { initPuppeteer } from '@geekgeekrun/geek-auto-start-chat-with-boss/index
|
|||||||
import extractZip from 'extract-zip'
|
import extractZip from 'extract-zip'
|
||||||
import { readStorageFile } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
import { readStorageFile } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
||||||
import { setDomainLocalStorage } from '@geekgeekrun/utils/puppeteer/local-storage.mjs'
|
import { setDomainLocalStorage } from '@geekgeekrun/utils/puppeteer/local-storage.mjs'
|
||||||
import { saveJobInfoFromRecommendPage } from '@geekgeekrun/sqlite-plugin/dist/handlers'
|
import {
|
||||||
|
saveJobInfoFromRecommendPage,
|
||||||
|
saveChatStartupRecord
|
||||||
|
} from '@geekgeekrun/sqlite-plugin/dist/handlers'
|
||||||
import { initDb } from '@geekgeekrun/sqlite-plugin'
|
import { initDb } from '@geekgeekrun/sqlite-plugin'
|
||||||
import { getPublicDbFilePath } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
import { getPublicDbFilePath } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
||||||
|
|
||||||
@@ -59,8 +62,33 @@ const attachRequestsListener = async (target: Target) => {
|
|||||||
|
|
||||||
console.log(data)
|
console.log(data)
|
||||||
if (data.code === 0) {
|
if (data.code === 0) {
|
||||||
saveJobInfoFromRecommendPage(await dbInitPromise, data.zpData)
|
await saveJobInfoFromRecommendPage(await dbInitPromise, data.zpData)
|
||||||
}
|
}
|
||||||
|
} else if (
|
||||||
|
page.url().startsWith('https://www.zhipin.com/web/geek/job-recommend') &&
|
||||||
|
response.url().startsWith('https://www.zhipin.com/wapi/zpgeek/friend/add.json')
|
||||||
|
) {
|
||||||
|
const request = (await response.request()).url()
|
||||||
|
|
||||||
|
const url = new URL(request)
|
||||||
|
const jobIdInAddFriendUrl = url.searchParams.get('jobId')
|
||||||
|
|
||||||
|
// access current page, predict if jobId of current page is equal to jobId in request
|
||||||
|
// in case of page changed after startup chat
|
||||||
|
const currentJobData = await page.evaluate(
|
||||||
|
'document.querySelector(".job-detail-box").__vue__.data'
|
||||||
|
)
|
||||||
|
const currentJobId = currentJobData?.jobInfo?.encryptId
|
||||||
|
if (jobIdInAddFriendUrl !== currentJobId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentUserInfo = await page.evaluate(
|
||||||
|
'document.querySelector(".job-detail-box").__vue__.$store.state.userInfo'
|
||||||
|
)
|
||||||
|
await saveChatStartupRecord(await dbInitPromise, currentJobData, {
|
||||||
|
encryptUserId: currentUserInfo.encryptUserId
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user