Skip to content

Commit 259e1be

Browse files
committed
新增:在构建过程中确保data目录存在,并在打包环境中正确设置数据目录路径;更新release工作流以创建和移动data目录。
1 parent 167db67 commit 259e1be

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

.github/workflows/release.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ jobs:
6666
New-Item -ItemType Directory -Path "$VERSION"
6767
Move-Item "SD_Models_Manager_v*.exe" "$VERSION"
6868
69+
# 创建data目录
70+
New-Item -ItemType Directory -Path "$VERSION\data"
71+
Write-Host "Created data directory for storing prompt library"
72+
6973
# 只在 frontend 目录存在时才移动它
7074
if (Test-Path -Path "frontend") {
7175
Move-Item "frontend" "$VERSION"
@@ -78,6 +82,12 @@ jobs:
7882
Write-Host "Moved static directory to package"
7983
}
8084
85+
# 只在 data 目录存在时才移动它
86+
if (Test-Path -Path "data") {
87+
Move-Item "data" "$VERSION"
88+
Write-Host "Moved data directory to package"
89+
}
90+
8191
# 确保目录结构完整
8292
if (-not (Test-Path -Path "$VERSION\static")) {
8393
New-Item -ItemType Directory -Path "$VERSION\static"

build.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ def build_executable():
158158
# 设置环境变量以确保正确的编码
159159
os.environ['PYTHONIOENCODING'] = 'utf-8'
160160

161+
# 确保data目录存在
162+
os.makedirs('data', exist_ok=True)
163+
161164
# 构建前端
162165
if not build_frontend():
163166
print("警告: 前端构建失败,将只包含API部分")
@@ -180,6 +183,10 @@ def build_executable():
180183
if os.path.exists('static'):
181184
pyinstaller_args.append('--add-data=static;static')
182185

186+
# 添加data目录
187+
if os.path.exists('data'):
188+
pyinstaller_args.append('--add-data=data;data')
189+
183190
# 添加前端构建
184191
if os.path.exists('dist/frontend'):
185192
pyinstaller_args.append('--add-data=dist/frontend;frontend')

src/api/prompt_library_api.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import json
88
from datetime import datetime
9+
import sys
910

1011
# 提示词库项目模型
1112
class PromptLibraryItem(BaseModel):
@@ -36,7 +37,15 @@ class UpdatePromptLibraryItemRequest(BaseModel):
3637
class PromptLibraryManager:
3738
def __init__(self, data_dir):
3839
self.data_dir = data_dir
39-
self.library_file = os.path.join(data_dir, "prompt_library.json")
40+
41+
# 检查是否是PyInstaller打包环境
42+
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
43+
# 在打包环境中,使用应用程序所在目录下的data目录
44+
app_dir = os.path.dirname(sys.executable)
45+
self.data_dir = os.path.join(app_dir, "data")
46+
print(f"检测到打包环境,设置数据目录为: {self.data_dir}")
47+
48+
self.library_file = os.path.join(self.data_dir, "prompt_library.json")
4049
self.items = []
4150
self.load_library()
4251

@@ -49,7 +58,7 @@ def load_library(self):
4958
print(f"已加载提示词库,共{len(self.items)}个项目")
5059
else:
5160
self.items = []
52-
print("提示词库文件不存在,已初始化空库")
61+
print(f"提示词库文件不存在,已初始化空库 (路径: {self.library_file})")
5362
except Exception as e:
5463
print(f"加载提示词库失败: {str(e)}")
5564
self.items = []

0 commit comments

Comments
 (0)