body_cleanup.go 514 B

12345678910111213141516171819202122
  1. package middleware
  2. import (
  3. "github.com/QuantumNous/new-api/common"
  4. "github.com/QuantumNous/new-api/service"
  5. "github.com/gin-gonic/gin"
  6. )
  7. // BodyStorageCleanup 请求体存储清理中间件
  8. // 在请求处理完成后自动清理磁盘/内存缓存
  9. func BodyStorageCleanup() gin.HandlerFunc {
  10. return func(c *gin.Context) {
  11. // 处理请求
  12. c.Next()
  13. // 请求结束后清理存储
  14. common.CleanupBodyStorage(c)
  15. // 清理文件缓存(URL 下载的文件等)
  16. service.CleanupFileSources(c)
  17. }
  18. }