From b6049e28ffe8449d4ca5fe3f878a704a86fb99fe Mon Sep 17 00:00:00 2001 From: Zhang Minghan Date: Thu, 4 Jan 2024 18:13:02 +0800 Subject: [PATCH] feat: refresh api key feature and image file preview feature --- admin/statistic.go | 1 + app/src-tauri/tauri.conf.json | 2 +- app/src/assets/markdown/all.less | 19 +++++++++++++++++-- app/src/components/plugins/file.tsx | 15 +++++++++++++-- app/src/conf.ts | 2 +- app/src/dialogs/ApikeyDialog.tsx | 9 ++++++++- app/src/utils/dom.ts | 4 +++- middleware/throttle.go | 2 -- utils/config.go | 6 ++++++ 9 files changed, 50 insertions(+), 10 deletions(-) diff --git a/admin/statistic.go b/admin/statistic.go index af0b3f0b..08385715 100644 --- a/admin/statistic.go +++ b/admin/statistic.go @@ -32,5 +32,6 @@ func AnalysisRequest(model string, buffer *utils.Buffer, err error) { return } + IncrRequest(instance) IncrModelRequest(instance, model, int64(buffer.CountToken())) } diff --git a/app/src-tauri/tauri.conf.json b/app/src-tauri/tauri.conf.json index 7ff2ea17..0d2e3d58 100644 --- a/app/src-tauri/tauri.conf.json +++ b/app/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "chatnio", - "version": "3.8.0" + "version": "3.8.1" }, "tauri": { "allowlist": { diff --git a/app/src/assets/markdown/all.less b/app/src/assets/markdown/all.less index a2f2aa70..613d6eeb 100644 --- a/app/src/assets/markdown/all.less +++ b/app/src/assets/markdown/all.less @@ -5,8 +5,7 @@ .file-instance { cursor: pointer; display: flex; - flex-direction: row; - align-items: center; + flex-direction: column; margin: 2px 0 !important; margin-bottom: 4px !important; padding: 6px 12px !important; @@ -14,6 +13,22 @@ background: hsla(var(--background-container)) !important; border-radius: var(--radius); + .file-content { + background: none !important; + display: flex; + flex-direction: row; + align-items: center; + flex-wrap: wrap; + } + + img { + max-width: 320px; + max-height: 240px; + object-fit: cover; + border-radius: var(--radius); + margin: 0.25rem 0; + } + @media (max-width: 668px) { & { white-space: pre-wrap; diff --git a/app/src/components/plugins/file.tsx b/app/src/components/plugins/file.tsx index e346624e..be229262 100644 --- a/app/src/components/plugins/file.tsx +++ b/app/src/components/plugins/file.tsx @@ -1,5 +1,6 @@ import { File } from "lucide-react"; import { saveAsFile } from "@/utils/dom.ts"; +import { useMemo } from "react"; /** * file format: @@ -12,6 +13,13 @@ import { saveAsFile } from "@/utils/dom.ts"; export function parseFile(data: string) { const filename = data.split("\n")[0].replace("[[", "").replace("]]", ""); const content = data.replace(`[[${filename}]]\n`, ""); + const image = useMemo(() => { + // get image url from content (like: https://i.imgur.com/xxxxx.png) + const match = content + .toLowerCase() + .match(/(https?:\/\/.*\.(?:png|jpg|jpeg|gif))/); + return match ? match[0] : ""; + }, [filename, content]); return (
- - {filename} +
+ + {filename} +
+ {image && {""}}
); } diff --git a/app/src/conf.ts b/app/src/conf.ts index f8029273..5b8a92b9 100644 --- a/app/src/conf.ts +++ b/app/src/conf.ts @@ -14,7 +14,7 @@ import React from "react"; import { syncSiteInfo } from "@/admin/api/info.ts"; import { loadPreferenceModels } from "@/utils/storage.ts"; -export const version = "3.8.0-rc"; +export const version = "3.8.1"; export const dev: boolean = getDev(); export const deploy: boolean = true; export let rest_api: string = getRestApi(deploy); diff --git a/app/src/dialogs/ApikeyDialog.tsx b/app/src/dialogs/ApikeyDialog.tsx index 34b0dce8..63acbdc5 100644 --- a/app/src/dialogs/ApikeyDialog.tsx +++ b/app/src/dialogs/ApikeyDialog.tsx @@ -18,7 +18,7 @@ import { getApiKey, } from "@/store/api.ts"; import { Input } from "@/components/ui/input.tsx"; -import { Copy, ExternalLink } from "lucide-react"; +import { Copy, ExternalLink, RotateCw } from "lucide-react"; import { useToast } from "@/components/ui/use-toast.ts"; import { copyClipboard } from "@/utils/dom.ts"; import { useEffectAsync } from "@/utils/hook.ts"; @@ -53,6 +53,13 @@ function ApikeyDialog() {
+