From 253b06dfaa091d986a8714c081fd1e01679f538a Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 10 Feb 2021 02:03:06 +0800 Subject: ... --- .../Timeline/Controllers/TimelinePostController.cs | 28 ++++++++++++++++++---- .../Timeline/Controllers/UserAvatarController.cs | 15 ++++-------- 2 files changed, 27 insertions(+), 16 deletions(-) (limited to 'BackEnd/Timeline/Controllers') diff --git a/BackEnd/Timeline/Controllers/TimelinePostController.cs b/BackEnd/Timeline/Controllers/TimelinePostController.cs index 44498c58..a0fd1687 100644 --- a/BackEnd/Timeline/Controllers/TimelinePostController.cs +++ b/BackEnd/Timeline/Controllers/TimelinePostController.cs @@ -112,7 +112,7 @@ namespace Timeline.Controllers [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task DataGet([FromRoute][GeneralTimelineName] string timeline, [FromRoute] long post, [FromHeader(Name = "If-None-Match")] string? ifNoneMatch) + public async Task DataIndexGet([FromRoute][GeneralTimelineName] string timeline, [FromRoute] long post, [FromHeader(Name = "If-None-Match")] string? ifNoneMatch) { _ = ifNoneMatch; @@ -139,6 +139,24 @@ namespace Timeline.Controllers } } + /// + /// Get the data of a post. Usually a image post. + /// + /// Timeline name. + /// The id of the post. + /// If-None-Match header. + /// The data. + [HttpGet("{post}/data/{data_index}")] + [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)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task DataGet([FromRoute][GeneralTimelineName] string timeline, [FromRoute] long post, [FromHeader(Name = "If-None-Match")] string? ifNoneMatch) + { + } + /// /// Create a new post. /// @@ -163,18 +181,18 @@ namespace Timeline.Controllers var requestContent = body.Content; - TimelinePostCreateRequestContent createContent; + TimelinePostCreateRequestData createContent; switch (requestContent.Type) { - case TimelinePostContentTypes.Text: + case TimelinePostDataKind.Text: if (requestContent.Text is null) { return BadRequest(ErrorResponse.Common.CustomMessage_InvalidModel(Resources.Messages.TimelineController_TextContentTextRequired)); } createContent = new TimelinePostCreateRequestTextContent(requestContent.Text); break; - case TimelinePostContentTypes.Image: + case TimelinePostDataKind.Image: if (requestContent.Data is null) return BadRequest(ErrorResponse.Common.CustomMessage_InvalidModel(Resources.Messages.TimelineController_ImageContentDataRequired)); @@ -189,7 +207,7 @@ namespace Timeline.Controllers return BadRequest(ErrorResponse.Common.CustomMessage_InvalidModel(Resources.Messages.TimelineController_ImageContentDataNotBase64)); } - createContent = new TimelinePostCreateRequestImageContent(data); + createContent = new TimelinePostCreateRequestImageData(data); break; default: return BadRequest(ErrorResponse.Common.CustomMessage_InvalidModel(Resources.Messages.TimelineController_ContentUnknownType)); diff --git a/BackEnd/Timeline/Controllers/UserAvatarController.cs b/BackEnd/Timeline/Controllers/UserAvatarController.cs index f3b7fff8..8ac2d21a 100644 --- a/BackEnd/Timeline/Controllers/UserAvatarController.cs +++ b/BackEnd/Timeline/Controllers/UserAvatarController.cs @@ -7,6 +7,7 @@ using System; using System.Threading.Tasks; using Timeline.Filters; using Timeline.Helpers; +using Timeline.Helpers.Cache; using Timeline.Models; using Timeline.Models.Http; using Timeline.Models.Validation; @@ -63,11 +64,7 @@ namespace Timeline.Controllers return NotFound(ErrorResponse.UserCommon.NotExist()); } - return await DataCacheHelper.GenerateActionResult(this, () => _service.GetAvatarETag(id), async () => - { - var avatar = await _service.GetAvatar(id); - return avatar.ToCacheableData(); - }); + return await DataCacheHelper.GenerateActionResult(this, () => _service.GetAvatarDigest(id), () => _service.GetAvatar(id)); } /// @@ -105,11 +102,7 @@ namespace Timeline.Controllers try { - var etag = await _service.SetAvatar(id, new Avatar - { - Data = body.Data, - Type = body.ContentType - }); + var etag = await _service.SetAvatar(id, body); _logger.LogInformation(Log.Format(LogPutSuccess, ("Username", username), ("Mime Type", Request.ContentType))); @@ -166,7 +159,7 @@ namespace Timeline.Controllers return BadRequest(ErrorResponse.UserCommon.NotExist()); } - await _service.SetAvatar(id, null); + await _service.DeleteAvatar(id); return Ok(); } } -- cgit v1.2.3