From fd8d0a1746adc3c337ba9bb9dcefe525d7a19d40 Mon Sep 17 00:00:00 2001 From: butterfly Date: Fri, 12 Apr 2024 14:20:15 +0800 Subject: [PATCH 1/7] feat: fix the logtics of client joining webdav url --- app/utils/cloud/webdav.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/utils/cloud/webdav.ts b/app/utils/cloud/webdav.ts index f7d48dd03..5b0f3b123 100644 --- a/app/utils/cloud/webdav.ts +++ b/app/utils/cloud/webdav.ts @@ -75,7 +75,7 @@ export function createWebDavClient(store: SyncStore) { } let url; - if (proxyUrl.length > 0 || proxyUrl === "/") { + if (proxyUrl.length > 0) { let u = new URL(proxyUrl + "api/webdav/" + path); // add query params u.searchParams.append("endpoint", config.endpoint); From fb8b8d28da3174e134dc2551f1a97f2fdab27d1d Mon Sep 17 00:00:00 2001 From: butterfly Date: Tue, 16 Apr 2024 14:50:48 +0800 Subject: [PATCH 2/7] feat: (1) fix issues/4335 and issues/4518 --- app/client/platforms/anthropic.ts | 6 +++++- app/client/platforms/google.ts | 8 +++++++- app/client/platforms/openai.ts | 26 +++++++++++++++----------- app/utils/cloud/webdav.ts | 18 +++++++++--------- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/app/client/platforms/anthropic.ts b/app/client/platforms/anthropic.ts index fea3d8654..ba07dcc76 100644 --- a/app/client/platforms/anthropic.ts +++ b/app/client/platforms/anthropic.ts @@ -348,7 +348,11 @@ export class ClaudeApi implements LLMApi { path(path: string): string { const accessStore = useAccessStore.getState(); - let baseUrl: string = accessStore.anthropicUrl; + let baseUrl: string = ""; + + if (accessStore.useCustomConfig) { + baseUrl = accessStore.anthropicUrl; + } // if endpoint is empty, use default endpoint if (baseUrl.trim().length === 0) { diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index 848e5cd3f..16fcc7d51 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -104,7 +104,13 @@ export class GeminiProApi implements LLMApi { }; const accessStore = useAccessStore.getState(); - let baseUrl = accessStore.googleUrl; + + let baseUrl = ""; + + if (accessStore.useCustomConfig) { + baseUrl = accessStore.googleUrl; + } + const isApp = !!getClientConfig()?.isApp; let shouldStream = !!options.config.stream; diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 7652ba0f2..ca8bc2ebe 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -60,16 +60,24 @@ export class ChatGPTApi implements LLMApi { path(path: string): string { const accessStore = useAccessStore.getState(); - const isAzure = accessStore.provider === ServiceProvider.Azure; + let baseUrl = ""; - if (isAzure && !accessStore.isValidAzure()) { - throw Error( - "incomplete azure config, please check it in your settings page", - ); + if (accessStore.useCustomConfig) { + const isAzure = accessStore.provider === ServiceProvider.Azure; + + if (isAzure && !accessStore.isValidAzure()) { + throw Error( + "incomplete azure config, please check it in your settings page", + ); + } + + if (isAzure) { + path = makeAzurePath(path, accessStore.azureApiVersion); + } + + baseUrl = isAzure ? accessStore.azureUrl : accessStore.openaiUrl; } - let baseUrl = isAzure ? accessStore.azureUrl : accessStore.openaiUrl; - if (baseUrl.length === 0) { const isApp = !!getClientConfig()?.isApp; baseUrl = isApp @@ -84,10 +92,6 @@ export class ChatGPTApi implements LLMApi { baseUrl = "https://" + baseUrl; } - if (isAzure) { - path = makeAzurePath(path, accessStore.azureApiVersion); - } - console.log("[Proxy Endpoint] ", baseUrl, path); return [baseUrl, path].join("/"); diff --git a/app/utils/cloud/webdav.ts b/app/utils/cloud/webdav.ts index 5b0f3b123..0ca781b75 100644 --- a/app/utils/cloud/webdav.ts +++ b/app/utils/cloud/webdav.ts @@ -63,26 +63,26 @@ export function createWebDavClient(store: SyncStore) { }; }, path(path: string, proxyUrl: string = "") { - // if (!path.endsWith("/")) { - // path += "/"; - // } if (path.startsWith("/")) { path = path.slice(1); } - if (proxyUrl.length > 0 && !proxyUrl.endsWith("/")) { - proxyUrl += "/"; + if (proxyUrl.endsWith("/")) { + proxyUrl = proxyUrl.slice(0, -1); } let url; - if (proxyUrl.length > 0) { - let u = new URL(proxyUrl + "api/webdav/" + path); + const pathPrefix = "/api/webdav/"; + + try { + let u = new URL(proxyUrl + pathPrefix + path); // add query params u.searchParams.append("endpoint", config.endpoint); url = u.toString(); - } else { - url = "/api/upstash/" + path + "?endpoint=" + config.endpoint; + } catch (e) { + url = pathPrefix + path + "?endpoint=" + config.endpoint; } + return url; }, }; From cd68a0135e7dd53ae065e2bbba2b66264ee0a6ed Mon Sep 17 00:00:00 2001 From: sijinhui Date: Sun, 21 Apr 2024 23:57:13 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=BE=AE=E8=B0=83=EF=BC=8C=E6=9A=82?= =?UTF-8?q?=E4=B8=8D=E5=8F=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/auth.ts | 8 ++++++-- prisma/schema.prisma | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/auth.ts b/lib/auth.ts index e58227197..25c022589 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -29,6 +29,9 @@ export const authOptions: NextAuthOptions = { image: profile.avatar_url, }; }, + httpOptions: { + timeout: 50000, + } }), EmailProvider({ server: { @@ -152,11 +155,12 @@ export const authOptions: NextAuthOptions = { // console.log('555555555,', session, token) return session; }, - // 过滤不存在的用户,目前没用 + // 过滤不存在的用户 async signIn({ user, account, profile, email, credentials }) { const existingUser = await existUser(user as User); console.log('---', user, 'account', account, 'email', email, 'exist', existingUser) - return !!existingUser; + // 顺便过滤掉不允许登录的用户 + return !!existingUser && existingUser.allowToLogin; } }, }; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 59f94bb03..e5b40d003 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -24,6 +24,7 @@ model User { password String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt + allowToLogin Boolean @default(true) accounts Account[] sessions Session[] // sites Site[] From ba2fc279281fb138804e01bf4474f72cd0afc41d Mon Sep 17 00:00:00 2001 From: sijinhui Date: Mon, 22 Apr 2024 16:13:54 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/admin/users/[[...path]]/route.ts | 1 + .../20240422081322_allowlogin/migration.sql | 107 ++++++++++++++++++ prisma/migrations/migration_lock.toml | 3 + 3 files changed, 111 insertions(+) create mode 100644 prisma/migrations/20240422081322_allowlogin/migration.sql create mode 100644 prisma/migrations/migration_lock.toml diff --git a/app/api/admin/users/[[...path]]/route.ts b/app/api/admin/users/[[...path]]/route.ts index 4a53239f0..b206c595c 100644 --- a/app/api/admin/users/[[...path]]/route.ts +++ b/app/api/admin/users/[[...path]]/route.ts @@ -64,6 +64,7 @@ async function handle( emailVerified: item.emailVerified, createdAt: item.createdAt, updatedAt: item.updatedAt, + allowToLogin: item.allowToLogin, }; }), }); diff --git a/prisma/migrations/20240422081322_allowlogin/migration.sql b/prisma/migrations/20240422081322_allowlogin/migration.sql new file mode 100644 index 000000000..cb65526c7 --- /dev/null +++ b/prisma/migrations/20240422081322_allowlogin/migration.sql @@ -0,0 +1,107 @@ +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL, + "name" TEXT, + "username" TEXT, + "gh_username" TEXT, + "email" TEXT, + "emailVerified" TIMESTAMP(3), + "image" TEXT, + "password" TEXT, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + "allowToLogin" BOOLEAN NOT NULL DEFAULT true, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Account" ( + "id" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "type" TEXT NOT NULL, + "provider" TEXT NOT NULL, + "providerAccountId" TEXT NOT NULL, + "refresh_token" TEXT, + "refresh_token_expires_in" INTEGER, + "access_token" TEXT, + "expires_at" INTEGER, + "token_type" TEXT, + "scope" TEXT, + "id_token" TEXT, + "session_state" TEXT, + "oauth_token_secret" TEXT, + "oauth_token" TEXT, + + CONSTRAINT "Account_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Session" ( + "id" TEXT NOT NULL, + "sessionToken" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "expires" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "Session_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "LogEntry" ( + "id" SERIAL NOT NULL, + "ip" VARCHAR(25), + "path" TEXT, + "model" VARCHAR(25), + "userName" VARCHAR(50), + "userID" TEXT, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "logToken" INTEGER DEFAULT 0, + + CONSTRAINT "LogEntry_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "VerificationToken" ( + "identifier" TEXT NOT NULL, + "token" TEXT NOT NULL, + "expires" TIMESTAMP(3) NOT NULL +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_name_key" ON "User"("name"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_gh_username_key" ON "User"("gh_username"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- CreateIndex +CREATE INDEX "Account_userId_idx" ON "Account"("userId"); + +-- CreateIndex +CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId"); + +-- CreateIndex +CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken"); + +-- CreateIndex +CREATE INDEX "Session_userId_idx" ON "Session"("userId"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token"); + +-- AddForeignKey +ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "LogEntry" ADD CONSTRAINT "LogEntry_userID_fkey" FOREIGN KEY ("userID") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 000000000..fbffa92c2 --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "postgresql" \ No newline at end of file From 97d34a3ff030bb851df94074643fcc91ecd3a3c2 Mon Sep 17 00:00:00 2001 From: sijinhui Date: Mon, 22 Apr 2024 16:16:26 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E7=B4=A7=E5=8F=8A=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20240422081322_allowlogin/migration.sql | 107 ------------------ 1 file changed, 107 deletions(-) delete mode 100644 prisma/migrations/20240422081322_allowlogin/migration.sql diff --git a/prisma/migrations/20240422081322_allowlogin/migration.sql b/prisma/migrations/20240422081322_allowlogin/migration.sql deleted file mode 100644 index cb65526c7..000000000 --- a/prisma/migrations/20240422081322_allowlogin/migration.sql +++ /dev/null @@ -1,107 +0,0 @@ --- CreateTable -CREATE TABLE "User" ( - "id" TEXT NOT NULL, - "name" TEXT, - "username" TEXT, - "gh_username" TEXT, - "email" TEXT, - "emailVerified" TIMESTAMP(3), - "image" TEXT, - "password" TEXT, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL, - "allowToLogin" BOOLEAN NOT NULL DEFAULT true, - - CONSTRAINT "User_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Account" ( - "id" TEXT NOT NULL, - "userId" TEXT NOT NULL, - "type" TEXT NOT NULL, - "provider" TEXT NOT NULL, - "providerAccountId" TEXT NOT NULL, - "refresh_token" TEXT, - "refresh_token_expires_in" INTEGER, - "access_token" TEXT, - "expires_at" INTEGER, - "token_type" TEXT, - "scope" TEXT, - "id_token" TEXT, - "session_state" TEXT, - "oauth_token_secret" TEXT, - "oauth_token" TEXT, - - CONSTRAINT "Account_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Session" ( - "id" TEXT NOT NULL, - "sessionToken" TEXT NOT NULL, - "userId" TEXT NOT NULL, - "expires" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "Session_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "LogEntry" ( - "id" SERIAL NOT NULL, - "ip" VARCHAR(25), - "path" TEXT, - "model" VARCHAR(25), - "userName" VARCHAR(50), - "userID" TEXT, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "logToken" INTEGER DEFAULT 0, - - CONSTRAINT "LogEntry_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "VerificationToken" ( - "identifier" TEXT NOT NULL, - "token" TEXT NOT NULL, - "expires" TIMESTAMP(3) NOT NULL -); - --- CreateIndex -CREATE UNIQUE INDEX "User_name_key" ON "User"("name"); - --- CreateIndex -CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); - --- CreateIndex -CREATE UNIQUE INDEX "User_gh_username_key" ON "User"("gh_username"); - --- CreateIndex -CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); - --- CreateIndex -CREATE INDEX "Account_userId_idx" ON "Account"("userId"); - --- CreateIndex -CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId"); - --- CreateIndex -CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken"); - --- CreateIndex -CREATE INDEX "Session_userId_idx" ON "Session"("userId"); - --- CreateIndex -CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token"); - --- CreateIndex -CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token"); - --- AddForeignKey -ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "LogEntry" ADD CONSTRAINT "LogEntry_userID_fkey" FOREIGN KEY ("userID") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; From 9286624ea27e0c6e362b1cffbbc469c6e78fec91 Mon Sep 17 00:00:00 2001 From: sijinhui Date: Mon, 22 Apr 2024 16:16:47 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E7=B4=A7=E5=8F=8A=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prisma/migrations/migration_lock.toml | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 prisma/migrations/migration_lock.toml diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml deleted file mode 100644 index fbffa92c2..000000000 --- a/prisma/migrations/migration_lock.toml +++ /dev/null @@ -1,3 +0,0 @@ -# Please do not edit this file manually -# It should be added in your version-control system (i.e. Git) -provider = "postgresql" \ No newline at end of file From ff7ecbf3b97834d8dc5ca927fa9078bd106dd5b6 Mon Sep 17 00:00:00 2001 From: sijinhui Date: Mon, 22 Apr 2024 17:49:53 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E4=B8=80=E7=82=B9=E7=82=B9=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app/(admin)/components/users-table.tsx | 16 +++++++++++++++- app/app/login.scss | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/app/(admin)/components/users-table.tsx b/app/app/(admin)/components/users-table.tsx index 203185294..f6226899e 100644 --- a/app/app/(admin)/components/users-table.tsx +++ b/app/app/(admin)/components/users-table.tsx @@ -10,6 +10,7 @@ import { Button, notification, Popconfirm, + Checkbox, } from "antd"; import type { GetRef, TableColumnsType } from "antd"; // import { headers } from 'next/headers' @@ -187,6 +188,18 @@ function UsersTable({ users, setUsers, loading }: UserInterface) { dataIndex: "updatedAt", render: (value) => getCurrentTime(new Date(value)), }, + { + title: "allowToLogin", + dataIndex: "allowToLogin", + width: 120, + render: (value) => { + return ( +
+ +
+ ); + }, + }, { title: "Action", dataIndex: "", @@ -195,7 +208,8 @@ function UsersTable({ users, setUsers, loading }: UserInterface) { {contextHolder}