Skip to content

Commit 6bf12df

Browse files
committed
feat: update addition feature storage and frontend features
1 parent 9f41572 commit 6bf12df

14 files changed

+33
-15
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ screenshot
1515
config.yaml
1616
config.dev.yaml
1717

18+
# current in ~/storage
1819
addition/generation/data/*
1920
!addition/generation/data/.gitkeep
2021

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ _🚀 **Next Generation AI One-Stop Solution**_
145145
-p 8000:8094 \
146146
-v ~/config:/config \
147147
-v ~/logs:/logs \
148+
-v ~/storage:/storage \
148149
-e MYSQL_HOST=localhost \
149150
-e MYSQL_PORT=3306 \
150151
-e MYSQL_DATABASE=chatnio \
@@ -160,7 +161,7 @@ _🚀 **Next Generation AI One-Stop Solution**_
160161
> - *-p 8000:8094* 指映射宿主机端口为 8000, 可自行修改冒号前的端口号
161162
> - SECRET: JWT 密钥, 自行生成随机字符串修改
162163
> - SERVE_STATIC: 是否启用静态文件服务 (正常情况下不需要更改此项, 详见下方常见问题解答)
163-
> - *-v ~/config:/config* *-v ~/logs:/logs* 指挂载配置文件和日志文件的宿主机目录, 可自行修改
164+
> - *-v ~/config:/config* 挂载配置文件, *-v ~/logs:/logs* 挂载日志文件的宿主机目录, *-v ~/storage:/storage* 挂载附加功能的生成文件
164165
> - 需配置 MySQL 和 Redis 服务, 请自行参考上方信息修改环境变量
165166

166167
版本更新 (_开启 Watchtower 后无需手动更新, 执行后按照上述步骤重新运行即可_):

addition/article/api.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ type WebsocketArticleResponse struct {
2525
func ProjectTarDownloadAPI(c *gin.Context) {
2626
hash := strings.TrimSpace(c.Query("hash"))
2727
c.Writer.Header().Add("Content-Disposition", "attachment; filename=article.tar.gz")
28-
c.File(fmt.Sprintf("addition/article/data/out/%s.tar.gz", hash))
28+
c.File(fmt.Sprintf("storage/article/%s.tar.gz", hash))
2929
}
3030

3131
func ProjectZipDownloadAPI(c *gin.Context) {
3232
hash := strings.TrimSpace(c.Query("hash"))
3333
c.Writer.Header().Add("Content-Disposition", "attachment; filename=article.zip")
34-
c.File(fmt.Sprintf("addition/article/data/out/%s.zip", hash))
34+
c.File(fmt.Sprintf("storage/article/%s.zip", hash))
3535
}
3636

3737
func GenerateAPI(c *gin.Context) {

addition/article/generate.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func CreateWorker(c *gin.Context, user *auth.User, model string, prompt string,
7575

7676
hook(StreamProgressResponse{Current: current, Total: total, Quota: 0})
7777

78-
path := fmt.Sprintf("addition/article/data/%s", hash)
79-
if _, _, err := utils.GenerateCompressTask(hash, "addition/article/data/out", path, path); err != nil {
78+
path := fmt.Sprintf("storage/article/data/%s", hash)
79+
if _, _, err := utils.GenerateCompressTask(hash, "storage/article", path, path); err != nil {
8080
globals.Debug(fmt.Sprintf("[article] error during generate compress task: %s", err.Error()))
8181
return ""
8282
}

addition/article/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func GenerateDocxFile(target, title, content string) error {
3030
}
3131

3232
func CreateArticleFile(hash, title, content string) string {
33-
target := fmt.Sprintf("addition/article/data/%s/%s.docx", hash, title)
33+
target := fmt.Sprintf("storage/article/data/%s/%s.docx", hash, title)
3434
utils.FileDirSafe(target)
3535
if err := GenerateDocxFile(target, title, content); err != nil {
3636
globals.Debug(fmt.Sprintf("[article] error during generate article %s: %s", title, err.Error()))

addition/generation/api.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ type WebsocketGenerationForm struct {
1818
func ProjectTarDownloadAPI(c *gin.Context) {
1919
hash := strings.TrimSpace(c.Query("hash"))
2020
c.Writer.Header().Add("Content-Disposition", "attachment; filename=code.tar.gz")
21-
c.File(fmt.Sprintf("addition/generation/data/out/%s.tar.gz", hash))
21+
c.File(fmt.Sprintf("storage/generation/%s.tar.gz", hash))
2222
}
2323

2424
func ProjectZipDownloadAPI(c *gin.Context) {
2525
hash := strings.TrimSpace(c.Query("hash"))
2626
c.Writer.Header().Add("Content-Disposition", "attachment; filename=code.zip")
27-
c.File(fmt.Sprintf("addition/generation/data/out/%s.zip", hash))
27+
c.File(fmt.Sprintf("storage/generation/%s.zip", hash))
2828
}
2929

3030
func GenerateAPI(c *gin.Context) {

addition/generation/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func GetFolder(hash string) string {
10-
return fmt.Sprintf("addition/generation/data/%s", hash)
10+
return fmt.Sprintf("storage/generation/data/%s", hash)
1111
}
1212

1313
func GetFolderByHash(model string, prompt string) (string, string) {

addition/generation/generate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func CreateGenerationWithCache(group, model, prompt string, hook func(buffer *ut
1515
}
1616
}
1717

18-
if _, _, err := utils.GenerateCompressTask(hash, "addition/generation/data/out", path, path); err != nil {
18+
if _, _, err := utils.GenerateCompressTask(hash, "storage/generation", path, path); err != nil {
1919
return "", fmt.Errorf("error during generate compress task: %s", err.Error())
2020
}
2121

app/src/components/Markdown.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,10 @@ function MarkdownContent({
246246
<DialogClose asChild>
247247
<Button variant={`outline`}>{t("cancel")}</Button>
248248
</DialogClose>
249-
<DialogClose onClick={async () => await sendAction(message)} asChild>
249+
<DialogClose
250+
onClick={async () => await sendAction(message)}
251+
asChild
252+
>
250253
<Button variant={`default`}>{t("confirm")}</Button>
251254
</DialogClose>
252255
</DialogFooter>

app/src/routes/Article.tsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "@/assets/pages/article.less";
22
import { Button } from "@/components/ui/button.tsx";
33
import router from "@/router.tsx";
4-
import { Check, ChevronLeft, Files, Globe, Loader2 } from "lucide-react";
4+
import { Check, ChevronLeft, Cloud, Files, Globe, Loader2 } from "lucide-react";
55
import { Textarea } from "@/components/ui/textarea.tsx";
66
import { useTranslation } from "react-i18next";
77
import { useDispatch, useSelector } from "react-redux";
@@ -31,7 +31,7 @@ type ProgressProps = {
3131
total: number;
3232
};
3333

34-
function GenerateProgress({ current, total }: ProgressProps) {
34+
function GenerateProgress({ current, total, quota }: ProgressProps & { quota: number }) {
3535
const { t } = useTranslation();
3636

3737
return (
@@ -56,6 +56,12 @@ function GenerateProgress({ current, total }: ProgressProps) {
5656
)}
5757
</p>
5858
<Progress value={(100 * current) / total} />
59+
<div
60+
className={`article-quota flex flex-row mt-4 border border-input rounded-md py-1 px-3 select-none w-max items-center mx-auto`}
61+
>
62+
<Cloud className={`h-4 w-4 mr-2`} />
63+
<p>{quota.toFixed(2)}</p>
64+
</div>
5965
</div>
6066
);
6167
}
@@ -72,13 +78,15 @@ function ArticleContent() {
7278
const [progress, setProgress] = useState(false);
7379

7480
const [state, setState] = useState<ProgressProps>({ current: 0, total: 0 });
81+
const [quota, setQuota] = useState<number>(0);
7582
const [hash, setHash] = useState("");
7683

7784
function clear() {
7885
setPrompt("");
7986
setTitle("");
8087
setHash("");
8188
setProgress(false);
89+
setQuota(0);
8290
setState({ current: 0, total: 0 });
8391
}
8492

@@ -100,6 +108,8 @@ function ArticleContent() {
100108

101109
connection.onmessage = (e) => {
102110
const data = JSON.parse(e.data);
111+
112+
data.data && data.data.quota && setQuota(quota + data.data.quota);
103113
if (!data.hash) setState(data.data as ProgressProps);
104114
else {
105115
toast({
@@ -123,7 +133,7 @@ function ArticleContent() {
123133

124134
return progress ? (
125135
<>
126-
<GenerateProgress {...state} />
136+
<GenerateProgress {...state} quota={quota} />
127137
{hash && (
128138
<div className={`article-action flex flex-row items-center my-4 gap-4`}>
129139
<Button

app/src/routes/Generation.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function Wrapper({ onSend }: WrapperProps) {
101101
{quota > 0 && (
102102
<div className={`quota-box`}>
103103
<Cloud className={`h-4 w-4 mr-2`} />
104-
{quota}
104+
{quota.toFixed(2)}
105105
</div>
106106
)}
107107
<pre className={`message-box`}>

docker-compose.stable.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ services:
5656
volumes:
5757
- ./config:/config
5858
- ./logs:/logs
59+
- ./storage:/storage
5960
networks:
6061
- chatnio-network
6162

docker-compose.watch.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ services:
5656
volumes:
5757
- ./config:/config
5858
- ./logs:/logs
59+
- ./storage:/storage
5960
networks:
6061
- chatnio-network
6162

docker-compose.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ services:
5656
volumes:
5757
- ./config:/config
5858
- ./logs:/logs
59+
- ./storage:/storage
5960
networks:
6061
- chatnio-network
6162

0 commit comments

Comments
 (0)