Skip to content

Commit

Permalink
feat: update ui
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Dec 10, 2023
1 parent 74fbb7d commit 849c833
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "chatnio",
"version": "3.7.3"
"version": "3.7.4"
},
"tauri": {
"allowlist": {
Expand Down
8 changes: 4 additions & 4 deletions app/src/assets/globals.less
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
Expand Down Expand Up @@ -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%;
Expand Down
2 changes: 1 addition & 1 deletion app/src/assets/pages/home.less
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@
}

&.active {
background: hsl(var(--card-hover));
background: hsl(var(--card-active));
border-color: hsl(var(--border-active));
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/components/app/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -24,7 +25,7 @@ function NavMenu() {
<div className={`avatar`}>
<MenuBar>
<Button variant={`ghost`} size={`icon`}>
<img src={`https://api.deeptrain.net/avatar/${username}`} alt="" />
<img src={`${deeptrainApiEndpoint}/avatar/${username}`} alt="" />
</Button>
</MenuBar>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/src/components/home/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -329,7 +330,7 @@ function SidebarMenu() {
<Separator orientation={`horizontal`} className={`mb-2`} />
<MenuBar className={`menu-bar`}>
<Button variant={`ghost`} className={`sidebar-wrapper`}>
<img src={`https://api.deeptrain.net/avatar/${username}`} alt="" />
<img src={`${deeptrainApiEndpoint}/avatar/${username}`} alt="" />
<span className={`username`}>{username}</span>
<MoreHorizontal className={`h-4 w-4`} />
</Button>
Expand Down
5 changes: 3 additions & 2 deletions app/src/components/home/subscription/BuyDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,14 +75,14 @@ async function callBuyAction(
action: (
<ToastAction
altText={t("buy.go")}
onClick={() => (location.href = "https://deeptrain.net/home/wallet")}
onClick={() => (location.href = `${deeptrainEndpoint}/home/wallet`)}
>
{t("buy.go")}
</ToastAction>
),
});
setTimeout(() => {
window.open("https://deeptrain.net/home/wallet");
window.open(`${deeptrainEndpoint}/home/wallet`);
}, 2000);
}
return res.status;
Expand Down
8 changes: 6 additions & 2 deletions app/src/conf.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import axios from "axios";
import { Model, PlanModel } from "@/api/types.ts";
import {
deeptrainAppName,
deeptrainEndpoint,
getDev,
getRestApi,
getTokenField,
getWebsocketApi,
} 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);
Expand Down Expand Up @@ -417,7 +419,9 @@ export const subscriptionPrize: Record<number, number> = {
};

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;
Expand Down
3 changes: 2 additions & 1 deletion app/src/dialogs/PackageDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -77,7 +78,7 @@ function PackageDialog() {
</Button>
<Button
variant={`default`}
onClick={() => window.open("https://deeptrain.net/home/package")}
onClick={() => window.open(`${deeptrainEndpoint}/home/package`)}
>
{t("pkg.go")}
</Button>
Expand Down
7 changes: 3 additions & 4 deletions app/src/dialogs/QuotaDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -245,8 +245,7 @@ function QuotaDialog() {
<ToastAction
altText={t("buy.go")}
onClick={() =>
(location.href =
"https://deeptrain.net/home/wallet")
(location.href = `${deeptrainEndpoint}/home/wallet`)
}
>
{t("buy.go")}
Expand All @@ -255,7 +254,7 @@ function QuotaDialog() {
});
setTimeout(() => {
window.open(
"https://deeptrain.net/home/wallet",
`${deeptrainEndpoint}/home/wallet`,
);
}, 2000);
}
Expand Down
6 changes: 2 additions & 4 deletions app/src/routes/Sharing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,10 +33,7 @@ function SharingForm({ refer, data }: SharingFormProps) {
<div className={`sharing-container`}>
<div className={`header`}>
<div className={`user`}>
<img
src={`https://api.deeptrain.net/avatar/${data.username}`}
alt=""
/>
<img src={`${deeptrainApiEndpoint}/avatar/${data.username}`} alt="" />
<span>{data.username}</span>
</div>
<div className={`name`}>{data.name}</div>
Expand Down
5 changes: 5 additions & 0 deletions app/src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
6 changes: 5 additions & 1 deletion auth/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion auth/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions auth/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down
3 changes: 2 additions & 1 deletion utils/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"context"
"errors"
"fmt"
"github.com/go-redis/redis/v8"
"time"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 849c833

Please sign in to comment.