diff options
| author | crupest <crupest@outlook.com> | 2020-10-27 19:21:35 +0800 |
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2020-10-27 19:21:35 +0800 |
| commit | ac769e656b122ff569c3f1534701b71e00fed586 (patch) | |
| tree | 72966645ff1e25139d3995262e1c4349f2c14733 /Timeline/Filters | |
| parent | 14e5848c23c643cea9b5d709770747d98c3d75e2 (diff) | |
| download | timeline-ac769e656b122ff569c3f1534701b71e00fed586.tar.gz timeline-ac769e656b122ff569c3f1534701b71e00fed586.tar.bz2 timeline-ac769e656b122ff569c3f1534701b71e00fed586.zip | |
Split front and back end.
Diffstat (limited to 'Timeline/Filters')
| -rw-r--r-- | Timeline/Filters/Header.cs | 63 | ||||
| -rw-r--r-- | Timeline/Filters/Timeline.cs | 32 |
2 files changed, 0 insertions, 95 deletions
diff --git a/Timeline/Filters/Header.cs b/Timeline/Filters/Header.cs deleted file mode 100644 index cc5ddd9f..00000000 --- a/Timeline/Filters/Header.cs +++ /dev/null @@ -1,63 +0,0 @@ -using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Filters;
-using Timeline.Models.Http;
-
-namespace Timeline.Filters
-{
- /// <summary>
- /// Restrict max content length.
- /// </summary>
- public class MaxContentLengthFilter : IResourceFilter
- {
- /// <summary>
- ///
- /// </summary>
- /// <param name="maxByteLength">Max length.</param>
- public MaxContentLengthFilter(long maxByteLength)
- {
- MaxByteLength = maxByteLength;
- }
-
- /// <summary>
- /// Max length.
- /// </summary>
- public long MaxByteLength { get; set; }
-
- /// <inheritdoc/>
- public void OnResourceExecuted(ResourceExecutedContext context)
- {
- }
-
- /// <inheritdoc/>
- public void OnResourceExecuting(ResourceExecutingContext context)
- {
- var contentLength = context.HttpContext.Request.ContentLength;
- if (contentLength != null && contentLength > MaxByteLength)
- {
- context.Result = new BadRequestObjectResult(ErrorResponse.Common.Content.TooBig(MaxByteLength + "B"));
- }
- }
- }
-
- /// <summary>
- /// Restrict max content length.
- /// </summary>
- public class MaxContentLengthAttribute : TypeFilterAttribute
- {
- /// <summary>
- ///
- /// </summary>
- /// <param name="maxByteLength">Max length.</param>
- public MaxContentLengthAttribute(long maxByteLength)
- : base(typeof(MaxContentLengthFilter))
- {
- MaxByteLength = maxByteLength;
- Arguments = new object[] { maxByteLength };
- }
-
- /// <summary>
- /// Max length.
- /// </summary>
- public long MaxByteLength { get; }
- }
-}
diff --git a/Timeline/Filters/Timeline.cs b/Timeline/Filters/Timeline.cs deleted file mode 100644 index 6a730ee7..00000000 --- a/Timeline/Filters/Timeline.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Filters;
-using Timeline.Models.Http;
-using Timeline.Services.Exceptions;
-
-namespace Timeline.Filters
-{
- public class CatchTimelineNotExistExceptionAttribute : ExceptionFilterAttribute
- {
- public override void OnException(ExceptionContext context)
- {
- if (context.Exception is TimelineNotExistException e)
- {
- if (e.InnerException is UserNotExistException)
- {
- if (HttpMethods.IsGet(context.HttpContext.Request.Method))
- context.Result = new NotFoundObjectResult(ErrorResponse.UserCommon.NotExist());
- else
- context.Result = new BadRequestObjectResult(ErrorResponse.UserCommon.NotExist());
- }
- else
- {
- if (HttpMethods.IsGet(context.HttpContext.Request.Method))
- context.Result = new NotFoundObjectResult(ErrorResponse.TimelineController.NotExist());
- else
- context.Result = new BadRequestObjectResult(ErrorResponse.TimelineController.NotExist());
- }
- }
- }
- }
-}
|
