chore: 统一为简体中文
This commit is contained in:
@@ -75,17 +75,17 @@ export default class ApiManager {
|
||||
|
||||
socket.on('disconnect', (_reason) => {
|
||||
if (clientInfo.userId == '')
|
||||
console.log(chalk.yellow('[斷]') + ` ${ip} disconnected`)
|
||||
console.log(chalk.yellow('[断]') + ` ${ip} disconnected`)
|
||||
else {
|
||||
console.log(chalk.green('[斷]') + ` ${ip} disconnected`)
|
||||
console.log(chalk.green('[断]') + ` ${ip} disconnected`)
|
||||
delete this.clients[clientInfo.userId][deviceId + '_' + sessionId]
|
||||
}
|
||||
})
|
||||
console.log(chalk.yellow('[連]') + ` ${ip} connected`)
|
||||
console.log(chalk.yellow('[连]') + ` ${ip} connected`)
|
||||
|
||||
socket.on("The_White_Silk", async (name: string, args: { [key: string]: unknown }, callback_: (ret: ApiCallbackMessage) => void) => {
|
||||
function callback(ret: ApiCallbackMessage) {
|
||||
console.log(chalk.blue('[發]') + ` ${ip} <- ${ret.code == 200 ? chalk.green(ret.msg) : chalk.red(ret.msg)} [${ret.code}]${ret.data ? (' <extras: ' + stringifyNotIncludeArrayBuffer(ret.data) + '>') : ''}`)
|
||||
console.log(chalk.blue('[发]') + ` ${ip} <- ${ret.code == 200 ? chalk.green(ret.msg) : chalk.red(ret.msg)} [${ret.code}]${ret.data ? (' <extras: ' + stringifyNotIncludeArrayBuffer(ret.data) + '>') : ''}`)
|
||||
return callback_(ret)
|
||||
}
|
||||
async function checkIsPromiseAndAwait(value: Promise<unknown> | unknown) {
|
||||
@@ -106,11 +106,11 @@ export default class ApiManager {
|
||||
})
|
||||
} catch (e) {
|
||||
const err = e as Error
|
||||
console.log(chalk.yellow('[壞]') + ` ${err.message} (${err.stack})`)
|
||||
console.log(chalk.yellow('[坏]') + ` ${err.message} (${err.stack})`)
|
||||
try {
|
||||
callback({
|
||||
code: err instanceof DataWrongError ? 400 : 500,
|
||||
msg: "錯誤: " + err.message
|
||||
msg: "错误: " + err.message
|
||||
})
|
||||
} catch (_e) { }
|
||||
}
|
||||
|
||||
@@ -22,24 +22,24 @@ export default class ChatApi extends BaseApi {
|
||||
*/
|
||||
this.registerEvent("Chat.getInfo", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['token', 'target'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
|
||||
const chat = Chat.findById(args.target as string)
|
||||
if (chat == null) return {
|
||||
code: 404,
|
||||
msg: "對話不存在",
|
||||
msg: "对话不存在",
|
||||
}
|
||||
if (!UserChatLinker.checkUserIsLinkedToChat(token.author, chat!.bean.id)) return {
|
||||
code: 400,
|
||||
msg: "用戶無權訪問該對話",
|
||||
msg: "用户无权访问此对话",
|
||||
}
|
||||
|
||||
// 私聊
|
||||
@@ -83,24 +83,24 @@ export default class ChatApi extends BaseApi {
|
||||
*/
|
||||
this.registerEvent("Chat.sendMessage", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['token', 'target', 'text'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
|
||||
const chat = Chat.findById(args.target as string)
|
||||
if (chat == null) return {
|
||||
code: 404,
|
||||
msg: "對話不存在",
|
||||
msg: "对话不存在",
|
||||
}
|
||||
if (!UserChatLinker.checkUserIsLinkedToChat(token.author, chat!.bean.id)) return {
|
||||
code: 400,
|
||||
msg: "用戶無權訪問該對話",
|
||||
msg: "用户无权访问此对话",
|
||||
}
|
||||
|
||||
const msg = {
|
||||
@@ -142,24 +142,24 @@ export default class ChatApi extends BaseApi {
|
||||
*/
|
||||
this.registerEvent("Chat.getMessageHistory", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['token', 'target', 'page'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
|
||||
const chat = Chat.findById(args.target as string)
|
||||
if (chat == null) return {
|
||||
code: 404,
|
||||
msg: "對話不存在",
|
||||
msg: "对话不存在",
|
||||
}
|
||||
if (!UserChatLinker.checkUserIsLinkedToChat(token.author, chat!.bean.id)) return {
|
||||
code: 400,
|
||||
msg: "用戶無權訪問該對話",
|
||||
msg: "用户无权访问此对话",
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -179,24 +179,24 @@ export default class ChatApi extends BaseApi {
|
||||
*/
|
||||
this.registerEvent("Chat.uploadFile", async (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['token', 'target', 'data', 'file_name'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
|
||||
const chat = Chat.findById(args.target as string)
|
||||
if (chat == null) return {
|
||||
code: 404,
|
||||
msg: "對話不存在",
|
||||
msg: "对话不存在",
|
||||
}
|
||||
if (!UserChatLinker.checkUserIsLinkedToChat(token.author, chat!.bean.id)) return {
|
||||
code: 400,
|
||||
msg: "用戶無權訪問該對話",
|
||||
msg: "用户无权访问此对话",
|
||||
}
|
||||
|
||||
const file = await FileManager.uploadFile(args.file_name as string, args.data as Buffer<ArrayBufferLike>, args.target as string)
|
||||
@@ -216,20 +216,20 @@ export default class ChatApi extends BaseApi {
|
||||
*/
|
||||
this.registerEvent("Chat.getIdForPrivate", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['token', 'target'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
const user = User.findById(token.author) as User
|
||||
const targetUser = User.findById(args.target as string) as User
|
||||
if (targetUser == null) {
|
||||
return {
|
||||
msg: "找不到用戶",
|
||||
msg: "找不到用户",
|
||||
code: 404,
|
||||
}
|
||||
}
|
||||
@@ -251,18 +251,18 @@ export default class ChatApi extends BaseApi {
|
||||
*/
|
||||
this.registerEvent("Chat.createGroup", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['token', 'title'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
if (this.checkArgsEmpty(args, ['title'])) return {
|
||||
msg: "參數不得為空",
|
||||
msg: "参数不得为空",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
const user = User.findById(token.author) as User
|
||||
|
||||
@@ -291,14 +291,14 @@ export default class ChatApi extends BaseApi {
|
||||
*/
|
||||
this.registerEvent("Chat.getAnotherUserIdFromPrivate", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['token', 'target'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
|
||||
const user = User.findById(token.author) as User
|
||||
@@ -306,11 +306,11 @@ export default class ChatApi extends BaseApi {
|
||||
const chat = Chat.findById(args.target as string)
|
||||
if (chat == null) return {
|
||||
code: 404,
|
||||
msg: "對話不存在",
|
||||
msg: "对话不存在",
|
||||
}
|
||||
if (!UserChatLinker.checkUserIsLinkedToChat(token.author, chat!.bean.id)) return {
|
||||
code: 400,
|
||||
msg: "用戶無權訪問該對話",
|
||||
msg: "用户无权访问此对话",
|
||||
}
|
||||
|
||||
if (chat.bean.type == 'private')
|
||||
|
||||
@@ -25,7 +25,7 @@ export default class EventStorer {
|
||||
CREATE TABLE IF NOT EXISTS ${this.getTableName()} (
|
||||
/* 序号 */ count INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
/* 事件 */ event_name TEXT NOT NULL,
|
||||
/* 數據 */ data TEXT NOT NULL,
|
||||
/* 数据 */ data TEXT NOT NULL,
|
||||
);
|
||||
`)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export default class UserApi extends BaseApi {
|
||||
// 驗證
|
||||
this.registerEvent("User.auth", (args, clientInfo) => {
|
||||
if (this.checkArgsMissing(args, ['access_token'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
const { deviceId, ip, socket, sessionId } = clientInfo
|
||||
@@ -23,20 +23,20 @@ export default class UserApi extends BaseApi {
|
||||
const access_token = TokenManager.decode(args.access_token as string)
|
||||
|
||||
if (access_token.expired_time < Date.now()) return {
|
||||
msg: "登錄令牌失效",
|
||||
msg: "登录令牌失效",
|
||||
code: 401,
|
||||
}
|
||||
if (!access_token.author || !User.findById(access_token.author)) return {
|
||||
msg: "賬號不存在",
|
||||
msg: "账号不存在",
|
||||
code: 401,
|
||||
}
|
||||
if (access_token.device_id != deviceId) return {
|
||||
msg: "驗證失敗",
|
||||
msg: "验证失败",
|
||||
code: 401,
|
||||
}
|
||||
|
||||
clientInfo.userId = access_token.author
|
||||
console.log(chalk.green('[驗]') + ` ${access_token.author} authed on Client ${deviceId} (ip = ${ip})`)
|
||||
console.log(chalk.green('[验]') + ` ${access_token.author} authed on Client ${deviceId} (ip = ${ip})`)
|
||||
if (ApiManager.clients[clientInfo.userId] == null) ApiManager.clients[clientInfo.userId] = {
|
||||
[deviceId + '_' + sessionId]: socket
|
||||
}
|
||||
@@ -50,7 +50,7 @@ export default class UserApi extends BaseApi {
|
||||
const err = e as Error
|
||||
if (err.message.indexOf("JSON") != -1)
|
||||
return {
|
||||
msg: "無效的登錄令牌",
|
||||
msg: "无效的用户令牌",
|
||||
code: 401,
|
||||
}
|
||||
else
|
||||
@@ -60,17 +60,17 @@ export default class UserApi extends BaseApi {
|
||||
// 登錄
|
||||
this.registerEvent("User.login", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['account', 'password'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
if (this.checkArgsEmpty(args, ['account', 'password'])) return {
|
||||
msg: "參數不得為空",
|
||||
msg: "参数不得为空",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const user = User.findByAccount(args.account as string) as User
|
||||
if (user == null) return {
|
||||
msg: "賬號或密碼錯誤",
|
||||
msg: "账号或密码错误",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
@@ -83,18 +83,18 @@ export default class UserApi extends BaseApi {
|
||||
}
|
||||
|
||||
return {
|
||||
msg: "賬號或密碼錯誤",
|
||||
msg: "账号或密码错误",
|
||||
code: 400,
|
||||
}
|
||||
})
|
||||
// 注冊
|
||||
this.registerEvent("User.register", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['nickname', 'password'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
if (this.checkArgsEmpty(args, ['nickname', 'password'])) return {
|
||||
msg: "參數不得為空",
|
||||
msg: "参数不得为空",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
@@ -120,17 +120,17 @@ export default class UserApi extends BaseApi {
|
||||
// 更新頭像
|
||||
this.registerEvent("User.setAvatar", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['avatar', 'token'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
if (!(args.avatar instanceof Buffer)) return {
|
||||
msg: "參數不合法",
|
||||
msg: "参数不合法",
|
||||
code: 400,
|
||||
}
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
|
||||
const avatar: Buffer = args.avatar as Buffer
|
||||
@@ -145,14 +145,14 @@ export default class UserApi extends BaseApi {
|
||||
// 更新資料
|
||||
this.registerEvent("User.updateProfile", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['token'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
|
||||
const user = User.findById(token.author)
|
||||
@@ -169,14 +169,14 @@ export default class UserApi extends BaseApi {
|
||||
// 獲取用戶信息
|
||||
this.registerEvent("User.getMyInfo", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['token'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
|
||||
const user = User.findById(token.author)
|
||||
@@ -195,14 +195,14 @@ export default class UserApi extends BaseApi {
|
||||
// 獲取最近对话列表
|
||||
this.registerEvent("User.getMyRecentChats", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['token'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
|
||||
const user = User.findById(token.author) as User
|
||||
@@ -229,14 +229,14 @@ export default class UserApi extends BaseApi {
|
||||
// 獲取聯絡人列表
|
||||
this.registerEvent("User.getMyContacts", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['token'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
|
||||
const user = User.findById(token.author) as User
|
||||
@@ -262,14 +262,14 @@ export default class UserApi extends BaseApi {
|
||||
// 添加聯絡人
|
||||
this.registerEvent("User.addContact", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['token', 'target'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
|
||||
const user = User.findById(token.author) as User
|
||||
@@ -300,14 +300,14 @@ export default class UserApi extends BaseApi {
|
||||
// 獲取用戶信息
|
||||
this.registerEvent("User.getInfo", (args, { deviceId }) => {
|
||||
if (this.checkArgsMissing(args, ['token', 'target'])) return {
|
||||
msg: "參數缺失",
|
||||
msg: "参数缺失",
|
||||
code: 400,
|
||||
}
|
||||
|
||||
const token = TokenManager.decode(args.token as string)
|
||||
if (!this.checkToken(token, deviceId)) return {
|
||||
code: 401,
|
||||
msg: "令牌無效",
|
||||
msg: "令牌无效",
|
||||
}
|
||||
|
||||
const user = User.findById(args.target as string)
|
||||
|
||||
Reference in New Issue
Block a user