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