From ac769e656b122ff569c3f1534701b71e00fed586 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 27 Oct 2020 19:21:35 +0800 Subject: Split front and back end. --- Timeline/Filters/Header.cs | 63 -------------------------------------------- Timeline/Filters/Timeline.cs | 32 ---------------------- 2 files changed, 95 deletions(-) delete mode 100644 Timeline/Filters/Header.cs delete mode 100644 Timeline/Filters/Timeline.cs (limited to 'Timeline/Filters') 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 -{ - /// - /// Restrict max content length. - /// - public class MaxContentLengthFilter : IResourceFilter - { - /// - /// - /// - /// Max length. - public MaxContentLengthFilter(long maxByteLength) - { - MaxByteLength = maxByteLength; - } - - /// - /// Max length. - /// - public long MaxByteLength { get; set; } - - /// - public void OnResourceExecuted(ResourceExecutedContext context) - { - } - - /// - 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")); - } - } - } - - /// - /// Restrict max content length. - /// - public class MaxContentLengthAttribute : TypeFilterAttribute - { - /// - /// - /// - /// Max length. - public MaxContentLengthAttribute(long maxByteLength) - : base(typeof(MaxContentLengthFilter)) - { - MaxByteLength = maxByteLength; - Arguments = new object[] { maxByteLength }; - } - - /// - /// Max length. - /// - 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()); - } - } - } - } -} -- cgit v1.2.3