增加ImageCache微信 图片缓存

This commit is contained in:
chfei committed 2026-10-21 17:04:26 +08:00
1 parent d6cb5b966b
commit d0f9f00b76
15 files changed
+518 -30

No files matched your search

+12 -18
View File
@@ -16,37 +16,31 @@ namespace MAX.Framework.Commons
{
if (context.Result is ObjectResult objResult)
{
if (!IsAlreadyWrapped(objResult.Value))
if (objResult.Value is ApiResultBase)
{
objResult.StatusCode = 200;
objResult.DeclaredType = objResult.Value.GetType();
return;
}
// 非成功响应交由状态码中间件处理,避免先包装成业务成功。
var statusCode = objResult.StatusCode ?? 200;
if (statusCode >= 200 && statusCode < 300)
{
var apiResult = ApiResult<object>.Ok(objResult.Value);
objResult.Value = apiResult;
objResult.DeclaredType = null;
objResult.StatusCode = 200;
}
}
else if (context.Result is EmptyResult || context.Result is NoContentResult)
{
context.Result = new ObjectResult(ApiResult.Ok());
context.Result = new ObjectResult(ApiResult.Ok()) { StatusCode = 200 };
}
}
public void OnActionExecuting(ActionExecutingContext context) { }
private static bool IsAlreadyWrapped(object? value)
{
if (value is null) return false;
var type = value.GetType();
// 递归判断:只要类型链上有任何一层是 ApiResult<> 的开放泛型定义,或直接是 ApiResult,就算已包装
while (type is not null)
{
if (type == typeof(ApiResult)) return true;
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ApiResult<>)) return true;
type = type.BaseType;
}
return false;
}
}
}
@@ -59,7 +59,7 @@ namespace MAX.Framework.Commons
}
var originalBody = context.Response.Body;
var buffer = _streamManager.GetStream();
using var buffer = _streamManager.GetStream();
context.Response.Body = buffer;
@@ -126,7 +126,6 @@ namespace MAX.Framework.Commons
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
});
buffer.Dispose();
}
private static bool IsPassthroughByRequest(HttpContext context)