mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-08-28 19:46:50 +08:00
migrate cookies to storage
This commit is contained in:
@@ -1,3 +1,2 @@
|
|||||||
{
|
{
|
||||||
"cookies": []
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[]
|
||||||
@@ -9,8 +9,9 @@ import { get__dirname } from '@geekgeekrun/utils/legacy-path.mjs';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import JSON5 from 'json5'
|
import JSON5 from 'json5'
|
||||||
|
|
||||||
import { readConfigFile, ensureConfigFileExist } from './runtime-file-utils.mjs'
|
import { readConfigFile, ensureConfigFileExist, readStorageFile, ensureStorageFileExist } from './runtime-file-utils.mjs'
|
||||||
ensureConfigFileExist()
|
ensureConfigFileExist()
|
||||||
|
ensureStorageFileExist()
|
||||||
|
|
||||||
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'
|
||||||
@@ -45,7 +46,7 @@ export async function initPuppeteer () {
|
|||||||
puppeteer.use(StealthPlugin())
|
puppeteer.use(StealthPlugin())
|
||||||
}
|
}
|
||||||
|
|
||||||
const { cookies: bossCookies } = readConfigFile('boss.json')
|
const bossCookies = readStorageFile('boss-cookie.json')
|
||||||
|
|
||||||
const targetCompanyList = readConfigFile('target-company-list.json')
|
const targetCompanyList = readConfigFile('target-company-list.json')
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import defaultDingtalkConf from './default-config-file/dingtalk.json' assert {ty
|
|||||||
import defaultBossConf from './default-config-file/boss.json' assert {type: 'json'}
|
import defaultBossConf from './default-config-file/boss.json' assert {type: 'json'}
|
||||||
import defaultTargetCompanyListConf from './default-config-file/target-company-list.json' assert {type: 'json'}
|
import defaultTargetCompanyListConf from './default-config-file/target-company-list.json' assert {type: 'json'}
|
||||||
|
|
||||||
|
import defaultBossCookieStorage from './default-storage-file/boss-cookies.json' assert { type: 'json' }
|
||||||
export const configFileNameList = ['boss.json', 'dingtalk.json', 'target-company-list.json']
|
export const configFileNameList = ['boss.json', 'dingtalk.json', 'target-company-list.json']
|
||||||
|
|
||||||
const defaultConfigFileContentMap = {
|
const defaultConfigFileContentMap = {
|
||||||
@@ -20,7 +21,7 @@ const ensureRuntimeFolderPathExist = () => {
|
|||||||
if (!fs.existsSync(runtimeFolderPath)) {
|
if (!fs.existsSync(runtimeFolderPath)) {
|
||||||
fs.mkdirSync(runtimeFolderPath)
|
fs.mkdirSync(runtimeFolderPath)
|
||||||
}
|
}
|
||||||
;['config'].forEach(dirPath => {
|
;['config', 'storage'].forEach(dirPath => {
|
||||||
if (!fs.existsSync(
|
if (!fs.existsSync(
|
||||||
path.join(runtimeFolderPath, dirPath)
|
path.join(runtimeFolderPath, dirPath)
|
||||||
)) {
|
)) {
|
||||||
@@ -52,8 +53,9 @@ export const ensureConfigFileExist = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const readConfigFile = (fileName) => {
|
export const readConfigFile = (fileName) => {
|
||||||
|
const joinedPath = path.join(configFolderPath, fileName)
|
||||||
if (!fs.existsSync(
|
if (!fs.existsSync(
|
||||||
path.join(configFolderPath, fileName)
|
joinedPath
|
||||||
)) {
|
)) {
|
||||||
ensureConfigFileExist()
|
ensureConfigFileExist()
|
||||||
}
|
}
|
||||||
@@ -61,10 +63,10 @@ export const readConfigFile = (fileName) => {
|
|||||||
let o
|
let o
|
||||||
try {
|
try {
|
||||||
o = JSON.parse(
|
o = JSON.parse(
|
||||||
fs.readFileSync(path.join(configFolderPath, fileName))
|
fs.readFileSync(joinedPath)
|
||||||
)
|
)
|
||||||
} catch {
|
} catch {
|
||||||
fs.unlinkSync(fs.readFileSync(path.join(configFolderPath, fileName)))
|
fs.existsSync(joinedPath) && fs.unlinkSync(joinedPath)
|
||||||
ensureConfigFileExist()
|
ensureConfigFileExist()
|
||||||
o = JSON.parse(defaultConfigFileContentMap[fileName])
|
o = JSON.parse(defaultConfigFileContentMap[fileName])
|
||||||
}
|
}
|
||||||
@@ -81,3 +83,50 @@ export const writeConfigFile = async (fileName, content) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const storageFilePath = path.join(
|
||||||
|
runtimeFolderPath,
|
||||||
|
'storage'
|
||||||
|
)
|
||||||
|
export const storageFileNameList = ['boss-cookies.json']
|
||||||
|
|
||||||
|
const defaultStorageFileContentMap = {
|
||||||
|
'boss-cookies.json': JSON.stringify(defaultBossCookieStorage)
|
||||||
|
}
|
||||||
|
export const ensureStorageFileExist = () => {
|
||||||
|
ensureRuntimeFolderPathExist()
|
||||||
|
;storageFileNameList.forEach(
|
||||||
|
fileName => {
|
||||||
|
if (!fs.existsSync(
|
||||||
|
path.join(storageFilePath, fileName)
|
||||||
|
)) {
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(storageFilePath, fileName),
|
||||||
|
defaultStorageFileContentMap[fileName]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const readStorageFile = (fileName) => {
|
||||||
|
const joinedPath = path.join(storageFilePath, fileName)
|
||||||
|
|
||||||
|
if (!fs.existsSync(
|
||||||
|
joinedPath
|
||||||
|
)) {
|
||||||
|
ensureStorageFileExist()
|
||||||
|
}
|
||||||
|
|
||||||
|
let o
|
||||||
|
try {
|
||||||
|
o = JSON.parse(
|
||||||
|
fs.readFileSync(joinedPath)
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
fs.existsSync(joinedPath) && fs.unlinkSync(joinedPath)
|
||||||
|
ensureStorageFileExist()
|
||||||
|
o = JSON.parse(defaultStorageFileContentMap[fileName])
|
||||||
|
}
|
||||||
|
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import fs from 'node:fs'
|
|||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import { get__dirname } from '@geekgeekrun/utils/legacy-path.mjs';
|
import { get__dirname } from '@geekgeekrun/utils/legacy-path.mjs';
|
||||||
import JSON5 from 'json5'
|
import JSON5 from 'json5'
|
||||||
import { readConfigFile } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
import { readConfigFile, readStorageFile } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
||||||
const { cookies: bossCookies } = readConfigFile('boss.json')
|
const bossCookies = readStorageFile('boss-cookies.json')
|
||||||
const { groupRobotAccessToken: dingTalkAccessToken } = readConfigFile('dingtalk.json')
|
const { groupRobotAccessToken: dingTalkAccessToken } = readConfigFile('dingtalk.json')
|
||||||
|
|
||||||
const initPlugins = (hooks) => {
|
const initPlugins = (hooks) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user