This repository was archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Closes: #9
- Loading branch information
chentianyu
committed
Oct 8, 2023
1 parent
1b64d1e
commit 6008271
Showing
10 changed files
with
172 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
PORT=3001 | ||
# 如果想自己处理收到消息的逻辑,在下面填上你的API地址, 默认为空 | ||
LOCAL_RECVD_MSG_API= | ||
LOCAL_RECVD_MSG_API=https://home.danielcoding.me:888/webhook-test/53f51927-9cec-447b-899a-d4a212000808 | ||
# 登录地址Token访问地址: http://localhost:3001/loginCheck?token=[LOCAL_LOGIN_API_TOKEN] | ||
# 生成规则:src/utils/index.js | ||
# 生成规则:src/utils/index.js -> generateToken | ||
LOCAL_LOGIN_API_TOKEN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 给 shell 调用使用 | ||
const fs = require('fs'); | ||
const dotenv = require('dotenv'); | ||
const { generateToken } = require('../src/utils/index') | ||
|
||
// 读取 .env 文件内容 | ||
const envContent = fs.readFileSync('.env', 'utf-8').split('\n'); | ||
|
||
// 解析 .env 文件内容 | ||
const envConfig = dotenv.parse(envContent.join('\n')); | ||
|
||
// 无配置token,会默认生成一个token | ||
if(envConfig.LOCAL_LOGIN_API_TOKEN) return | ||
const token = generateToken() | ||
console.log(`检测未配置 LOGIN_API_TOKEN, 写入初始化值 LOCAL_LOGIN_API_TOKEN=${token} => .env \n`) | ||
|
||
envConfig.LOCAL_LOGIN_API_TOKEN = token // 添加或修改键值对 | ||
|
||
// 生成新的 .env 文件内容,同时保留注释 | ||
const newEnv = envContent.map(line => { | ||
if (line.startsWith('#')) { | ||
// 保留注释 | ||
return line; | ||
} | ||
|
||
const [key] = line.split('='); | ||
if (envConfig[key] !== undefined) { | ||
// 更新已存在的键值对 | ||
const updatedLine = `${key}=${envConfig[key]}`; | ||
delete envConfig[key]; // 从 envConfig 中移除已处理的键 | ||
return updatedLine; | ||
} | ||
|
||
return line; | ||
}).join('\n'); | ||
|
||
// 将未在原始 .env 文件中的新键值对添加到文件末尾 | ||
for (const [key, value] of Object.entries(envConfig)) { | ||
newEnv += `\n${key}=${value}`; | ||
} | ||
|
||
// 写入新的 .env 文件内容 | ||
fs.writeFileSync('.env', newEnv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module.exports.TextMsg = class TextMsg { | ||
constructor({ text, isSystemEvent = false }) { | ||
this.payload = text | ||
this.isSystemEvent = isSystemEvent | ||
} | ||
|
||
type() { | ||
return 7 | ||
} | ||
|
||
text() { | ||
return this.payload | ||
} | ||
|
||
self() { | ||
return false | ||
} | ||
|
||
room() { | ||
return '' | ||
} | ||
|
||
to() { | ||
return '' | ||
} | ||
|
||
talker() { | ||
return '' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters