Add Luxsin curve API client and validation functionality
- Introduced a new module `curve_client.py` for interacting with the Luxsin curve API, including functions for custom Base64 decoding and parametric EQ validation. - Implemented error handling for API responses and validation checks for curve data. - Removed outdated test files to streamline the codebase. - Updated brand creation and update logic in `brands.py` to ensure brand names are validated and checked for duplicates. - Enhanced model handling in `models.py` with new validation and push-to-search functionality, integrating curve validation before pushing to Meilisearch. - Updated frontend components to support new validation and push processes, including user feedback for validation results and progress tracking. - Changed favicon to SVG format for better scalability and appearance.
This commit is contained in:
+29
-13
@@ -65,14 +65,16 @@ def get_brand(brand_id: int, db: Session = Depends(get_db)):
|
||||
def create_brand(brand: BrandCreate, db: Session = Depends(get_db)):
|
||||
"""创建新品牌"""
|
||||
try:
|
||||
logger.info(f"Creating brand: name={brand.name}")
|
||||
# 检查是否已存在
|
||||
existing = db.query(Brand).filter(Brand.name == brand.name).first()
|
||||
name = (brand.name or "").strip()
|
||||
if not name:
|
||||
return ApiResponse.error(msg="品牌名称不能为空", code=0)
|
||||
logger.info(f"Creating brand: name={name}")
|
||||
existing = db.query(Brand).filter(Brand.name == name).first()
|
||||
if existing:
|
||||
logger.warning(f"Brand already exists: name={brand.name}")
|
||||
logger.warning(f"Brand already exists: name={name}")
|
||||
return ApiResponse.error(msg="品牌名称已存在", code=0)
|
||||
|
||||
db_brand = Brand(name=brand.name)
|
||||
|
||||
db_brand = Brand(name=name)
|
||||
db.add(db_brand)
|
||||
db.commit()
|
||||
db.refresh(db_brand)
|
||||
@@ -88,19 +90,33 @@ def create_brand(brand: BrandCreate, db: Session = Depends(get_db)):
|
||||
def update_brand(brand_id: int, brand: BrandUpdate, db: Session = Depends(get_db)):
|
||||
"""更新品牌"""
|
||||
try:
|
||||
logger.info(f"Updating brand: id={brand_id}, data={brand.dict()}")
|
||||
logger.info(f"Updating brand: id={brand_id}, data={brand.model_dump()}")
|
||||
db_brand = db.query(Brand).filter(Brand.id == brand_id).first()
|
||||
if not db_brand:
|
||||
logger.warning(f"Brand not found: id={brand_id}")
|
||||
return ApiResponse.no_data(msg="品牌不存在")
|
||||
|
||||
# 如果更新名称,检查是否冲突
|
||||
if brand.name and brand.name != db_brand.name:
|
||||
existing = db.query(Brand).filter(Brand.name == brand.name).first()
|
||||
|
||||
if brand.name is None:
|
||||
db.commit()
|
||||
db.refresh(db_brand)
|
||||
return ApiResponse.success(data=db_brand.to_dict(), msg="品牌更新成功")
|
||||
|
||||
new_name = brand.name.strip()
|
||||
if not new_name:
|
||||
return ApiResponse.error(msg="品牌名称不能为空", code=0)
|
||||
|
||||
current_name = (db_brand.name or "").strip()
|
||||
if new_name != current_name:
|
||||
# 排除当前记录;MySQL 大小写不敏感时,仅改大小写也会命中自身
|
||||
existing = (
|
||||
db.query(Brand)
|
||||
.filter(Brand.name == new_name, Brand.id != brand_id)
|
||||
.first()
|
||||
)
|
||||
if existing:
|
||||
logger.warning(f"Brand name already exists: name={brand.name}")
|
||||
logger.warning(f"Brand name already exists: name={new_name}")
|
||||
return ApiResponse.error(msg="品牌名称已存在", code=0)
|
||||
db_brand.name = brand.name
|
||||
db_brand.name = new_name
|
||||
|
||||
db.commit()
|
||||
db.refresh(db_brand)
|
||||
|
||||
Reference in New Issue
Block a user