feat: add SQLite write-ahead log and shared memory files.

This commit is contained in:
tinix-ai
2026-04-09 16:19:39 +07:00
parent f12cedf6d0
commit c3a69d145b
68 changed files with 9079 additions and 42 deletions
+10 -4
View File
@@ -109,6 +109,11 @@ def build_create_tab():
suggest_plot_status = gr.Textbox(show_label=False, interactive=False, visible=False)
with gr.Accordion("📝 3. Dàn ý truyện", open=False):
custom_outline_prompt = gr.Textbox(
label="Yêu cầu riêng/Chỉ dẫn bổ sung cho Dàn ý (Tùy chọn)",
placeholder="VD: Không có nữ chính, kết cục mở, nvc là người tu ma nhưng tính cách hài hước...",
lines=2, interactive=False
)
with gr.Row():
total_chapters = gr.Number(
label=t("create.chapter_count"), value=20, minimum=1, maximum=200, step=1, scale=1, interactive=False
@@ -202,12 +207,12 @@ def build_create_tab():
traceback.print_exc()
yield gr.update(), gr.update(value=f"❌ Lỗi: {str(e)}", visible=True), gr.update(interactive=True)
def on_generate_outline(title, genre, sub_genres, num_chapters, char_setting, world_setting, plot_idea, progress=gr.Progress()):
def on_generate_outline(title, genre, sub_genres, num_chapters, char_setting, world_setting, plot_idea, custom_outline, progress=gr.Progress()):
progress(0.1, desc="Đang gọi AI...")
gen = app_state.get_generator()
content, msg = gen.generate_outline(
title, genre, sub_genres or [],
int(num_chapters), char_setting, world_setting, plot_idea
int(num_chapters), char_setting, world_setting, plot_idea, custom_outline
)
return content, msg
@@ -350,7 +355,7 @@ def build_create_tab():
)
generate_outline_btn.click(
fn=on_generate_outline,
inputs=[title_input, genre_dropdown, sub_genre_dropdown, total_chapters, character_input, world_input, plot_input],
inputs=[title_input, genre_dropdown, sub_genre_dropdown, total_chapters, character_input, world_input, plot_input, custom_outline_prompt],
outputs=[outline_output, outline_status],
show_progress="full"
)
@@ -400,10 +405,11 @@ def build_create_tab():
plot_input.change(
fn=lambda p: [
gr.update(interactive=bool(p)),
gr.update(interactive=bool(p)),
gr.update(interactive=bool(p))
],
inputs=[plot_input],
outputs=[total_chapters, generate_outline_btn]
outputs=[total_chapters, custom_outline_prompt, generate_outline_btn]
)
outline_output.change(
+44 -1
View File
@@ -10,10 +10,30 @@ from services.style_manager import StyleManager
from core.state import app_state
def build_settings_tab():
from core.auth import has_password, verify_password, set_password
with gr.Tab(t("tabs.settings")):
gr.Markdown(f"### {t('settings.header')}")
with gr.Tabs():
is_locked = has_password()
with gr.Column(visible=is_locked) as login_col:
gr.Markdown("#### 🔒 Bảng điều khiển bảo mật")
gr.Markdown("Cài đặt hệ thống đang được bảo vệ bằng mật khẩu.")
with gr.Row():
login_pwd = gr.Textbox(label="Vui lòng nhập mật khẩu", type="password", scale=4)
login_btn = gr.Button("Xác nhận", variant="primary", scale=1)
login_msg = gr.Markdown("")
with gr.Tabs(visible=not is_locked) as settings_tabs:
def on_login(pwd):
if verify_password(pwd):
return gr.update(visible=False), gr.update(visible=True), ""
else:
return gr.update(), gr.update(), "❌ Mật khẩu không chính xác!"
login_btn.click(fn=on_login, inputs=[login_pwd], outputs=[login_col, settings_tabs, login_msg])
login_pwd.submit(fn=on_login, inputs=[login_pwd], outputs=[login_col, settings_tabs, login_msg])
# Sub-tab: Quản lý giao diện API
with gr.Tab(t("settings.tab_backends")):
gr.Markdown(f"### {t('settings.backends_header')}")
@@ -466,3 +486,26 @@ def build_settings_tab():
style_add_btn.click(fn=on_style_add, inputs=[style_name_input, style_desc_input], outputs=[style_op_status, style_select])
style_update_btn.click(fn=on_style_update, inputs=[style_select, style_name_input, style_desc_input], outputs=[style_op_status, style_select])
style_delete_btn.click(fn=on_style_delete, inputs=[style_select], outputs=[style_op_status, style_select])
# Sub-tab: Bảo mật
with gr.Tab("Bảo mật"):
gr.Markdown("#### Quản lý Mật khẩu cho phần Cài đặt hệ thống")
gr.Markdown("Nếu để trống mật khẩu mới, hệ thống sẽ gỡ bỏ bảo vệ mật khẩu.")
with gr.Row():
with gr.Column(scale=1):
security_old_pwd = gr.Textbox(label="Mật khẩu cũ (để trống nếu chưa cài)", type="password")
security_new_pwd = gr.Textbox(label="Mật khẩu mới", type="password")
security_confirm_pwd = gr.Textbox(label="Xác nhận mật khẩu mới", type="password")
security_save_btn = gr.Button("Lưu mật khẩu", variant="primary")
security_status = gr.Textbox(label="Trạng thái", interactive=False)
def on_security_save(old_pwd, new_pwd, confirm_pwd):
if new_pwd != confirm_pwd:
return "❌ Mật khẩu xác nhận không khớp!"
success, msg = set_password(old_pwd, new_pwd)
return ("" if success else "") + msg
security_save_btn.click(fn=on_security_save, inputs=[security_old_pwd, security_new_pwd, security_confirm_pwd], outputs=[security_status])