Skip to content

Commit 1029521

Browse files
authored
Feat/v0.10.0 (#52)
1 parent 77b6942 commit 1029521

File tree

20 files changed

+530
-570
lines changed

20 files changed

+530
-570
lines changed

backend/pkg/webhook/message/qa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func NewQANeedReview(body commonDoc) Message {
7070
return &docMsg{
7171
Header: Header{
7272
MsgType: TypeQANeedReview,
73-
MsgTitle: "有新的问答对待审核",
73+
MsgTitle: "有新的问答等待审核",
7474
HeadingPrefix: "问题",
7575
},
7676
Doc: body,

backend/svc/discussion.go

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -575,35 +575,57 @@ func (d *Discussion) AcceptComment(ctx context.Context, user model.UserInfo, dis
575575
if disc.UserID != user.UID {
576576
return errors.New("not allowed to accept comment")
577577
}
578-
if disc.Resolved {
579-
return errors.New("discussion already resolved")
580-
}
581-
alreadyAccepted, err := d.in.CommRepo.Exist(ctx,
582-
repo.QueryWithEqual("discussion_id", disc.ID),
583-
repo.QueryWithEqual("accepted", true),
584-
)
578+
579+
comment, err := d.in.CommRepo.Detail(ctx, commentID)
585580
if err != nil {
586581
return err
587582
}
588-
if alreadyAccepted {
589-
return errors.New("comment already accepted")
583+
584+
if comment.Accepted {
585+
err = d.in.CommRepo.Update(ctx, map[string]any{
586+
"accepted": false,
587+
"accepted_at": gorm.Expr("null"),
588+
}, repo.QueryWithEqual("id", commentID))
589+
if err != nil {
590+
return err
591+
}
592+
593+
err = d.in.DiscRepo.Update(ctx, map[string]any{
594+
"resolved": false,
595+
"resolved_at": gorm.Expr("null"),
596+
}, repo.QueryWithEqual("id", disc.ID))
597+
if err != nil {
598+
return err
599+
}
600+
601+
return nil
590602
}
591-
comment, err := d.in.CommRepo.Detail(ctx, commentID)
603+
604+
err = d.in.CommRepo.Update(ctx, map[string]any{
605+
"accepted": false,
606+
"accepted_at": gorm.Expr("null"),
607+
}, repo.QueryWithEqual("discussion_id", disc.ID),
608+
repo.QueryWithEqual("accepted", true))
592609
if err != nil {
593610
return err
594611
}
612+
595613
if err := d.in.CommRepo.UpdateByModel(ctx, &model.Comment{
596614
Accepted: true,
597615
AcceptedAt: model.Timestamp(time.Now().Unix()),
598616
}, repo.QueryWithEqual("id", commentID)); err != nil {
599617
return err
600618
}
601-
if err := d.in.DiscRepo.Update(ctx, map[string]any{
602-
"resolved": true,
603-
"resolved_at": model.Timestamp(time.Now().Unix()),
604-
}, repo.QueryWithEqual("id", disc.ID)); err != nil {
605-
return err
619+
620+
if !disc.Resolved {
621+
if err := d.in.DiscRepo.Update(ctx, map[string]any{
622+
"resolved": true,
623+
"resolved_at": model.Timestamp(time.Now().Unix()),
624+
}, repo.QueryWithEqual("id", disc.ID)); err != nil {
625+
return err
626+
}
606627
}
628+
607629
notifyMsg := topic.MsgMessageNotify{
608630
DiscussID: disc.ID,
609631
ForumID: disc.ForumID,

backend/svc/llm.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,13 @@ func (l *LLM) Chat(ctx context.Context, sMsg string, uMsg string, params map[str
8383
return "", err
8484
}
8585
logger := l.logger.WithContext(ctx)
86-
template := prompt.FromMessages(schema.GoTemplate,
86+
templates := []schema.MessagesTemplate{
8787
schema.SystemMessage(sMsg),
88-
schema.UserMessage(uMsg),
89-
)
88+
}
89+
if uMsg != "" {
90+
templates = append(templates, schema.UserMessage(uMsg))
91+
}
92+
template := prompt.FromMessages(schema.GoTemplate, templates...)
9093
msgs, err := template.Format(ctx, params)
9194
if err != nil {
9295
return "", err

ui/admin/api-templates/http-client.ejs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
<%
22
const { apiConfig, generateResponses, config } = it;
33
%>
4+
/* eslint-disable */
5+
/* tslint:disable */
6+
// @ts-nocheck
7+
/*
8+
* ---------------------------------------------------------------
9+
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
10+
* ## ##
11+
* ## AUTHOR: acacode ##
12+
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
13+
* ---------------------------------------------------------------
14+
*/
15+
416
import { message } from "@ctzhian/ui";
517
import type {
618
AxiosInstance,
@@ -94,8 +106,7 @@ export enum ContentType {
94106
Text = "text/plain",
95107
}
96108

97-
type ExtractDataProp<T> = T extends { data?: infer U } ? U : T
98-
109+
type ExtractDataProp<T> = T extends { data?: infer U } ? U : T;
99110

100111
export class HttpClient<SecurityDataType = unknown> {
101112
public instance: AxiosInstance;
@@ -143,7 +154,7 @@ export class HttpClient<SecurityDataType = unknown> {
143154
return Promise.reject(error.response);
144155
},
145156
);
146-
}
157+
}
147158

148159
public setSecurityData = (data: SecurityDataType | null) => {
149160
this.securityData = data;

ui/admin/src/api/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export interface ModelForumInfo {
253253
group_ids?: number[];
254254
id?: number;
255255
index?: number;
256-
name?: string;
256+
name: string;
257257
route_name?: string;
258258
}
259259

ui/admin/src/components/editor/edit/Wrap.tsx

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ const EditorWrap = ({
9595
exclude: ['invisibleCharacters', 'youtube', 'mention', 'aiWriting'],
9696
immediatelyRender: false,
9797
onUpload: handleUpload,
98-
onFocus: () => {
99-
console.log('编辑器获得焦点');
100-
},
101-
onBlur: () => {
102-
console.log('编辑器失去焦点');
103-
},
104-
10598
});
10699

107100
// 这些函数需要在editorRef初始化后定义
@@ -138,59 +131,6 @@ const EditorWrap = ({
138131
setOriginalContent(value !== undefined ? value : detail?.content || '');
139132
}, [value, detail?.content, editorRef.editor]);
140133

141-
// 聚焦编辑器的函数
142-
const focusEditor = useCallback(() => {
143-
if (editorRef.editor) {
144-
editorRef.editor.commands.focus();
145-
// 将光标移到内容末尾
146-
const docSize = editorRef.editor.state.doc.content.size;
147-
editorRef.editor.commands.setTextSelection(docSize);
148-
}
149-
}, []);
150-
151-
// 编辑器加载后自动聚焦
152-
useEffect(() => {
153-
if (editorRef.editor && isMounted) {
154-
// 立即尝试聚焦
155-
focusEditor();
156-
157-
// 延时再次尝试,确保聚焦成功
158-
const timer1 = setTimeout(focusEditor, 100);
159-
const timer2 = setTimeout(focusEditor, 300);
160-
161-
return () => {
162-
clearTimeout(timer1);
163-
clearTimeout(timer2);
164-
};
165-
}
166-
}, [editorRef.editor, isMounted, focusEditor]);
167-
168-
// 监听组件可见性,当组件变为可见时聚焦编辑器
169-
useEffect(() => {
170-
if (!containerRef.current || !editorRef.editor) return;
171-
172-
const observer = new IntersectionObserver(
173-
entries => {
174-
entries.forEach(entry => {
175-
if (entry.isIntersecting && entry.intersectionRatio > 0.5) {
176-
// 当组件超过50%可见时,聚焦编辑器
177-
setTimeout(focusEditor, 100);
178-
}
179-
});
180-
},
181-
{
182-
threshold: [0.5], // 当50%可见时触发
183-
rootMargin: '0px',
184-
}
185-
);
186-
187-
observer.observe(containerRef.current);
188-
189-
return () => {
190-
observer.disconnect();
191-
};
192-
}, [containerRef.current, editorRef.editor, focusEditor]);
193-
194134
// 在服务端渲染时返回漂亮的占位符
195135
if (!isMounted) {
196136
return (
@@ -387,6 +327,7 @@ const EditorWrap = ({
387327
transition: 'all 0.3s ease',
388328
position: 'relative',
389329
overflow: 'hidden',
330+
wordBreak: 'break-all',
390331
cursor: 'text',
391332
'&::before': {
392333
content: '""',
@@ -398,7 +339,6 @@ const EditorWrap = ({
398339
transition: 'all 0.3s ease',
399340
},
400341
}}
401-
onClick={focusEditor}
402342
>
403343
{editorRef.editor ? (
404344
<Editor editor={editorRef.editor} />

ui/admin/src/pages/settings/component/Webhook.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const contentOptions = [
4242
{ value: 1, label: '点踩 AI 的回答' },
4343
{ value: 2, label: 'AI 无法解答问题' },
4444
{ value: 4, label: '有新的反馈' },
45-
// { value: 5, label: '有新的博客' },
45+
{ value: 6, label: '有新的回答等待审核' },
4646
];
4747

4848
// 定义表单验证 schema

ui/front/.env.development

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
TARGET=http://10.9.35.17:8090
2-
MY_SECRET_TOKEN=MEFrKrrVI3dZkvAluXncWPSC4z0zHrlJdqtFCgzzLxLR8p2qPljD9vE3KyBbdO36
1+
TARGET=http://10.9.35.17:8090

0 commit comments

Comments
 (0)