From fe47aae7331185fc3228fafc0ba947e8e8e3bc7f Mon Sep 17 00:00:00 2001 From: Arvin Xu Date: Thu, 31 Oct 2024 00:00:44 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20fix=20duplicate=20error?= =?UTF-8?q?=20when=20creating=20new=20user=20=20(#4554)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/server/models/user.ts | 6 ++++++ src/libs/langchain/loaders/index.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/database/server/models/user.ts b/src/database/server/models/user.ts index ef2a190c87f6..e4341d9c5a90 100644 --- a/src/database/server/models/user.ts +++ b/src/database/server/models/user.ts @@ -19,6 +19,12 @@ export class UserNotFoundError extends TRPCError { export class UserModel { static createUser = async (params: NewUser) => { + // if user already exists, skip creation + if (params.id) { + const user = await serverDB.query.users.findFirst({ where: eq(users.id, params.id) }); + if (!!user) return; + } + const [user] = await serverDB .insert(users) .values({ ...params }) diff --git a/src/libs/langchain/loaders/index.ts b/src/libs/langchain/loaders/index.ts index df9884d2038f..205b2dfc9004 100644 --- a/src/libs/langchain/loaders/index.ts +++ b/src/libs/langchain/loaders/index.ts @@ -61,7 +61,7 @@ export class ChunkingLoader { default: { throw new Error( - 'Unsupported file type, please check your file is a supported type, or just create an issue.', + `Unsupported file type [${type}], please check your file is supported, or create report issue here: https://github.com/lobehub/lobe-chat/discussions/3550`, ); } }