From 849c833c6f874ac809b2f2dbcf06dc62b7fce3ee Mon Sep 17 00:00:00 2001 From: Zhang Minghan Date: Sun, 10 Dec 2023 16:58:16 +0800 Subject: [PATCH] feat: update ui --- app/src-tauri/tauri.conf.json | 2 +- app/src/assets/globals.less | 8 ++++---- app/src/assets/pages/home.less | 2 +- app/src/components/app/NavBar.tsx | 3 ++- app/src/components/home/SideBar.tsx | 3 ++- app/src/components/home/subscription/BuyDialog.tsx | 5 +++-- app/src/conf.ts | 8 ++++++-- app/src/dialogs/PackageDialog.tsx | 3 ++- app/src/dialogs/QuotaDialog.tsx | 7 +++---- app/src/routes/Sharing.tsx | 6 ++---- app/src/utils/env.ts | 5 +++++ auth/call.go | 6 +++++- auth/cert.go | 2 +- auth/payment.go | 4 ++-- utils/cache.go | 3 ++- 15 files changed, 41 insertions(+), 26 deletions(-) diff --git a/app/src-tauri/tauri.conf.json b/app/src-tauri/tauri.conf.json index 8aa353aa..104b6879 100644 --- a/app/src-tauri/tauri.conf.json +++ b/app/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "chatnio", - "version": "3.7.3" + "version": "3.7.4" }, "tauri": { "allowlist": { diff --git a/app/src/assets/globals.less b/app/src/assets/globals.less index e7aa49b8..075afe1d 100644 --- a/app/src/assets/globals.less +++ b/app/src/assets/globals.less @@ -10,8 +10,8 @@ --foreground: 240 10% 3.9%; --card: 0 0% 100%; - --card-hover: 0 0% 97.5%; - --card-active: 0 0% 95%; + --card-hover: 0 0% 97%; + --card-active: 0 0% 94.5%; --card-foreground: 240 10% 3.9%; --popover: 0 0% 100%; @@ -68,8 +68,8 @@ --foreground: 210 40% 98%; --card: 240 10% 3.9%; - --card-hover: 240 10% 8.9%; - --card-active: 240 10% 13.9%; + --card-hover: 240 11% 12.5%; + --card-active: 240 9.5% 19%; --card-foreground: 0 0% 98%; --popover: 240 10% 3.9%; diff --git a/app/src/assets/pages/home.less b/app/src/assets/pages/home.less index cd6e34ae..878e1e50 100644 --- a/app/src/assets/pages/home.less +++ b/app/src/assets/pages/home.less @@ -413,7 +413,7 @@ } &.active { - background: hsl(var(--card-hover)); + background: hsl(var(--card-active)); border-color: hsl(var(--border-active)); } } diff --git a/app/src/components/app/NavBar.tsx b/app/src/components/app/NavBar.tsx index 96d1a2ee..b83137e6 100644 --- a/app/src/components/app/NavBar.tsx +++ b/app/src/components/app/NavBar.tsx @@ -16,6 +16,7 @@ import ModeToggle from "@/components/ThemeProvider.tsx"; import router from "@/router.tsx"; import MenuBar from "./MenuBar.tsx"; import { getMemory } from "@/utils/memory.ts"; +import { deeptrainApiEndpoint } from "@/utils/env.ts"; function NavMenu() { const username = useSelector(selectUsername); @@ -24,7 +25,7 @@ function NavMenu() {
diff --git a/app/src/components/home/SideBar.tsx b/app/src/components/home/SideBar.tsx index 924195b0..da6dff18 100644 --- a/app/src/components/home/SideBar.tsx +++ b/app/src/components/home/SideBar.tsx @@ -42,6 +42,7 @@ import { Input } from "@/components/ui/input.tsx"; import { login } from "@/conf.ts"; import MenuBar from "@/components/app/MenuBar.tsx"; import { Separator } from "@/components/ui/separator.tsx"; +import { deeptrainApiEndpoint } from "@/utils/env.ts"; type Operation = { target: ConversationInstance | null; @@ -329,7 +330,7 @@ function SidebarMenu() { diff --git a/app/src/components/home/subscription/BuyDialog.tsx b/app/src/components/home/subscription/BuyDialog.tsx index f843da62..6f2ef22b 100644 --- a/app/src/components/home/subscription/BuyDialog.tsx +++ b/app/src/components/home/subscription/BuyDialog.tsx @@ -25,6 +25,7 @@ import { expiredSelector, refreshSubscription } from "@/store/subscription.ts"; import { Plus } from "lucide-react"; import { subscriptionPrize } from "@/conf.ts"; import { ToastAction } from "@/components/ui/toast.tsx"; +import { deeptrainEndpoint } from "@/utils/env.ts"; function countPrize(base: number, month: number): number { const prize = subscriptionPrize[base] * month; @@ -74,14 +75,14 @@ async function callBuyAction( action: ( (location.href = "https://deeptrain.net/home/wallet")} + onClick={() => (location.href = `${deeptrainEndpoint}/home/wallet`)} > {t("buy.go")} ), }); setTimeout(() => { - window.open("https://deeptrain.net/home/wallet"); + window.open(`${deeptrainEndpoint}/home/wallet`); }, 2000); } return res.status; diff --git a/app/src/conf.ts b/app/src/conf.ts index 4c2ec63d..ae587001 100644 --- a/app/src/conf.ts +++ b/app/src/conf.ts @@ -1,6 +1,8 @@ import axios from "axios"; import { Model, PlanModel } from "@/api/types.ts"; import { + deeptrainAppName, + deeptrainEndpoint, getDev, getRestApi, getTokenField, @@ -8,7 +10,7 @@ import { } from "@/utils/env.ts"; import { getMemory } from "@/utils/memory.ts"; -export const version = "3.7.3"; +export const version = "3.7.4"; export const dev: boolean = getDev(); export const deploy: boolean = true; export let rest_api: string = getRestApi(deploy); @@ -417,7 +419,9 @@ export const subscriptionPrize: Record = { }; export function login() { - location.href = `https://deeptrain.net/login?app=${dev ? "dev" : "chatnio"}`; + location.href = `${deeptrainEndpoint}/login?app=${ + dev ? "dev" : deeptrainAppName + }`; } axios.defaults.baseURL = rest_api; diff --git a/app/src/dialogs/PackageDialog.tsx b/app/src/dialogs/PackageDialog.tsx index c179f077..22079223 100644 --- a/app/src/dialogs/PackageDialog.tsx +++ b/app/src/dialogs/PackageDialog.tsx @@ -23,6 +23,7 @@ import { Separator } from "@/components/ui/separator.tsx"; import { Badge } from "@/components/ui/badge.tsx"; import { useEffectAsync } from "@/utils/hook.ts"; import { selectAuthenticated } from "@/store/auth.ts"; +import { deeptrainEndpoint } from "@/utils/env.ts"; function PackageDialog() { const { t } = useTranslation(); @@ -77,7 +78,7 @@ function PackageDialog() { diff --git a/app/src/dialogs/QuotaDialog.tsx b/app/src/dialogs/QuotaDialog.tsx index 018ed1dd..a3f0eb5d 100644 --- a/app/src/dialogs/QuotaDialog.tsx +++ b/app/src/dialogs/QuotaDialog.tsx @@ -39,7 +39,7 @@ import { useToast } from "@/components/ui/use-toast.ts"; import { useEffectAsync } from "@/utils/hook.ts"; import { selectAuthenticated } from "@/store/auth.ts"; import { ToastAction } from "@/components/ui/toast.tsx"; -import { docsEndpoint } from "@/utils/env.ts"; +import { deeptrainEndpoint, docsEndpoint } from "@/utils/env.ts"; type AmountComponentProps = { amount: number; @@ -245,8 +245,7 @@ function QuotaDialog() { - (location.href = - "https://deeptrain.net/home/wallet") + (location.href = `${deeptrainEndpoint}/home/wallet`) } > {t("buy.go")} @@ -255,7 +254,7 @@ function QuotaDialog() { }); setTimeout(() => { window.open( - "https://deeptrain.net/home/wallet", + `${deeptrainEndpoint}/home/wallet`, ); }, 2000); } diff --git a/app/src/routes/Sharing.tsx b/app/src/routes/Sharing.tsx index be6ec55e..ea73aa59 100644 --- a/app/src/routes/Sharing.tsx +++ b/app/src/routes/Sharing.tsx @@ -12,6 +12,7 @@ import router from "@/router.tsx"; import { useToast } from "@/components/ui/use-toast.ts"; import { sharingEvent } from "@/events/sharing.ts"; import { Message } from "@/api/types.ts"; +import { deeptrainApiEndpoint } from "@/utils/env.ts"; type SharingFormProps = { refer?: string; @@ -32,10 +33,7 @@ function SharingForm({ refer, data }: SharingFormProps) {
- + {data.username}
{data.name}
diff --git a/app/src/utils/env.ts b/app/src/utils/env.ts index 1396f8c7..d87c3f15 100644 --- a/app/src/utils/env.ts +++ b/app/src/utils/env.ts @@ -4,6 +4,11 @@ export const blobEndpoint = import.meta.env.VITE_BLOB_ENDPOINT || "https://blob.chatnio.net"; export const docsEndpoint = import.meta.env.VITE_DOCS_ENDPOINT || "https://docs.chatnio.net"; +export const deeptrainEndpoint = + import.meta.env.VITE_DEEPTRAIN_ENDPOINT || "https://deeptrain.net"; +export const deeptrainAppName = import.meta.env.VITE_DEEPTRAIN_APP || "chatnio"; +export const deeptrainApiEndpoint = + import.meta.env.VITE_DEEPTRAIN_API_ENDPOINT || "https://api.deeptrain.net"; export function getDev(): boolean { /** diff --git a/auth/call.go b/auth/call.go index 63c6292f..9c2c86d2 100644 --- a/auth/call.go +++ b/auth/call.go @@ -12,8 +12,12 @@ type ValidateUserResponse struct { ID int `json:"id" required:"true"` } +func getDeeptrainApi(path string) string { + return viper.GetString("auth.endpoint") + path +} + func Validate(token string) *ValidateUserResponse { - res, err := utils.Post("https://api.deeptrain.net/app/validate", map[string]string{ + res, err := utils.Post(getDeeptrainApi("/app/validate"), map[string]string{ "Content-Type": "application/json", }, map[string]interface{}{ "password": viper.GetString("auth.access"), diff --git a/auth/cert.go b/auth/cert.go index b5c75747..31e8354f 100644 --- a/auth/cert.go +++ b/auth/cert.go @@ -13,7 +13,7 @@ type CertResponse struct { } func Cert(username string) *CertResponse { - res, err := utils.Post("https://api.deeptrain.net/app/cert", map[string]string{ + res, err := utils.Post(getDeeptrainApi("/app/cert"), map[string]string{ "Content-Type": "application/json", }, map[string]interface{}{ "password": viper.GetString("auth.access"), diff --git a/auth/payment.go b/auth/payment.go index 66d1eec8..15223004 100644 --- a/auth/payment.go +++ b/auth/payment.go @@ -25,7 +25,7 @@ func GenerateOrder() string { func GetBalance(username string) float32 { order := GenerateOrder() - res, err := utils.Post("https://api.deeptrain.net/app/balance", map[string]string{ + res, err := utils.Post(getDeeptrainApi("/app/balance"), map[string]string{ "Content-Type": "application/json", }, map[string]interface{}{ "password": viper.GetString("auth.access"), @@ -46,7 +46,7 @@ func GetBalance(username string) float32 { func Pay(username string, amount float32) bool { order := GenerateOrder() - res, err := utils.Post("https://api.deeptrain.net/app/payment", map[string]string{ + res, err := utils.Post(getDeeptrainApi("/app/payment"), map[string]string{ "Content-Type": "application/json", }, map[string]interface{}{ "password": viper.GetString("auth.access"), diff --git a/utils/cache.go b/utils/cache.go index 55f0721c..9d0e683b 100644 --- a/utils/cache.go +++ b/utils/cache.go @@ -2,6 +2,7 @@ package utils import ( "context" + "errors" "fmt" "github.com/go-redis/redis/v8" "time" @@ -47,7 +48,7 @@ func GetJson[T any](cache *redis.Client, key string) *T { func IncrWithLimit(cache *redis.Client, key string, delta int64, limit int64, expiration int64) bool { // not exist if _, err := cache.Get(context.Background(), key).Result(); err != nil { - if err == redis.Nil { + if errors.Is(err, redis.Nil) { cache.Set(context.Background(), key, delta, time.Duration(expiration)*time.Second) return true }