aboutsummaryrefslogtreecommitdiff
path: root/Timeline
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-08-23 17:17:04 +0800
committercrupest <crupest@outlook.com>2020-08-23 17:17:04 +0800
commitb1b10b7dda86138d020b1545b4de55b37ee793b3 (patch)
tree7edfeca01b33e2bff98f10148b371d473e73a299 /Timeline
parented5b550e8a19be250952371c60e1c1f3d2864a1e (diff)
downloadtimeline-b1b10b7dda86138d020b1545b4de55b37ee793b3.tar.gz
timeline-b1b10b7dda86138d020b1545b4de55b37ee793b3.tar.bz2
timeline-b1b10b7dda86138d020b1545b4de55b37ee793b3.zip
Add produces and consumes .
Diffstat (limited to 'Timeline')
-rw-r--r--Timeline/Controllers/TimelineController.cs3
-rw-r--r--Timeline/Controllers/UserAvatarController.cs2
-rw-r--r--Timeline/Helpers/DataCacheHelper.cs2
-rw-r--r--Timeline/Startup.cs4
4 files changed, 8 insertions, 3 deletions
diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs
index 43178ac6..90b50bbb 100644
--- a/Timeline/Controllers/TimelineController.cs
+++ b/Timeline/Controllers/TimelineController.cs
@@ -199,7 +199,8 @@ namespace Timeline.Controllers
/// <param name="ifNoneMatch">If-None-Match header.</param>
/// <returns>The data.</returns>
[HttpGet("timelines/{name}/posts/{id}/data")]
- [ProducesResponseType(StatusCodes.Status200OK)]
+ [Produces("image/png", "image/jpeg", "image/gif", "image/webp", "application/json", "text/json")]
+ [ProducesResponseType(typeof(byte[]), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(void), StatusCodes.Status304NotModified)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
diff --git a/Timeline/Controllers/UserAvatarController.cs b/Timeline/Controllers/UserAvatarController.cs
index 32f63fc6..97c4bdb8 100644
--- a/Timeline/Controllers/UserAvatarController.cs
+++ b/Timeline/Controllers/UserAvatarController.cs
@@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
-using System.IO;
using System.Threading.Tasks;
using Timeline.Auth;
using Timeline.Filters;
@@ -46,6 +45,7 @@ namespace Timeline.Controllers
/// <param name="ifNoneMatch">If-None-Match header.</param>
/// <returns>Avatar data.</returns>
[HttpGet("users/{username}/avatar")]
+ [Produces("image/png", "image/jpeg", "image/gif", "image/webp", "application/json", "text/json")]
[ProducesResponseType(typeof(byte[]), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(void), StatusCodes.Status304NotModified)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
diff --git a/Timeline/Helpers/DataCacheHelper.cs b/Timeline/Helpers/DataCacheHelper.cs
index 574d90b4..1ad69708 100644
--- a/Timeline/Helpers/DataCacheHelper.cs
+++ b/Timeline/Helpers/DataCacheHelper.cs
@@ -107,7 +107,7 @@ namespace Timeline.Helpers
controller.Response.Headers.Add(ETagHeaderKey, eTagValue);
controller.Response.Headers.Add(CacheControlHeaderKey, GenerateCacheControlHeaderValue());
- return controller.StatusCode(StatusCodes.Status304NotModified);
+ return controller.StatusCode(StatusCodes.Status304NotModified, null);
}
}
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs
index cbca01d0..82c231cb 100644
--- a/Timeline/Startup.cs
+++ b/Timeline/Startup.cs
@@ -1,6 +1,7 @@
using AutoMapper;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@@ -11,6 +12,7 @@ using NSwag;
using NSwag.Generation.Processors.Security;
using System;
using System.ComponentModel;
+using System.Net.Mime;
using System.Text.Json.Serialization;
using Timeline.Auth;
using Timeline.Configs;
@@ -50,6 +52,8 @@ namespace Timeline
{
setup.InputFormatters.Add(new StringInputFormatter());
setup.InputFormatters.Add(new BytesInputFormatter());
+ setup.Filters.Add(new ConsumesAttribute(MediaTypeNames.Application.Json, "text/json"));
+ setup.Filters.Add(new ProducesAttribute(MediaTypeNames.Application.Json, "text/json"));
setup.UseApiRoutePrefix("api");
})
.AddJsonOptions(options =>