public async Task <ActionResult <HttpTimelinePost> > Post([FromRoute][GeneralTimelineName] string timeline, [FromBody] HttpTimelinePostCreateRequest body) { var timelineId = await _timelineService.GetTimelineIdByNameAsync(timeline); var userId = GetUserId(); if (!UserHasAllTimelineManagementPermission && !await _timelineService.IsMemberOfAsync(timelineId, userId)) { return(ForbidWithCommonResponse()); } var createRequest = new TimelinePostCreateRequest() { Time = body.Time, Color = body.Color }; for (int i = 0; i < body.DataList.Count; i++) { var data = body.DataList[i]; if (data is null) { return(BadRequest(new CommonResponse(ErrorCodes.Common.InvalidModel, $"Data at index {i} is null."))); } try { var d = Convert.FromBase64String(data.Data); createRequest.DataList.Add(new TimelinePostCreateRequestData(data.ContentType, d)); } catch (FormatException) { return(BadRequest(new CommonResponse(ErrorCodes.Common.InvalidModel, $"Data at index {i} is not a valid base64 string."))); } } try { var post = await _postService.CreatePostAsync(timelineId, userId, createRequest); var result = await Map(post); return(result); } catch (TimelinePostCreateDataException e) { return(BadRequest(new CommonResponse(ErrorCodes.Common.InvalidModel, $"Data at index {e.Index} is invalid. {e.Message}"))); } }