mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-05-11 18:09:50 +08:00
save autoStartupChatRecordId, chatStartupFrom in ChatStartupLog
This commit is contained in:
@@ -15,6 +15,8 @@ import { readConfigFile, writeStorageFile, ensureConfigFileExist, readStorageFil
|
||||
import { calculateTotalCombinations, combineFiltersWithConstraintsGenerator } from './combineCalculator.mjs'
|
||||
import { default as jobFilterConditions } from './internal-config/job-filter-conditions-20241002.json'
|
||||
import { default as rawIndustryFilterExemption } from './internal-config/job-filter-industry-filter-exemption-20241002.json'
|
||||
import { ChatStartupFrom } from '@geekgeekrun/sqlite-plugin/dist/entity/ChatStartupLog'
|
||||
|
||||
const jobFilterConditionsMapByCode = {}
|
||||
Object.values(jobFilterConditions).forEach(arr => {
|
||||
arr.forEach(option => {
|
||||
@@ -388,7 +390,7 @@ async function toRecommendPage (hooks) {
|
||||
|
||||
try {
|
||||
const { targetJobIndex, targetJobData } = await new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
try {
|
||||
let requestNextPagePromiseWithResolver = null
|
||||
page.on(
|
||||
'request',
|
||||
@@ -587,7 +589,7 @@ async function toRecommendPage (hooks) {
|
||||
throw new Error('STARTUP_CHAT_ERROR_WITH_UNKNOWN_ERROR')
|
||||
}
|
||||
} else {
|
||||
await hooks.newChatStartup?.promise(targetJobData)
|
||||
await hooks.newChatStartup?.promise(targetJobData, { chatStartupFrom: ChatStartupFrom.AutoFromRecommendList })
|
||||
blockBossNotNewChat.add(targetJobData.jobInfo.encryptUserId)
|
||||
|
||||
await storeStorage(page).catch(() => void 0)
|
||||
@@ -701,7 +703,7 @@ async function storeStorage (page) {
|
||||
return Promise.all(
|
||||
[
|
||||
writeStorageFile('boss-cookies.json', cookies),
|
||||
writeStorageFile('boss-local-storage.json', localStorage),
|
||||
writeStorageFile('boss-local-storage.json', localStorage),
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
@@ -46,17 +46,19 @@ const main = async () => {
|
||||
process.exit(AUTO_CHAT_ERROR_EXIT_CODE.COOKIE_INVALID)
|
||||
}
|
||||
const hooks = {
|
||||
daemonInitialized: new AsyncSeriesHook(),
|
||||
puppeteerLaunched: new SyncHook(),
|
||||
pageLoaded: new SyncHook(),
|
||||
cookieWillSet: new SyncHook(['cookies']),
|
||||
userInfoResponse: new AsyncSeriesHook(['userInfo']),
|
||||
newChatWillStartup: new AsyncSeriesHook(['positionInfoDetail']),
|
||||
newChatStartup: new AsyncSeriesHook(['positionInfoDetail']),
|
||||
newChatStartup: new AsyncSeriesHook(['positionInfoDetail', 'chatRunningContext']),
|
||||
noPositionFoundForCurrentJob: new SyncHook(),
|
||||
noPositionFoundAfterTraverseAllJob: new SyncHook(),
|
||||
errorEncounter: new SyncHook(['errorInfo'])
|
||||
}
|
||||
initPlugins(hooks)
|
||||
await hooks.daemonInitialized.callAsync()
|
||||
while (true) {
|
||||
try {
|
||||
await mainLoop(hooks)
|
||||
|
||||
11
packages/sqlite-plugin/src/entity/AutoStartChatRunRecord.ts
Normal file
11
packages/sqlite-plugin/src/entity/AutoStartChatRunRecord.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { requireTypeorm } from "../utils/module-loader";
|
||||
const { Entity, Column, PrimaryGeneratedColumn } = requireTypeorm();
|
||||
|
||||
@Entity()
|
||||
export class AutoStartChatRunRecord {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
date: Date;
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
import { requireTypeorm } from "../utils/module-loader";
|
||||
const { Entity, Column, PrimaryGeneratedColumn } = requireTypeorm()
|
||||
|
||||
export enum ChatStartupFrom {
|
||||
AutoFromRecommendList = null,
|
||||
ManuallyFromRecommendList = 1
|
||||
}
|
||||
|
||||
@Entity()
|
||||
export class ChatStartupLog {
|
||||
@PrimaryGeneratedColumn()
|
||||
@@ -14,4 +19,14 @@ export class ChatStartupLog {
|
||||
|
||||
@Column()
|
||||
date: Date;
|
||||
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
chatStartupFrom?: ChatStartupFrom;
|
||||
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
autoStartupChatRecordId?: number;
|
||||
}
|
||||
|
||||
@@ -238,7 +238,12 @@ export async function saveJobInfoFromRecommendPage(ds: DataSource, _jobInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
export async function saveChatStartupRecord(ds: DataSource, _jobInfo, { encryptUserId }) {
|
||||
export async function saveChatStartupRecord(
|
||||
ds: DataSource,
|
||||
_jobInfo,
|
||||
{ encryptUserId },
|
||||
{ autoStartupChatRecordId = undefined, chatStartupFrom = undefined } = {}
|
||||
) {
|
||||
const { jobInfo } = _jobInfo;
|
||||
|
||||
//#region chat-startup-log
|
||||
@@ -247,6 +252,8 @@ export async function saveChatStartupRecord(ds: DataSource, _jobInfo, { encryptU
|
||||
date: new Date(),
|
||||
encryptCurrentUserId: encryptUserId,
|
||||
encryptJobId: jobInfo.encryptId,
|
||||
autoStartupChatRecordId,
|
||||
chatStartupFrom
|
||||
}
|
||||
Object.assign(chatStartupLog, chatStartupLogPayload)
|
||||
|
||||
|
||||
@@ -4,13 +4,14 @@ import { requireTypeorm } from "./utils/module-loader";
|
||||
|
||||
import { BossInfo } from "./entity/BossInfo";
|
||||
import { BossInfoChangeLog } from "./entity/BossInfoChangeLog";
|
||||
import { ChatStartupLog } from './entity/ChatStartupLog';
|
||||
import { ChatStartupFrom, ChatStartupLog } from './entity/ChatStartupLog';
|
||||
import { CompanyInfoChangeLog } from "./entity/CompanyInfoChangeLog";
|
||||
import { CompanyInfo } from "./entity/CompanyInfo";
|
||||
import { JobInfo } from "./entity/JobInfo";
|
||||
import { JobInfoChangeLog } from "./entity/JobInfoChangeLog";
|
||||
import { BossActiveStatusRecord } from "./entity/BossActiveStatusRecord";
|
||||
import { UserInfo } from "./entity/UserInfo";
|
||||
import { AutoStartChatRunRecord } from './entity/AutoStartChatRunRecord';
|
||||
import { VChatStartupLog } from "./entity/VChatStartupLog";
|
||||
import { VBossLibrary } from "./entity/VBossLibrary";
|
||||
import { VJobLibrary } from "./entity/VJobLibrary";
|
||||
@@ -19,6 +20,8 @@ import { VCompanyLibrary } from "./entity/VCompanyLibrary"
|
||||
import sqlite3 from 'sqlite3';
|
||||
import * as cliHighlight from 'cli-highlight';
|
||||
import { saveChatStartupRecord, saveJobInfoFromRecommendPage } from "./handlers";
|
||||
import { UpdateChatStartupLogTable1729182577167 } from "./migrations/1729182577167-UpdateChatStartupLogTable";
|
||||
|
||||
Boolean(cliHighlight);
|
||||
|
||||
export function initDb(dbFilePath) {
|
||||
@@ -40,17 +43,23 @@ export function initDb(dbFilePath) {
|
||||
JobInfoChangeLog,
|
||||
BossActiveStatusRecord,
|
||||
UserInfo,
|
||||
AutoStartChatRunRecord,
|
||||
VChatStartupLog,
|
||||
VBossLibrary,
|
||||
VJobLibrary,
|
||||
VCompanyLibrary
|
||||
],
|
||||
migrations: [
|
||||
UpdateChatStartupLogTable1729182577167
|
||||
],
|
||||
migrationsRun: true
|
||||
});
|
||||
return appDataSource.initialize();
|
||||
}
|
||||
|
||||
export default class SqlitePlugin {
|
||||
initPromise: Promise<DataSource>;
|
||||
runRecordId: number;
|
||||
|
||||
constructor(dbFilePath) {
|
||||
this.initPromise = initDb(dbFilePath);
|
||||
@@ -59,6 +68,20 @@ export default class SqlitePlugin {
|
||||
userInfo = null
|
||||
|
||||
apply(hooks) {
|
||||
hooks.daemonInitialized.tapPromise(
|
||||
"SqlitePlugin",
|
||||
async () => {
|
||||
const ds = await this.initPromise;
|
||||
|
||||
const autoStartChatRunRecord = new AutoStartChatRunRecord();
|
||||
autoStartChatRunRecord.date = new Date();
|
||||
|
||||
const autoStartChatRunRecordRepository = ds.getRepository(AutoStartChatRunRecord)
|
||||
const result = await autoStartChatRunRecordRepository.save(autoStartChatRunRecord);
|
||||
|
||||
this.runRecordId = result.id;
|
||||
}
|
||||
);
|
||||
hooks.userInfoResponse.tapPromise(
|
||||
"SqlitePlugin",
|
||||
async (userInfoResponse) => {
|
||||
@@ -85,9 +108,12 @@ export default class SqlitePlugin {
|
||||
await saveJobInfoFromRecommendPage(ds, _jobInfo);
|
||||
});
|
||||
|
||||
hooks.newChatStartup.tapPromise("SqlitePlugin", async (_jobInfo) => {
|
||||
hooks.newChatStartup.tapPromise("SqlitePlugin", async (_jobInfo, { chatStartupFrom = ChatStartupFrom.AutoFromRecommendList } = {}) => {
|
||||
const ds = await this.initPromise;
|
||||
return await saveChatStartupRecord(ds, _jobInfo, this.userInfo);
|
||||
return await saveChatStartupRecord(ds, _jobInfo, this.userInfo, {
|
||||
autoStartupChatRecordId: this.runRecordId,
|
||||
chatStartupFrom
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
|
||||
const dropViewSql = `DROP VIEW IF EXISTS "v_chat_startup_log"`;
|
||||
|
||||
export class UpdateChatStartupLogTable1729182577167 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(dropViewSql);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(dropViewSql);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as path from 'node:path';
|
||||
import type typeormType from 'typeorm'
|
||||
import type TypeormType from 'typeorm'
|
||||
const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE)
|
||||
const isUiDev = process.env.NODE_ENV === 'development'
|
||||
|
||||
export function requireTypeorm () {
|
||||
export function requireTypeorm (): typeof TypeormType {
|
||||
const importResult = require('typeorm')
|
||||
return importResult
|
||||
}
|
||||
@@ -79,18 +79,20 @@ const runAutoChat = async () => {
|
||||
}
|
||||
|
||||
const hooks = {
|
||||
daemonInitialized: new AsyncSeriesHook(),
|
||||
puppeteerLaunched: new SyncHook(),
|
||||
pageLoaded: new SyncHook(),
|
||||
cookieWillSet: new SyncHook(['cookies']),
|
||||
userInfoResponse: new AsyncSeriesHook(['userInfo']),
|
||||
jobDetailIsGetFromRecommendList: new AsyncSeriesHook(['userInfo']),
|
||||
newChatWillStartup: new AsyncSeriesHook(['positionInfoDetail']),
|
||||
newChatStartup: new AsyncSeriesHook(['positionInfoDetail']),
|
||||
newChatStartup: new AsyncSeriesHook(['positionInfoDetail', 'chatRunningContext']),
|
||||
noPositionFoundForCurrentJob: new SyncHook(),
|
||||
noPositionFoundAfterTraverseAllJob: new SyncHook(),
|
||||
errorEncounter: new SyncHook(['errorInfo'])
|
||||
}
|
||||
initPlugins(hooks)
|
||||
await hooks.daemonInitialized.promise()
|
||||
pipeWriteRegardlessError(
|
||||
pipe,
|
||||
JSON.stringify({
|
||||
|
||||
@@ -18,6 +18,7 @@ import packageJson from '@geekgeekrun/launch-bosszhipin-login-page-with-preload-
|
||||
import { Target } from 'puppeteer'
|
||||
import { pipeWriteRegardlessError } from '../utils/pipe'
|
||||
import * as JSONStream from 'JSONStream'
|
||||
import { ChatStartupFrom } from '@geekgeekrun/sqlite-plugin/dist/entity/ChatStartupLog'
|
||||
|
||||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
|
||||
const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE)
|
||||
@@ -89,9 +90,16 @@ const attachRequestsListener = async (target: Target) => {
|
||||
const currentUserInfo = await page.evaluate(
|
||||
'document.querySelector(".job-detail-box").__vue__.$store.state.userInfo'
|
||||
)
|
||||
await saveChatStartupRecord(await dbInitPromise, currentJobData, {
|
||||
encryptUserId: currentUserInfo.encryptUserId
|
||||
})
|
||||
await saveChatStartupRecord(
|
||||
await dbInitPromise,
|
||||
currentJobData,
|
||||
{
|
||||
encryptUserId: currentUserInfo.encryptUserId
|
||||
},
|
||||
{
|
||||
chatStartupFrom: ChatStartupFrom.ManuallyFromRecommendList
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user