init
This commit is contained in:
+7
-1
@@ -14,4 +14,10 @@ __pycache__/
|
|||||||
|
|
||||||
# 项目临时文件
|
# 项目临时文件
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.log
|
*.log
|
||||||
|
.env
|
||||||
|
logs/
|
||||||
|
uploads/
|
||||||
|
html_output/
|
||||||
|
src/uploads/
|
||||||
|
src/html_output/
|
||||||
|
|||||||
+4
-4
@@ -28,9 +28,9 @@ class Settings:
|
|||||||
self.PARALLEL_PROCESSING = os.getenv('PARALLEL_PROCESSING', 'true').lower() == 'true'
|
self.PARALLEL_PROCESSING = os.getenv('PARALLEL_PROCESSING', 'true').lower() == 'true'
|
||||||
|
|
||||||
# RustFS 对象存储配置 (S3v4 API)
|
# RustFS 对象存储配置 (S3v4 API)
|
||||||
self.RUSTFS_ENDPOINT = os.getenv('RUSTFS_ENDPOINT', 'http://localhost:8080')
|
self.RUSTFS_ENDPOINT = os.getenv('RUSTFS_ENDPOINT') or os.getenv('MINIO_ENDPOINT') or 'http://localhost:8080'
|
||||||
self.RUSTFS_ACCESS_KEY = os.getenv('RUSTFS_ACCESS_KEY', 'your-access-key')
|
self.RUSTFS_ACCESS_KEY = os.getenv('RUSTFS_ACCESS_KEY') or os.getenv('MINIO_ACCESS_KEY') or 'your-access-key'
|
||||||
self.RUSTFS_SECRET_KEY = os.getenv('RUSTFS_SECRET_KEY', 'your-secret-key')
|
self.RUSTFS_SECRET_KEY = os.getenv('RUSTFS_SECRET_KEY') or os.getenv('MINIO_SECRET_KEY') or 'your-secret-key'
|
||||||
self.RUSTFS_TIMEOUT = int(os.getenv('RUSTFS_TIMEOUT', '30'))
|
self.RUSTFS_TIMEOUT = int(os.getenv('RUSTFS_TIMEOUT', '30'))
|
||||||
|
|
||||||
# 预签名URL过期时间(秒)
|
# 预签名URL过期时间(秒)
|
||||||
@@ -99,4 +99,4 @@ class Settings:
|
|||||||
|
|
||||||
|
|
||||||
# 创建全局配置实例
|
# 创建全局配置实例
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
|||||||
+4
-5
@@ -61,11 +61,10 @@ services:
|
|||||||
- DB_NAME=${DB_NAME:-moldinsight}
|
- DB_NAME=${DB_NAME:-moldinsight}
|
||||||
- DB_USER=${DB_USER:-moldinsight_user}
|
- DB_USER=${DB_USER:-moldinsight_user}
|
||||||
- DB_PASSWORD=${DB_PASSWORD:-moldinsight_password}
|
- DB_PASSWORD=${DB_PASSWORD:-moldinsight_password}
|
||||||
# MinIO配置
|
# RustFS配置
|
||||||
- MINIO_ENDPOINT=minio:9000
|
- RUSTFS_ENDPOINT=http://minio:9000
|
||||||
- MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY:-minioadmin}
|
- RUSTFS_ACCESS_KEY=${MINIO_ACCESS_KEY:-minioadmin}
|
||||||
- MINIO_SECRET_KEY=${MINIO_SECRET_KEY:-minioadmin}
|
- RUSTFS_SECRET_KEY=${MINIO_SECRET_KEY:-minioadmin}
|
||||||
- MINIO_SECURE=false
|
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
postgres:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|||||||
+10
-7
@@ -18,6 +18,8 @@ from core.mold_generator import MoldCavityGenerator
|
|||||||
from core.aluminum_foam_mold import AluminumFoamMoldGenerator
|
from core.aluminum_foam_mold import AluminumFoamMoldGenerator
|
||||||
from core.mold_quality_inspector import AluminumFoamMoldQualityInspector
|
from core.mold_quality_inspector import AluminumFoamMoldQualityInspector
|
||||||
from core.mesh_generator import MeshGenerator
|
from core.mesh_generator import MeshGenerator
|
||||||
|
from services.auth_service import get_current_active_user
|
||||||
|
from models.database import User
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
@@ -52,7 +54,8 @@ async def upload_stp(
|
|||||||
background_tasks: BackgroundTasks,
|
background_tasks: BackgroundTasks,
|
||||||
file: UploadFile = File(...),
|
file: UploadFile = File(...),
|
||||||
material: Optional[str] = "ABS",
|
material: Optional[str] = "ABS",
|
||||||
db_session: AsyncSession = Depends(get_db_session)
|
db_session: AsyncSession = Depends(get_db_session),
|
||||||
|
current_user: User = Depends(get_current_active_user)
|
||||||
):
|
):
|
||||||
"""上传STP文件并存储到数据库"""
|
"""上传STP文件并存储到数据库"""
|
||||||
|
|
||||||
@@ -62,8 +65,7 @@ async def upload_stp(
|
|||||||
task_id = str(uuid.uuid4())
|
task_id = str(uuid.uuid4())
|
||||||
|
|
||||||
# 保存文件
|
# 保存文件
|
||||||
file_path = await file_handler.save_uploaded_file(file)
|
file_path, file_size = await file_handler.save_uploaded_file(file)
|
||||||
content = await file.read()
|
|
||||||
|
|
||||||
# 创建存储集成服务实例
|
# 创建存储集成服务实例
|
||||||
storage_service = StorageIntegrationService()
|
storage_service = StorageIntegrationService()
|
||||||
@@ -72,7 +74,8 @@ async def upload_stp(
|
|||||||
stp_file = await storage_service.save_stp_file(
|
stp_file = await storage_service.save_stp_file(
|
||||||
session=db_session,
|
session=db_session,
|
||||||
file_path=file_path,
|
file_path=file_path,
|
||||||
original_filename=file.filename
|
original_filename=file.filename,
|
||||||
|
user_id=current_user.id
|
||||||
)
|
)
|
||||||
|
|
||||||
# 创建处理任务记录
|
# 创建处理任务记录
|
||||||
@@ -84,7 +87,7 @@ async def upload_stp(
|
|||||||
status=ProcessingStatus.PROCESSING,
|
status=ProcessingStatus.PROCESSING,
|
||||||
filename=file.filename,
|
filename=file.filename,
|
||||||
file_path=str(file_path),
|
file_path=str(file_path),
|
||||||
file_size=len(content),
|
file_size=file_size,
|
||||||
upload_time=str(datetime.now())
|
upload_time=str(datetime.now())
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -97,7 +100,7 @@ async def upload_stp(
|
|||||||
"message": "文件上传成功,开始处理并存储到数据库",
|
"message": "文件上传成功,开始处理并存储到数据库",
|
||||||
"file_info": {
|
"file_info": {
|
||||||
"filename": file.filename,
|
"filename": file.filename,
|
||||||
"size": len(content),
|
"size": file_size,
|
||||||
"pythonocc_available": True,
|
"pythonocc_available": True,
|
||||||
"database_file_id": stp_file.id
|
"database_file_id": stp_file.id
|
||||||
}
|
}
|
||||||
@@ -857,4 +860,4 @@ async def process_file_core(
|
|||||||
|
|
||||||
tasks[task_id]["status"] = ProcessingStatus.FAILED
|
tasks[task_id]["status"] = ProcessingStatus.FAILED
|
||||||
tasks[task_id]["error"] = str(e)
|
tasks[task_id]["error"] = str(e)
|
||||||
tasks[task_id]["completed_at"] = str(datetime.now())
|
tasks[task_id]["completed_at"] = str(datetime.now())
|
||||||
|
|||||||
@@ -134,12 +134,10 @@ async def init_database():
|
|||||||
print("数据库初始化成功!")
|
print("数据库初始化成功!")
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
print(f"管理员用户名: {settings.ADMIN_USERNAME}")
|
print(f"管理员用户名: {settings.ADMIN_USERNAME}")
|
||||||
print(f"管理员密码: {settings.ADMIN_PASSWORD}")
|
|
||||||
print(f"管理员邮箱: {settings.ADMIN_EMAIL}")
|
print(f"管理员邮箱: {settings.ADMIN_EMAIL}")
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
print("可以在 .env 文件中修改管理员配置:")
|
print("可以在 .env 文件中修改管理员配置:")
|
||||||
print(" ADMIN_USERNAME")
|
print(" ADMIN_USERNAME")
|
||||||
print(" ADMIN_PASSWORD")
|
|
||||||
print(" ADMIN_EMAIL")
|
print(" ADMIN_EMAIL")
|
||||||
print(" ADMIN_FULL_NAME")
|
print(" ADMIN_FULL_NAME")
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
|
|||||||
@@ -116,8 +116,7 @@ async def create_user(
|
|||||||
username: str,
|
username: str,
|
||||||
email: str,
|
email: str,
|
||||||
password: str,
|
password: str,
|
||||||
full_name: Optional[str] = None,
|
full_name: Optional[str] = None
|
||||||
is_superuser: bool = False
|
|
||||||
) -> User:
|
) -> User:
|
||||||
hashed_password = get_password_hash(password)
|
hashed_password = get_password_hash(password)
|
||||||
user = User(
|
user = User(
|
||||||
@@ -125,7 +124,6 @@ async def create_user(
|
|||||||
email=email,
|
email=email,
|
||||||
hashed_password=hashed_password,
|
hashed_password=hashed_password,
|
||||||
full_name=full_name,
|
full_name=full_name,
|
||||||
is_superuser=is_superuser,
|
|
||||||
is_active=True
|
is_active=True
|
||||||
)
|
)
|
||||||
db_session.add(user)
|
db_session.add(user)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import aiofiles
|
import aiofiles
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from fastapi import UploadFile
|
from fastapi import UploadFile
|
||||||
|
from typing import Tuple
|
||||||
|
|
||||||
|
|
||||||
class FileHandler:
|
class FileHandler:
|
||||||
@@ -9,15 +10,15 @@ class FileHandler:
|
|||||||
self.upload_dir = Path(upload_dir)
|
self.upload_dir = Path(upload_dir)
|
||||||
self.upload_dir.mkdir(exist_ok=True)
|
self.upload_dir.mkdir(exist_ok=True)
|
||||||
|
|
||||||
async def save_uploaded_file(self, file: UploadFile) -> Path:
|
async def save_uploaded_file(self, file: UploadFile) -> Tuple[Path, int]:
|
||||||
"""保存上传的文件"""
|
"""保存上传的文件"""
|
||||||
file_path = self.upload_dir / file.filename
|
file_path = self.upload_dir / file.filename
|
||||||
|
|
||||||
|
content = await file.read()
|
||||||
async with aiofiles.open(file_path, 'wb') as f:
|
async with aiofiles.open(file_path, 'wb') as f:
|
||||||
content = await file.read()
|
|
||||||
await f.write(content)
|
await f.write(content)
|
||||||
|
|
||||||
return file_path
|
return file_path, len(content)
|
||||||
|
|
||||||
def cleanup_file(self, file_path: Path):
|
def cleanup_file(self, file_path: Path):
|
||||||
"""清理文件"""
|
"""清理文件"""
|
||||||
@@ -25,4 +26,4 @@ class FileHandler:
|
|||||||
if file_path.exists():
|
if file_path.exists():
|
||||||
file_path.unlink()
|
file_path.unlink()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"文件清理失败: {e}")
|
print(f"文件清理失败: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user