From 1c985f28a24d8bd75b8d9c54c6b739b45273ae43 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Mon, 6 Oct 2025 02:10:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E6=A3=80=E9=AA=8C?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E5=92=8C=E5=AF=B9=E8=AF=9D=20ID=20?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=B7=B2=E7=BB=8F=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/data/Chat.ts | 8 ++++++++ server/data/User.ts | 17 +++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/server/data/Chat.ts b/server/data/Chat.ts index 25ef42b..6a0c8f2 100644 --- a/server/data/Chat.ts +++ b/server/data/Chat.ts @@ -9,6 +9,7 @@ import chalk from "chalk" import User from "./User.ts" import ChatType from "./ChatType.ts" import UserChatLinker from "./UserChatLinker.ts" +import DataWrongError from '../api/DataWrongError.ts' /** * Chat.ts - Wrapper and manager @@ -48,6 +49,8 @@ export default class Chat { } static create(chatId: string, type: ChatType) { + if (this.findAllBeansByCondition('id = ?', chatId).length > 0) + throw new DataWrongError(`对话ID ${chatId} 已被使用`) const chat = new Chat( Chat.findAllBeansByCondition( 'count = ?', @@ -101,6 +104,11 @@ export default class Chat { return null } + setTitle(title: string) { + if (this.bean.type == 'private') + throw new Error('不允许对私聊进行命名') + this.setAttr('title', title) + } getTitle(userMySelf?: User) { if (this.bean.type == 'group') return this.bean.title if (this.bean.type == 'private') return this.getAnotherUserForPrivate(userMySelf as User)?.getNickName() diff --git a/server/data/User.ts b/server/data/User.ts index 2a4b7bd..f0e7824 100644 --- a/server/data/User.ts +++ b/server/data/User.ts @@ -10,11 +10,11 @@ import UserBean from './UserBean.ts' import FileManager from './FileManager.ts' import { SQLInputValue } from "node:sqlite" -import DataWrongError from "../api/DataWrongError.ts" import ChatPrivate from "./ChatPrivate.ts" import Chat from "./Chat.ts" import ChatBean from "./ChatBean.ts" -import MapJson from "../MapJson.ts"; +import MapJson from "../MapJson.ts" +import DataWrongError from '../api/DataWrongError.ts' type UserBeanKey = keyof UserBean @@ -45,18 +45,9 @@ export default class User { return db } - static createWithUserNameChecked(userName: string | null, password: string, nickName: string, avatar: Buffer | null) { + static create(userName: string | null, password: string, nickName: string, avatar: Buffer | null) { if (userName && User.findAllBeansByCondition('username = ?', userName).length > 0) throw new DataWrongError(`用户名 ${userName} 已存在`) - return User.create( - userName, - password, - nickName, - avatar - ) - } - - static create(userName: string | null, password: string, nickName: string, avatar: Buffer | null) { const user = new User( User.findAllBeansByCondition( 'count = ?', @@ -124,6 +115,8 @@ export default class User { return this.bean.username } setUserName(userName: string) { + if (User.findAllBeansByCondition('username = ?', userName).length > 0) + throw new DataWrongError(`用户名 ${userName} 已存在`) this.setAttr("username", userName) } updateRecentChat(chatId: string, content: string) {