From ed822d7cc420b27a40d6debda2fc400f270473cf Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Sun, 17 Mar 2024 16:15:31 +0800 Subject: [PATCH] call sqlite-plugin in run-core --- .../geek-auto-start-chat-with-boss/index.mjs | 3 +-- .../main.mjs | 11 ++++++++- .../package.json | 3 ++- packages/sqlite-plugin/package.json | 1 + packages/sqlite-plugin/src/index.ts | 19 +++++++++++---- pnpm-lock.yaml | 24 +++++++++++++++---- 6 files changed, 49 insertions(+), 12 deletions(-) diff --git a/packages/geek-auto-start-chat-with-boss/index.mjs b/packages/geek-auto-start-chat-with-boss/index.mjs index 7468db6..0401f87 100644 --- a/packages/geek-auto-start-chat-with-boss/index.mjs +++ b/packages/geek-auto-start-chat-with-boss/index.mjs @@ -113,8 +113,6 @@ export async function mainLoop (hooks) { hooks.pageLoaded?.call() let userInfoResponse = await userInfoPromise - hooks.userInfoResponse?.call(userInfoResponse) - if (userInfoResponse.code !== 0) { autoStartChatEventBus.emit('LOGIN_STATUS_INVALID', { userInfoResponse @@ -123,6 +121,7 @@ export async function mainLoop (hooks) { throw new Error("LOGIN_STATUS_INVALID") } else { await storeStorage(page).catch(() => void 0) + await hooks.userInfoResponse?.promise(userInfoResponse) } // check set security question tip modal diff --git a/packages/run-core-of-geek-auto-start-chat-with-boss/main.mjs b/packages/run-core-of-geek-auto-start-chat-with-boss/main.mjs index 7e4c965..70b8314 100644 --- a/packages/run-core-of-geek-auto-start-chat-with-boss/main.mjs +++ b/packages/run-core-of-geek-auto-start-chat-with-boss/main.mjs @@ -14,6 +14,11 @@ import { AUTO_CHAT_ERROR_EXIT_CODE } from './enums.mjs' +import SqlitePluginModule from '@geekgeekrun/sqlite-plugin' +const { + default: SqlitePlugin +} = SqlitePluginModule + const rerunInterval = (() => { let v = Number(process.env.MAIN_BOSSGEEKGO_RERUN_INTERVAL) if (isNaN(v)) { @@ -32,6 +37,7 @@ const { groupRobotAccessToken: dingTalkAccessToken } = readConfigFile('dingtalk. const initPlugins = (hooks) => { new DingtalkPlugin(dingTalkAccessToken).apply(hooks) + new SqlitePlugin().apply(hooks) } const main = async () => { @@ -43,6 +49,7 @@ const main = async () => { puppeteerLaunched: new SyncHook(), pageLoaded: new SyncHook(), cookieWillSet: new SyncHook(['cookies']), + userInfoResponse: new AsyncSeriesHook(['userInfo']), newChatWillStartup: new AsyncSeriesHook(['positionInfoDetail']), newChatStartup: new SyncHook(['positionInfoDetail']), noPositionFoundForCurrentJob: new SyncHook(), @@ -79,5 +86,7 @@ const main = async () => { (async () => { try { await main() - } catch {} + } catch(err) { + console.error(err) + } })() \ No newline at end of file diff --git a/packages/run-core-of-geek-auto-start-chat-with-boss/package.json b/packages/run-core-of-geek-auto-start-chat-with-boss/package.json index cb779df..6e2eff9 100644 --- a/packages/run-core-of-geek-auto-start-chat-with-boss/package.json +++ b/packages/run-core-of-geek-auto-start-chat-with-boss/package.json @@ -14,6 +14,7 @@ "dependencies": { "@geekgeekrun/dingtalk-plugin": "workspace:*", "@geekgeekrun/geek-auto-start-chat-with-boss": "workspace:*", - "@geekgeekrun/utils": "workspace:*" + "@geekgeekrun/utils": "workspace:*", + "@geekgeekrun/sqlite-plugin": "workspace:*" } } diff --git a/packages/sqlite-plugin/package.json b/packages/sqlite-plugin/package.json index c4be0dc..40518f0 100644 --- a/packages/sqlite-plugin/package.json +++ b/packages/sqlite-plugin/package.json @@ -2,6 +2,7 @@ "name": "@geekgeekrun/sqlite-plugin", "version": "0.0.1", "description": "", + "main": "dist/index.js", "dependencies": { "reflect-metadata": "^0.2.1", "sqlite3": "^5.1.7", diff --git a/packages/sqlite-plugin/src/index.ts b/packages/sqlite-plugin/src/index.ts index d0825f6..5edd06a 100644 --- a/packages/sqlite-plugin/src/index.ts +++ b/packages/sqlite-plugin/src/index.ts @@ -33,7 +33,18 @@ async function initDb() { return appDataSource.initialize(); } -(async () => { - const a = await initDb(); - console.log(a); -})(); +export default class SqlitePlugin { + initPromise: Promise + + constructor () { + this.initPromise = initDb() + } + apply (hooks) { + hooks.userInfoResponse.tapPromise( + 'SqlitePlugin', + (userInfo) => new Promise((resolve, reject) => { + console.log(userInfo) + }) + ) + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 44ba3f0..ffb9158 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -61,6 +61,9 @@ importers: '@geekgeekrun/geek-auto-start-chat-with-boss': specifier: workspace:* version: link:../geek-auto-start-chat-with-boss + '@geekgeekrun/sqlite-plugin': + specifier: workspace:* + version: link:../sqlite-plugin '@geekgeekrun/utils': specifier: workspace:* version: link:../utils @@ -73,13 +76,12 @@ importers: sqlite3: specifier: ^5.1.7 version: 5.1.7 - typeorm: - specifier: ^0.3.20 - version: 0.3.20(sqlite3@5.1.7)(ts-node@10.9.2) - devDependencies: ts-node: specifier: ^10.9.2 version: 10.9.2(@types/node@18.19.15)(typescript@5.3.3) + typeorm: + specifier: ^0.3.20 + version: 0.3.20(sqlite3@5.1.7)(ts-node@10.9.2) typescript: specifier: ^5.3.3 version: 5.3.3 @@ -559,6 +561,7 @@ packages: engines: {node: '>=12'} dependencies: '@jridgewell/trace-mapping': 0.3.9 + dev: false /@ctrl/tinycolor@3.6.1: resolution: {integrity: sha512-SITSV6aIXsuVNV3f3O0f2n/cgyEDWoSqtZMYiAmcsYHydcKrOz3gUxB/iXd/Qf08+IZX4KpgNbvUdMBmWz+kcA==} @@ -1045,6 +1048,7 @@ packages: dependencies: '@jridgewell/resolve-uri': 3.1.1 '@jridgewell/sourcemap-codec': 1.4.15 + dev: false /@malept/cross-spawn-promise@1.1.1: resolution: {integrity: sha512-RTBGWL5FWQcg9orDOCcp4LvItNzUPcyEU9bwaeJX0rJ1IQxzucC48Y0/sQLp/g6t99IQgAlGIaesJS+gTn7tVQ==} @@ -1335,15 +1339,19 @@ packages: /@tsconfig/node10@1.0.9: resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==} + dev: false /@tsconfig/node12@1.0.11: resolution: {integrity: sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==} + dev: false /@tsconfig/node14@1.0.3: resolution: {integrity: sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==} + dev: false /@tsconfig/node16@1.0.4: resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==} + dev: false /@types/cacheable-request@6.0.3: resolution: {integrity: sha512-IQ3EbTzGxIigb1I3qPZc1rWJnH0BmSKv5QYTalEwweFvyBDLSAe24zP0le/hyi7ecGfZVlIVAg4BZqb8WBwKqw==} @@ -2017,6 +2025,7 @@ packages: /acorn-walk@8.3.2: resolution: {integrity: sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==} engines: {node: '>=0.4.0'} + dev: false /acorn@8.11.3: resolution: {integrity: sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==} @@ -2171,6 +2180,7 @@ packages: /arg@4.1.3: resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} + dev: false /argparse@2.0.1: resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} @@ -2638,6 +2648,7 @@ packages: /create-require@1.1.1: resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} + dev: false /cross-env@7.0.3: resolution: {integrity: sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==} @@ -2795,6 +2806,7 @@ packages: /diff@4.0.2: resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} engines: {node: '>=0.3.1'} + dev: false /dir-compare@3.3.0: resolution: {integrity: sha512-J7/et3WlGUCxjdnD3HAAzQ6nsnc0WL6DD7WcwJb7c39iH1+AWfg+9OqzJNaI6PkBwBvm1mhZNL9iY/nRiZXlPg==} @@ -4173,6 +4185,7 @@ packages: /make-error@1.3.6: resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} + dev: false /make-fetch-happen@9.1.0: resolution: {integrity: sha512-+zopwDy7DNknmwPQplem5lAZX/eCOzSvSNNcSKm5eVwTkOBzoktEfXsa9L23J/GIRhxRsaxzkPEhrJEpE2F4Gg==} @@ -5630,6 +5643,7 @@ packages: typescript: 5.3.3 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 + dev: false /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} @@ -5938,6 +5952,7 @@ packages: /v8-compile-cache-lib@3.0.1: resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} + dev: false /verror@1.10.1: resolution: {integrity: sha512-veufcmxri4e3XSrT0xwfUR7kguIkaxBeosDg00yDWhk49wdwkSUrvvsm7nc75e1PUyvIeZj6nS8VQRYz2/S4Xg==} @@ -6212,6 +6227,7 @@ packages: /yn@3.1.1: resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==} engines: {node: '>=6'} + dev: false /yocto-queue@0.1.0: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}