feat(api): 修改oss
- 替换开发环境API基础URL为本地服务地址 - 实现签名URL本地缓存机制,解决微信按URL缓存图片导致重复下载问题 - 添加缓存清理功能,包括过期清理和按需删除特定缓存项 - 集成阿里云OSS上传功能,支持直传减少服务器带宽占用 - 优化头像地址处理逻辑,统一使用签名缓存避免地址频繁变化 - 移除过时的OSS上传示例文件oss-upload.js - 更新课程页面实现跳转第三方小程序功能 - 调整打卡记录图片地址获取方式,统一使用新的签名缓存逻辑 - 优化图片上传流程,增加压缩处理和批量上传支持 - 完善认证模块中的缓存清理逻辑,切换账号时清除相关图片缓存 - 添加后端环境变量配置模板和代理文档说明
This commit is contained in:
32
main.py
32
main.py
@@ -1,11 +1,11 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
import logging
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from wechat_backend.routes import auth, checkin, course_vote, feedback, plan, profile, survey, webview, yijing
|
||||
from . import config, oss_store
|
||||
from .routes import auth, checkin, course_vote, feedback, plan, profile, survey, webview, yijing
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
app = FastAPI(title="明缘进阶场 API")
|
||||
app.include_router(auth.router)
|
||||
@@ -19,12 +19,28 @@ app.include_router(yijing.router)
|
||||
app.include_router(webview.router)
|
||||
|
||||
|
||||
# ── 启动自检:把 OSS 状态打进 stderr ────────────────────────────────────────
|
||||
# 为什么必须显式打这一条:OSS 坏掉时**完全没有别的信号** —— 上传接口返 503、
|
||||
# 图片地址全是空串,而 oss_store 里一处日志都没有;「没装 oss2」和「.env 没配」
|
||||
# 还表现成一个样。2026-10-09 排查「部署后 OSS 不能用」时就是卡在这里。
|
||||
# 这里刻意用 **error** 级:项目没有 basicConfig,root logger 未配置时只有
|
||||
# WARNING 以上才会经 lastResort 落到 stderr(即 start_prd.sh 的 server.err.log)。
|
||||
_oss_reason = oss_store.unavailable_reason()
|
||||
if _oss_reason:
|
||||
logger.error("对象存储(OSS) 未启用:%s"
|
||||
" —— 上传接口会返 503、图片地址全为空串。"
|
||||
"排查:用该 venv 跑 check_oss.py", _oss_reason)
|
||||
else:
|
||||
logger.info("对象存储(OSS) 已启用:bucket=%s endpoint=%s public_host=%s",
|
||||
config.OSS_BUCKET, config.OSS_ENDPOINT, oss_store.public_host())
|
||||
|
||||
|
||||
@app.get("/api/v1/health")
|
||||
def health():
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run("wechat_backend.main:app", host="127.0.0.1", port=8000, reload=True)
|
||||
# 启动方式:相对导入(from . import ...)下不能 `python main.py` 直接运行
|
||||
# (顶层会报 `attempted relative import`),必须通过 uvicorn 以包方式加载:
|
||||
# uvicorn wechat_backend.main:app --host 0.0.0.0 --port 8000
|
||||
|
||||
|
||||
Reference in New Issue
Block a user