feat: 前后台静态资源路径冲突修复 + 用户管理功能
- 修改 admin/vite.config.js 添加 base: '/admin/' 解决静态资源路径问题 - 修复后台 index.html 资源引用从 /assets/ → /admin/assets/ - 更新优化器默认 API 地址为服务器地址 - 添加友链管理相关代码 - 修复多处分类管理页面
This commit is contained in:
@@ -3,12 +3,36 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.database import get_db
|
||||
from app.models.link import Link
|
||||
from app.schemas.link import LinkCreate, LinkResponse
|
||||
from app.schemas.link import LinkCreate, LinkResponse, LinkApply
|
||||
|
||||
router = APIRouter(tags=["友情链接"])
|
||||
|
||||
|
||||
@router.get("/links", response_model=list[LinkResponse])
|
||||
def list_links(db: Session = Depends(get_db)):
|
||||
"""公开:获取所有友情链接"""
|
||||
return db.query(Link).order_by(Link.sort_order, Link.id).all()
|
||||
"""公开:获取已通过审核的友情链接"""
|
||||
return db.query(Link).filter(Link.status == "approved").order_by(Link.sort_order, Link.id).all()
|
||||
|
||||
|
||||
@router.post("/links/apply", response_model=LinkResponse)
|
||||
def apply_link(link_data: LinkApply, db: Session = Depends(get_db)):
|
||||
"""公开:申请友链"""
|
||||
# 检查是否已存在同名或同URL的申请/已通过友链
|
||||
existing = db.query(Link).filter(
|
||||
(Link.name == link_data.name) | (Link.url == link_data.url)
|
||||
).first()
|
||||
if existing:
|
||||
return existing # 已存在则返回已有记录
|
||||
|
||||
link = Link(
|
||||
name=link_data.name,
|
||||
url=link_data.url,
|
||||
description=link_data.description,
|
||||
contact=link_data.contact,
|
||||
status="pending",
|
||||
sort_order=999, # 新申请放在最后
|
||||
)
|
||||
db.add(link)
|
||||
db.commit()
|
||||
db.refresh(link)
|
||||
return link
|
||||
Reference in New Issue
Block a user