From 8f09e3172f249a9f5d229040415a0569e9d1c01b Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 6 Mar 2021 22:51:53 +0800 Subject: feat: Auto translate url in markdown post. --- BackEnd/Timeline/Controllers/TimelinePostController.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'BackEnd/Timeline/Controllers') diff --git a/BackEnd/Timeline/Controllers/TimelinePostController.cs b/BackEnd/Timeline/Controllers/TimelinePostController.cs index 4026d551..86c5c8cf 100644 --- a/BackEnd/Timeline/Controllers/TimelinePostController.cs +++ b/BackEnd/Timeline/Controllers/TimelinePostController.cs @@ -32,14 +32,17 @@ namespace Timeline.Controllers private readonly TimelineMapper _timelineMapper; + private readonly MarkdownProcessor _markdownProcessor; + /// /// /// - public TimelinePostController(ITimelineService timelineService, ITimelinePostService timelinePostService, TimelineMapper timelineMapper) + public TimelinePostController(ITimelineService timelineService, ITimelinePostService timelinePostService, TimelineMapper timelineMapper, MarkdownProcessor markdownProcessor) { _timelineService = timelineService; _postService = timelinePostService; _timelineMapper = timelineMapper; + _markdownProcessor = markdownProcessor; } private bool UserHasAllTimelineManagementPermission => this.UserHasPermission(UserPermission.AllTimelineManagement); @@ -147,7 +150,15 @@ namespace Timeline.Controllers return await DataCacheHelper.GenerateActionResult(this, () => _postService.GetPostDataDigest(timelineId, post, dataIndex), - () => _postService.GetPostData(timelineId, post, dataIndex) + async () => + { + var data = await _postService.GetPostData(timelineId, post, dataIndex); + if (data.ContentType == MimeTypes.TextMarkdown) + { + return new ByteData(_markdownProcessor.Process(data.Data, Url, timeline, post), data.ContentType); + } + return data; + } ); } -- cgit v1.2.3