feat: add asset access signing endpoints

This commit is contained in:
xiong
2026-07-26 14:54:50 +08:00
parent 0ff97e86cd
commit 06471151cd
9 changed files with 957 additions and 1 deletions

View File

@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Tiku.Api.Controllers;
using Tiku.Application.Assets;
using Tiku.Application.Auth;
using Tiku.Application.Storage;
using Tiku.Infrastructure.Content;
using Tiku.Infrastructure.QuestionBanks;
@@ -75,6 +77,28 @@ public sealed class ExceptionHandlingMiddleware(
return;
}
if (exception is AssetAccessException assetAccessException)
{
await WriteProblemAsync(
context,
assetAccessException.Message,
AssetAccessStatusCode(assetAccessException.Code),
assetAccessException.Code.ToLowerInvariant());
return;
}
if (exception is ObjectStorageException storageException)
{
await WriteProblemAsync(
context,
storageException.Message,
storageException is ObjectStorageNotConfiguredException
? StatusCodes.Status503ServiceUnavailable
: StatusCodes.Status400BadRequest,
storageException.Code.ToLowerInvariant());
return;
}
logger.LogError(exception, "Unhandled API exception");
var problem = new ProblemDetails
@@ -132,4 +156,17 @@ public sealed class ExceptionHandlingMiddleware(
context.Response.StatusCode = status;
await context.Response.WriteAsJsonAsync(problem);
}
private static int AssetAccessStatusCode(string code)
{
return code switch
{
"ASSET_NOT_FOUND" => StatusCodes.Status404NotFound,
"AUTH_REQUIRED" => StatusCodes.Status401Unauthorized,
"ASSET_HIDDEN" or "ASSET_MEMBERSHIP_REQUIRED" or "ASSET_SVIP_REQUIRED" => StatusCodes.Status403Forbidden,
"ASSET_UPLOAD_NOT_VERIFIED" or "ASSET_SECURITY_SCAN_NOT_PASSED" => StatusCodes.Status409Conflict,
"ASSET_PREVIEW_NOT_SUPPORTED" => StatusCodes.Status400BadRequest,
_ => StatusCodes.Status400BadRequest
};
}
}