Browse Source

一些bug修复

懒得勤快 6 years ago
parent
commit
fe9702fb60

File diff suppressed because it is too large
+ 0 - 0
src/Masuit.MyBlogs.Core/App_Data/ban.txt


+ 2 - 11
src/Masuit.MyBlogs.Core/Configs/HangfireJobInit.cs

@@ -1,8 +1,6 @@
 using Hangfire;
 using Masuit.MyBlogs.Core.Common;
 using Masuit.MyBlogs.Core.Extensions.Hangfire;
-using Masuit.Tools;
-using Masuit.Tools.NoSQL;
 using System;
 
 namespace Masuit.MyBlogs.Core.Configs
@@ -18,15 +16,8 @@ namespace Masuit.MyBlogs.Core.Configs
         public static void Start()
         {
             RecurringJob.AddOrUpdate(() => CheckLinks(), Cron.HourInterval(5)); //每5h检查友链
-            RecurringJob.AddOrUpdate(() => EverydayJob(), Cron.Daily, TimeZoneInfo.Local); //每天的任务
-            RecurringJob.AddOrUpdate(() => EveryweekJob(), Cron.Weekly(DayOfWeek.Monday, 3), TimeZoneInfo.Local); //每周的任务
-            using (RedisHelper redisHelper = RedisHelper.GetInstance())
-            {
-                if (!redisHelper.KeyExists("ArticleViewToken"))
-                {
-                    redisHelper.SetString("ArticleViewToken", string.Empty.CreateShortToken()); //更新加密文章的密码
-                }
-            }
+            RecurringJob.AddOrUpdate(() => EverydayJob(), Cron.Daily(5), TimeZoneInfo.Local); //每天的任务
+            RecurringJob.AddOrUpdate(() => EveryweekJob(), Cron.Weekly(DayOfWeek.Monday, 5), TimeZoneInfo.Local); //每周的任务
         }
 
         /// <summary>

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/MenuController.cs

@@ -37,7 +37,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <returns></returns>
         public ActionResult GetMenus()
         {
-            var menus = MenuService.GetAll(m => m.Sort).ToList();
+            var menus = MenuService.GetAll(m => m.ParentId).ThenBy(m => m.Sort).ToList();
             return ResultData(menus);
         }
 

+ 5 - 1
src/Masuit.MyBlogs.Core/Controllers/PostController.cs

@@ -141,7 +141,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 return View(list);
             }
 
-            return Redirect(Request.Headers[HeaderNames.Referer].ToString());
+            return RedirectToAction("Details", "Post", new { id });
         }
 
         /// <summary>
@@ -186,6 +186,10 @@ namespace Masuit.MyBlogs.Core.Controllers
             var main = PostService.GetById(id).Mapper<PostHistoryVersion>();
             var left = v1 <= 0 ? main : PostHistoryVersionService.GetById(v1);
             var right = v2 <= 0 ? main : PostHistoryVersionService.GetById(v2);
+            if (left is null || right is null)
+            {
+                return RedirectToAction("History", "Post", new { id });
+            }
             HtmlDiff.HtmlDiff diffHelper = new HtmlDiff.HtmlDiff(right.Content, left.Content);
             string diffOutput = diffHelper.Build();
             right.Content = Regex.Replace(Regex.Replace(diffOutput, "<ins.+?</ins>", string.Empty), @"<\w+></\w+>", string.Empty);

+ 2 - 3
src/Masuit.MyBlogs.Core/Controllers/SearchController.cs

@@ -56,10 +56,9 @@ namespace Masuit.MyBlogs.Core.Controllers
             var nul = new List<PostOutputDto>();
             ViewBag.Elapsed = 0;
             ViewBag.Total = 0;
-            ViewBag.Keyword = wd ?? "";
-            if (Regex.Match(wd, CommonHelper.BanRegex).Length > 0 || Regex.Match(wd, CommonHelper.ModRegex).Length > 0)
+            ViewBag.Keyword = wd;
+            if (Regex.Match(wd ?? "", CommonHelper.BanRegex + "|" + CommonHelper.ModRegex).Length > 0)
             {
-                //ViewBag.Wd = "";
                 return RedirectToAction("Search");
             }
             var start = DateTime.Today.AddDays(-7);

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/ToolsController.cs

@@ -91,7 +91,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 ip = $"{r.StrictNext(210)}.{r.StrictNext(255)}.{r.StrictNext(255)}.{r.StrictNext(255)}";
 #endif
                 PhysicsAddress address = await ip.GetPhysicsAddressInfo();
-                if (address.Status == 0)
+                if (address?.Status == 0)
                 {
                     ViewBag.Address = address.AddressResult.FormattedAddress;
                     if (Request.Method.ToLower().Equals("get"))

+ 8 - 8
src/Masuit.MyBlogs.Core/Extensions/FirewallMiddleware.cs

@@ -45,6 +45,7 @@ namespace Masuit.MyBlogs.Core.Extensions
 
             if (context.Request.Path.ToString().Contains(new[] { "error", "serviceunavailable" }))
             {
+                await _next.Invoke(context);
                 return;
             }
 
@@ -60,15 +61,14 @@ namespace Masuit.MyBlogs.Core.Extensions
                 }));
                 return;
             }
-            bool isSpider = context.Request.Headers[HeaderNames.UserAgent].ToString().Contains(new[]
+
+            bool isSpider = context.Request.Headers[HeaderNames.UserAgent].ToString().Contains(new[] { "DNSPod", "Baidu", "spider", "Python", "bot" });
+            if (isSpider)
             {
-                "DNSPod",
-                "Baidu",
-                "spider",
-                "Python",
-                "bot"
-            });
-            if (isSpider) return;
+                await _next.Invoke(context);
+                return;
+            }
+
             var times = _redisHelper.StringIncrement("Frequency:" + context.Connection.Id);
             _redisHelper.Expire("Frequency:" + context.Connection.Id, TimeSpan.FromMinutes(1));
             if (times > 300)

+ 8 - 5
src/Masuit.MyBlogs.Core/Extensions/Hangfire/HangfireBackJob.cs

@@ -7,6 +7,7 @@ using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.Tools.Core.Net;
+using Masuit.Tools.Core.NoSQL;
 using Masuit.Tools.NoSQL;
 using Masuit.Tools.Systems;
 using Microsoft.AspNetCore.Hosting;
@@ -43,18 +44,18 @@ namespace Masuit.MyBlogs.Core.Extensions.Hangfire
         /// <param name="settingService"></param>
         /// <param name="searchDetailsService"></param>
         /// <param name="linksService"></param>
-        /// <param name="redisHelper"></param>
+        /// <param name="redis"></param>
         /// <param name="httpClientFactory"></param>
         /// <param name="hostingEnvironment"></param>
         /// <param name="searchEngine"></param>
-        public HangfireBackJob(IUserInfoService userInfoService, IPostService postService, ISystemSettingService settingService, ISearchDetailsService searchDetailsService, ILinksService linksService, RedisHelper redisHelper, IHttpClientFactory httpClientFactory, IHostingEnvironment hostingEnvironment, ISearchEngine<DataContext> searchEngine)
+        public HangfireBackJob(IUserInfoService userInfoService, IPostService postService, ISystemSettingService settingService, ISearchDetailsService searchDetailsService, ILinksService linksService, RedisHelperFactory redis, IHttpClientFactory httpClientFactory, IHostingEnvironment hostingEnvironment, ISearchEngine<DataContext> searchEngine)
         {
             _userInfoService = userInfoService;
             _postService = postService;
             _settingService = settingService;
             _searchDetailsService = searchDetailsService;
             _linksService = linksService;
-            _redisHelper = redisHelper;
+            _redisHelper = redis.CreateDefault();
             _httpClientFactory = httpClientFactory;
             _hostingEnvironment = hostingEnvironment;
             _searchEngine = searchEngine;
@@ -133,7 +134,8 @@ namespace Masuit.MyBlogs.Core.Extensions.Hangfire
                 });
             }
 
-            _postService.UpdateEntitySaved(post);
+            _postService.UpdateEntity(post);
+            _postService.SaveChanges();
         }
 
         /// <summary>
@@ -165,7 +167,8 @@ namespace Masuit.MyBlogs.Core.Extensions.Hangfire
                 {
                     p.AverageViewCount = p.PostAccessRecord.Average(r => r.ClickCount);
                     p.TotalViewCount = p.PostAccessRecord.Sum(r => r.ClickCount);
-                    _postService.UpdateEntitySaved(p);
+                    _postService.UpdateEntity(p);
+                    _postService.SaveChanges();
                 }
                 catch (Exception)
                 {

+ 2 - 2
src/Masuit.MyBlogs.Core/Extensions/RequestInterceptMiddleware.cs

@@ -26,9 +26,9 @@ namespace Masuit.MyBlogs.Core.Extensions
 
         public async Task Invoke(HttpContext context)
         {
-            if (!context.Session.TryGetValue(context.Connection.Id, out _))
+            if (!context.Session.TryGetValue("session", out _))
             {
-                context.Session.Set(context.Connection.Id, context.Connection.Id);
+                context.Session.Set("session", 0);
                 _redisHelper.StringIncrement("Interview:ViewCount");
             }
             await _next.Invoke(context);

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Error/Index.cshtml

@@ -95,7 +95,7 @@
             <div id="container">
                 @{
                     Random r = new Random();
-                    string imgPath = $@"../Assets/images/404/404{r.StrictNext(Directory.GetFiles(HostingEnvironment.WebRootPath + "/Assets/images/404").Length) + 1}.jpg";
+                    string imgPath = $"/Assets/images/404/404{r.StrictNext(Directory.GetFiles(HostingEnvironment.WebRootPath + "/Assets/images/404").Length) + 1}.jpg";
                 }
                 <img class="img img-responsive img-thumbnail" width="100%" src="@imgPath" alt="@ViewBag.Keywords" />
                 <h3 class="margintop20">

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Error/ServiceUnavailable.cshtml

@@ -96,7 +96,7 @@
         <div id="container">
             @{
                 Random r = new Random();
-                string imgPath = $@"../Assets/images/503/503{r.StrictNext(Directory.GetFiles(HostingEnvironment.WebRootPath + "/Assets/images/503").Length) + 1}.jpg";
+                string imgPath = $"/Assets/images/503/503{r.StrictNext(Directory.GetFiles(HostingEnvironment.WebRootPath + "/Assets/images/503").Length) + 1}.jpg";
             }
             <img class="img img-responsive img-thumbnail" width="100%" src="@imgPath" alt="@ViewBag.Keywords" />
             <h3 class="margintop20">

Some files were not shown because too many files changed in this diff