From f9761a47bbbaacb54208c136e3312cd81094484e Mon Sep 17 00:00:00 2001 From: bossgeekgo Date: Sun, 11 Feb 2024 23:43:10 +0800 Subject: [PATCH] migrate config file to json; read them via fs. --- config/boss.json | 3 + config/boss.mjs | 1 - config/dingtalk.json | 3 + config/dingtalk.mjs | 1 - config/target-company-list.json | 106 ++++++++++++++++ config/target-company-list.mjs | 119 ------------------ .../geek-auto-start-chat-with-boss/index.mjs | 25 +++- .../index.mjs | 13 +- .../package.json | 3 +- packages/utils/legacy-path.mjs | 3 + pnpm-lock.yaml | 3 + 11 files changed, 154 insertions(+), 126 deletions(-) create mode 100644 config/boss.json delete mode 100644 config/boss.mjs create mode 100644 config/dingtalk.json delete mode 100644 config/dingtalk.mjs create mode 100644 config/target-company-list.json delete mode 100644 config/target-company-list.mjs create mode 100644 packages/utils/legacy-path.mjs diff --git a/config/boss.json b/config/boss.json new file mode 100644 index 0000000..d2b80d7 --- /dev/null +++ b/config/boss.json @@ -0,0 +1,3 @@ +{ + "cookies": [] +} \ No newline at end of file diff --git a/config/boss.mjs b/config/boss.mjs deleted file mode 100644 index cdc9f92..0000000 --- a/config/boss.mjs +++ /dev/null @@ -1 +0,0 @@ -export const cookies = [] \ No newline at end of file diff --git a/config/dingtalk.json b/config/dingtalk.json new file mode 100644 index 0000000..2435cac --- /dev/null +++ b/config/dingtalk.json @@ -0,0 +1,3 @@ +{ + "groupRobotAccessToken": "" +} \ No newline at end of file diff --git a/config/dingtalk.mjs b/config/dingtalk.mjs deleted file mode 100644 index e480bd7..0000000 --- a/config/dingtalk.mjs +++ /dev/null @@ -1 +0,0 @@ -export const dingTalkAccessToken = `` diff --git a/config/target-company-list.json b/config/target-company-list.json new file mode 100644 index 0000000..0ea231d --- /dev/null +++ b/config/target-company-list.json @@ -0,0 +1,106 @@ +[ + "青钱", + "软通动力", + "南天", + "睿服", + "中电金信", + "佰钧成", + "云链", + "博彦", + "汉克时代", + "柯莱特", + "拓保", + "亿达信息", + "纬创", + "微创", + "微澜", + "诚迈科技", + "法本", + "兆尹", + "诚迈", + "联合永道", + "新致软件", + "宇信科技", + "抖音", + "字节", + "字跳", + "有竹居", + "脸萌", + "头条", + "滴滴", + "网易", + "腾讯", + "搜狗", + "京东", + "百度", + "度小满", + "爱奇艺", + "携程", + "趣拿", + "去哪儿", + "集度", + "理想", + "顺丰", + "讯飞", + "同程", + "艺龙", + "贝壳", + "链家", + "我爱我家", + "多点", + "金山", + "小米", + "猎豹", + "新浪", + "微博", + "阿里", + "蚂蚁", + "飞猪", + "高德", + "乌鸫", + "美团", + "三快", + "快手", + "映客", + "小红书", + "行吟", + "奇虎", + "360", + "鸿盈", + "奇富", + "亚信", + "启明星辰", + "奇安信", + "汽车之家", + "车好多", + "瓜子", + "易车", + "昆仑万维", + "闲徕", + "趣加", + "完美", + "马上消费", + "轻松", + "水滴", + "白龙马", + "58", + "车欢欢", + "五八", + "红布林", + "致美", + "美餐", + "知乎", + "易点云", + "搜狐", + "用友", + "畅捷通", + "猿辅导", + "小猿", + "猿力", + "好未来", + "学而思", + "希望学", + "新东方", + "东方甄选", + "作业帮" +] \ No newline at end of file diff --git a/config/target-company-list.mjs b/config/target-company-list.mjs deleted file mode 100644 index ec0e84a..0000000 --- a/config/target-company-list.mjs +++ /dev/null @@ -1,119 +0,0 @@ -export default [ - '青钱', - '软通动力', - '南天', - '睿服', - '中电金信', - '佰钧成', - '云链', - '博彦', - '汉克时代', - '柯莱特', - '拓保', - '亿达信息', - '纬创', - '微创', - '微澜', - '诚迈科技', - '法本', - '兆尹', - '诚迈', - '联合永道', - '新致软件', - '宇信科技', - // - '抖音', '字节', '字跳', '有竹居', '脸萌', '头条', - // - '滴滴', - // - '网易', - // - '腾讯', '搜狗', - // - '京东', - // - '百度', - // - '度小满', - // - '爱奇艺', - // - '携程', '趣拿', '去哪儿', - // - '集度', - // - '理想', - // - '顺丰', - // - '讯飞', - // - '同程', '艺龙', - // - '贝壳', '链家', - // - '我爱我家', - // - '多点', - // - '金山', '小米', '猎豹', - // - '新浪', '微博', - // - '阿里', '蚂蚁', '飞猪', '高德', '乌鸫', - // - '美团', '三快', - // - '快手', - // - '映客', - // - '小红书', '行吟', - // - '奇虎', '360', '鸿盈', '奇富', - // - '亚信', - // - '启明星辰', - // - '奇安信', - // - '汽车之家', - // - '车好多', '瓜子', - // - '易车', - // - '昆仑万维', '闲徕', - // - '趣加', - // - '完美', - // - '马上消费', - // - '轻松', - // - '水滴', - // - '白龙马', - // - '58', '车欢欢', '五八', '红布林', '致美', - // - '美餐', - // - '知乎', - // - '易点云', - // - '搜狐', - // - '用友', '畅捷通', - // - '猿辅导', '小猿', '猿力', - // - '好未来', '学而思', '希望学', - // - '新东方', '东方甄选', - '作业帮' -] \ No newline at end of file diff --git a/packages/geek-auto-start-chat-with-boss/index.mjs b/packages/geek-auto-start-chat-with-boss/index.mjs index 0a2f284..6672900 100644 --- a/packages/geek-auto-start-chat-with-boss/index.mjs +++ b/packages/geek-auto-start-chat-with-boss/index.mjs @@ -1,16 +1,35 @@ import puppeteer from 'puppeteer-extra'; import StealthPlugin from 'puppeteer-extra-plugin-stealth' -import { cookies as bossCookies } from '../../config/boss.mjs' -import targetCompanyList from '../../config/target-company-list.mjs' - import { sleep, sleepWithRandomDelay } from '@bossgeekgo/utils/sleep.mjs' +import fs from 'node:fs' +import { get__dirname } from '@bossgeekgo/utils/legacy-path.mjs'; +import path from 'node:path'; + puppeteer.use(StealthPlugin()) +const { cookies: bossCookies } = JSON.parse( + fs.readFileSync( + path.join( + get__dirname(), + '../../config/boss.json' + ) + ) +) + +const targetCompanyList = JSON.parse( + fs.readFileSync( + path.join( + get__dirname(), + '../../config/target-company-list.json' + ) + ) +) + if (!bossCookies?.length) { console.error('There is no cookies. you can save a copy with EditThisCookie extension.') process.exit(1) diff --git a/packages/run-core-of-geek-auto-start-chat-with-boss/index.mjs b/packages/run-core-of-geek-auto-start-chat-with-boss/index.mjs index 8de2043..91dd5c1 100644 --- a/packages/run-core-of-geek-auto-start-chat-with-boss/index.mjs +++ b/packages/run-core-of-geek-auto-start-chat-with-boss/index.mjs @@ -1,10 +1,21 @@ import DingtalkPlugin from '@bossgeekgo/dingtalk-plugin/index.mjs' -import { dingTalkAccessToken } from "../../config/dingtalk.mjs" import { mainLoop } from '@bossgeekgo/geek-auto-start-chat-with-boss/index.mjs' import { SyncHook, AsyncSeriesHook } from 'tapable' +import fs from 'node:fs' +import path from 'node:path' +import { get__dirname } from '@bossgeekgo/utils/legacy-path.mjs'; + +const { groupRobotAccessToken: dingTalkAccessToken } = JSON.parse( + fs.readFileSync( + path.join( + get__dirname(), + '../../config/dingtalk.json' + ) + ) +) const initPlugins = (hooks) => { new DingtalkPlugin(dingTalkAccessToken).apply(hooks) 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 09136c6..25a864e 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 @@ -11,6 +11,7 @@ "license": "ISC", "dependencies": { "@bossgeekgo/dingtalk-plugin": "workspace:*", - "@bossgeekgo/geek-auto-start-chat-with-boss": "workspace:*" + "@bossgeekgo/geek-auto-start-chat-with-boss": "workspace:*", + "@bossgeekgo/utils": "workspace:*" } } diff --git a/packages/utils/legacy-path.mjs b/packages/utils/legacy-path.mjs new file mode 100644 index 0000000..ab72f15 --- /dev/null +++ b/packages/utils/legacy-path.mjs @@ -0,0 +1,3 @@ +import * as url from 'url'; +export const get__filename = () => url.fileURLToPath(import.meta.url); +export const get__dirname = () => url.fileURLToPath(new URL('.', import.meta.url)); \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ed2ca8f..6f37af0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -40,6 +40,9 @@ importers: '@bossgeekgo/geek-auto-start-chat-with-boss': specifier: workspace:* version: link:../geek-auto-start-chat-with-boss + '@bossgeekgo/utils': + specifier: workspace:* + version: link:../utils packages/ui: dependencies: