fix(storage): 修复存储目标编辑不显示配置 & 添加文件列表API
- fix(storage): StorageOut 增加 config 字段并解密返回,编辑时可回填
- fix(storage): Storage ORM 模型添加 config property 支持序列化
- fix(env): 修正 SECRET_KEY 截断、FERNET_KEY 非法占位符问题
- fix(deploy): 后端从 Docker 容器迁移到 systemd 服务,存储目标路径改为宿主机真实路径
- feat(api): 新增 GET /api/storages/{id}/files 文件浏览端点
- feat(frontend): 新增 listFiles API 调用
- docs: 更新 README 反映部署方式变更
This commit is contained in:
@@ -28,13 +28,26 @@ def _validate_config(type_: str, config: dict) -> dict:
|
||||
raise HTTPException(status_code=400, detail=f"Unsupported type: {type_}")
|
||||
|
||||
|
||||
def _row_to_out(row: Storage) -> StorageOut:
|
||||
"""将 Storage ORM 行转为 StorageOut(解密 config)。"""
|
||||
return StorageOut(
|
||||
id=row.id,
|
||||
name=row.name,
|
||||
type=row.type,
|
||||
is_default=row.is_default,
|
||||
config=decrypt_dict(row.config_json),
|
||||
created_at=row.created_at,
|
||||
updated_at=row.updated_at,
|
||||
)
|
||||
|
||||
|
||||
@router.get("", response_model=list[StorageOut])
|
||||
def list_storages(db: DBSession, _: AdminUser) -> list[Storage]:
|
||||
return db.query(Storage).order_by(Storage.id).all()
|
||||
def list_storages(db: DBSession, _: AdminUser) -> list[StorageOut]:
|
||||
return [_row_to_out(row) for row in db.query(Storage).order_by(Storage.id).all()]
|
||||
|
||||
|
||||
@router.post("", response_model=StorageOut, status_code=201)
|
||||
def create_storage_endpoint(payload: StorageCreate, db: DBSession, _: AdminUser) -> Storage:
|
||||
def create_storage_endpoint(payload: StorageCreate, db: DBSession, _: AdminUser) -> StorageOut:
|
||||
if db.query(Storage).filter(Storage.name == payload.name).first():
|
||||
raise HTTPException(status_code=400, detail="名称已存在")
|
||||
config = _validate_config(payload.type, payload.config)
|
||||
@@ -49,19 +62,19 @@ def create_storage_endpoint(payload: StorageCreate, db: DBSession, _: AdminUser)
|
||||
db.add(row)
|
||||
db.commit()
|
||||
db.refresh(row)
|
||||
return row
|
||||
return _row_to_out(row)
|
||||
|
||||
|
||||
@router.get("/{storage_id}", response_model=StorageOut)
|
||||
def get_storage(storage_id: int, db: DBSession, _: AdminUser) -> Storage:
|
||||
def get_storage(storage_id: int, db: DBSession, _: AdminUser) -> StorageOut:
|
||||
row = db.get(Storage, storage_id)
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="Not found")
|
||||
return row
|
||||
return _row_to_out(row)
|
||||
|
||||
|
||||
@router.put("/{storage_id}", response_model=StorageOut)
|
||||
def update_storage(storage_id: int, payload: StorageUpdate, db: DBSession, _: AdminUser) -> Storage:
|
||||
def update_storage(storage_id: int, payload: StorageUpdate, db: DBSession, _: AdminUser) -> StorageOut:
|
||||
row = db.get(Storage, storage_id)
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="Not found")
|
||||
@@ -78,7 +91,7 @@ def update_storage(storage_id: int, payload: StorageUpdate, db: DBSession, _: Ad
|
||||
row.is_default = payload.is_default
|
||||
db.commit()
|
||||
db.refresh(row)
|
||||
return row
|
||||
return _row_to_out(row)
|
||||
|
||||
|
||||
@router.delete("/{storage_id}", status_code=204)
|
||||
|
||||
Reference in New Issue
Block a user