Переглянути джерело

1.图床优化
2.公告页优化

懒得勤快 6 роки тому
батько
коміт
df5c994cb5

+ 1 - 280
src/Masuit.MyBlogs.Core/Common/CommonHelper.cs

@@ -1,23 +1,12 @@
-using Aliyun.OSS;
-using Hangfire;
-using IP2Region;
-using Masuit.MyBlogs.Core.Configs;
+using IP2Region;
 using Masuit.Tools;
 using Masuit.Tools;
-using Masuit.Tools.Html;
-using Masuit.Tools.Systems;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Http;
 using Microsoft.Net.Http.Headers;
 using Microsoft.Net.Http.Headers;
-using Newtonsoft.Json.Linq;
-using Polly;
 using System;
 using System;
 using System.Collections.Concurrent;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.Collections.Generic;
-using System.Drawing;
 using System.IO;
 using System.IO;
 using System.Linq;
 using System.Linq;
-using System.Net;
-using System.Net.Http;
-using System.Net.Http.Headers;
 #if !DEBUG
 #if !DEBUG
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.Tools.Models;
 using Masuit.Tools.Models;
@@ -186,274 +175,6 @@ namespace Masuit.MyBlogs.Core.Common
 #endif
 #endif
         }
         }
 
 
-        #region 图床相关
-
-        /// <summary>
-        /// OSS客户端
-        /// </summary>
-        public static OssClient OssClient { get; set; } = new OssClient(AppConfig.AliOssConfig.EndPoint, AppConfig.AliOssConfig.AccessKeyId, AppConfig.AliOssConfig.AccessKeySecret);
-
-        /// <summary>
-        /// 上传图片
-        /// </summary>
-        /// <param name="file"></param>
-        /// <returns></returns>
-        public static (string url, bool success) UploadImage(string file)
-        {
-            if (AppConfig.GiteeConfig.Enabled)
-            {
-                return UploadGitee(file);
-            }
-
-            if (AppConfig.GitlabConfig.Enabled)
-            {
-                return UploadGitlab(file);
-            }
-
-            if (AppConfig.AliOssConfig.Enabled)
-            {
-                return UploadOss(file);
-            }
-
-            return UploadSmms(file);
-        }
-
-        /// <summary>
-        /// 码云图床
-        /// </summary>
-        /// <param name="file"></param>
-        /// <returns></returns>
-        public static (string url, bool success) UploadGitee(string file)
-        {
-            if (!file.Contains(new[] { ".jpg", ".jpeg", ".gif", ".png", ".bmp" }))
-            {
-                return (null, false);
-            }
-
-            using (Image image = Image.FromFile(file))
-            {
-                using (MemoryStream m = new MemoryStream())
-                {
-                    image.Save(m, image.RawFormat);
-                    string base64String = Convert.ToBase64String(m.ToArray());
-                    using (HttpClient httpClient = new HttpClient())
-                    {
-                        string path = $"{DateTime.Now:yyyyMMdd}/{Path.GetFileName(file)}";
-                        using (var resp = httpClient.PostAsJsonAsync(AppConfig.GiteeConfig.ApiUrl + path, new
-                        {
-                            access_token = AppConfig.GiteeConfig.AccessToken,
-                            content = base64String,
-                            message = "上传一张图片"
-                        }).Result)
-                        {
-                            if (resp.IsSuccessStatusCode || resp.Content.ReadAsStringAsync().Result.Contains("already exists"))
-                            {
-                                return (AppConfig.GiteeConfig.RawUrl + path, true);
-                            }
-                        }
-                    }
-
-                    return UploadSmms(file);
-                }
-            }
-        }
-
-        /// <summary>
-        /// gitlab图床
-        /// </summary>
-        /// <param name="file"></param>
-        /// <returns></returns>
-        public static (string url, bool success) UploadGitlab(string file)
-        {
-            if (!file.Contains(new[] { ".jpg", ".jpeg", ".gif", ".png", ".bmp" }))
-            {
-                return (null, false);
-            }
-
-            using (Image image = Image.FromFile(file))
-            {
-                using (MemoryStream m = new MemoryStream())
-                {
-                    image.Save(m, image.RawFormat);
-                    string base64String = Convert.ToBase64String(m.ToArray());
-                    using (HttpClient httpClient = new HttpClient())
-                    {
-                        httpClient.DefaultRequestHeaders.Add("PRIVATE-TOKEN", AppConfig.GitlabConfig.AccessToken);
-                        string path = $"{DateTime.Now:yyyyMMdd}/{Path.GetFileName(file)}";
-                        using (var resp = httpClient.PostAsJsonAsync(AppConfig.GitlabConfig.ApiUrl + path, new
-                        {
-                            branch = AppConfig.GitlabConfig.Branch,
-                            author_email = "[email protected]",
-                            author_name = "ldqk",
-                            encoding = "base64",
-                            content = base64String,
-                            commit_message = "上传一张图片"
-                        }).Result)
-                        {
-                            if (resp.IsSuccessStatusCode || resp.Content.ReadAsStringAsync().Result.Contains("already exists"))
-                            {
-                                return (AppConfig.GitlabConfig.RawUrl + path, true);
-                            }
-                        }
-                    }
-
-                    return UploadSmms(file);
-                }
-            }
-        }
-
-        /// <summary>
-        /// 阿里云Oss图床
-        /// </summary>
-        /// <param name="file"></param>
-        /// <returns></returns>
-        public static (string url, bool success) UploadOss(string file)
-        {
-            var objectName = DateTime.Now.ToString("yyyyMMdd") + "/" + SnowFlake.NewId + Path.GetExtension(file);
-            var result = Policy.Handle<Exception>().Retry(5, (e, i) =>
-            {
-                Console.ForegroundColor = ConsoleColor.Red;
-                Console.WriteLine(e.Message);
-                Console.ResetColor();
-            }).Execute(() => OssClient.PutObject(AppConfig.AliOssConfig.BucketName, objectName, file));
-            return result.HttpStatusCode == HttpStatusCode.OK ? (AppConfig.AliOssConfig.BucketDomain + "/" + objectName, true) : UploadSmms(file);
-        }
-
-        /// <summary>
-        /// 上传图片到sm图床
-        /// </summary>
-        /// <returns></returns>
-        public static (string url, bool success) UploadSmms(string file)
-        {
-            string url = string.Empty;
-            bool success = false;
-            using (var fs = File.OpenRead(file))
-            {
-                using (HttpClient httpClient = new HttpClient())
-                {
-                    httpClient.DefaultRequestHeaders.UserAgent.Add(ProductInfoHeaderValue.Parse("Mozilla/5.0"));
-                    using (var bc = new StreamContent(fs))
-                    {
-                        bc.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
-                        {
-                            FileName = Path.GetFileName(file),
-                            Name = "smfile"
-                        };
-                        using (var content = new MultipartFormDataContent { bc })
-                        {
-                            var code = httpClient.PostAsync("https://sm.ms/api/upload?inajax=1&ssl=1", content).ContinueWith(t =>
-                            {
-                                if (t.IsCanceled || t.IsFaulted)
-                                {
-                                    return 0;
-                                }
-
-                                var res = t.Result;
-                                if (res.IsSuccessStatusCode)
-                                {
-                                    try
-                                    {
-                                        string s = res.Content.ReadAsStringAsync().Result;
-                                        var token = JObject.Parse(s);
-                                        url = (string)token["data"]["url"];
-                                        return 1;
-                                    }
-                                    catch
-                                    {
-                                        return 2;
-                                    }
-                                }
-
-                                return 2;
-                            }).Result;
-                            if (code == 1)
-                            {
-                                success = true;
-                            }
-                        }
-                    }
-                }
-            }
-
-            return success ? (url, true) : UploadPeople(file);
-        }
-
-        /// <summary>
-        /// 上传图片到人民网图床
-        /// </summary>
-        /// <param name="file"></param>
-        /// <returns></returns>
-        public static (string url, bool success) UploadPeople(string file)
-        {
-            bool success = false;
-            using (var httpClient = new HttpClient())
-            {
-                httpClient.DefaultRequestHeaders.UserAgent.Add(ProductInfoHeaderValue.Parse("Chrome/72.0.3626.96"));
-                using (var stream = File.OpenRead(file))
-                {
-                    using (var sc = new StreamContent(stream))
-                    {
-                        using (var mc = new MultipartFormDataContent
-                        {
-                            { sc, "Filedata", Path.GetFileName(file) },
-                            {new StringContent("."+Path.GetExtension(file)),"filetype"}
-                        })
-                        {
-                            var str = httpClient.PostAsync("http://bbs1.people.com.cn/postImageUpload.do", mc).ContinueWith(t =>
-                            {
-                                if (t.IsCompletedSuccessfully)
-                                {
-                                    var res = t.Result;
-                                    if (res.IsSuccessStatusCode)
-                                    {
-                                        string result = res.Content.ReadAsStringAsync().Result;
-                                        string url = "http://bbs1.people.com.cn" + (string)JObject.Parse(result)["imageUrl"];
-                                        if (url.EndsWith(Path.GetExtension(file)))
-                                        {
-                                            success = true;
-                                            return url;
-                                        }
-                                    }
-                                }
-
-                                return "";
-                            }).Result;
-                            return (str, success);
-                        }
-                    }
-                }
-            }
-        }
-
-        #endregion
-        /// <summary>
-        /// 替换img标签的src属性
-        /// </summary>
-        /// <param name="content"></param>
-        /// <returns></returns>
-        public static string ReplaceImgSrc(string content)
-        {
-            var srcs = content.MatchImgSrcs();
-            foreach (string src in srcs)
-            {
-                if (!src.StartsWith("http"))
-                {
-                    var path = Path.Combine(AppContext.BaseDirectory + "wwwroot", src.Replace("/", @"\").Substring(1));
-                    if (File.Exists(path))
-                    {
-                        var (url, success) = UploadImage(path);
-                        if (success)
-                        {
-                            content = content.Replace(src, url);
-                            BackgroundJob.Enqueue(() => File.Delete(path));
-                        }
-                    }
-                }
-            }
-
-            return content;
-        }
-
         /// <summary>
         /// <summary>
         /// 是否是机器人访问
         /// 是否是机器人访问
         /// </summary>
         /// </summary>

+ 265 - 0
src/Masuit.MyBlogs.Core/Common/ImagebedClient.cs

@@ -0,0 +1,265 @@
+using Aliyun.OSS;
+using Hangfire;
+using Masuit.MyBlogs.Core.Configs;
+using Masuit.Tools.Html;
+using Masuit.Tools.Systems;
+using Newtonsoft.Json.Linq;
+using Polly;
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using System.Threading.Tasks;
+using System.Web;
+
+namespace Masuit.MyBlogs.Core.Common
+{
+    /// <summary>
+    /// 图床客户端
+    /// </summary>
+    public class ImagebedClient
+    {
+        private readonly HttpClient _httpClient;
+
+        /// <summary>
+        /// 图床客户端
+        /// </summary>
+        /// <param name="httpClient"></param>
+        public ImagebedClient(HttpClient httpClient)
+        {
+            _httpClient = httpClient;
+        }
+
+        /// <summary>
+        /// OSS客户端
+        /// </summary>
+        public static OssClient OssClient { get; set; } = new OssClient(AppConfig.AliOssConfig.EndPoint, AppConfig.AliOssConfig.AccessKeyId, AppConfig.AliOssConfig.AccessKeySecret);
+
+        /// <summary>
+        /// 上传图片
+        /// </summary>
+        /// <param name="stream"></param>
+        /// <param name="file"></param>
+        /// <returns></returns>
+        public async Task<(string url, bool success)> UploadImage(Stream stream, string file)
+        {
+            if (AppConfig.GiteeConfig.Enabled)
+            {
+                return await UploadGitee(stream, file);
+            }
+
+            if (AppConfig.GitlabConfig.Enabled)
+            {
+                return await UploadGitlab(stream, file);
+            }
+
+            if (AppConfig.AliOssConfig.Enabled)
+            {
+                return await UploadOss(stream, file);
+            }
+
+            return await UploadSmms(stream, file);
+        }
+
+        /// <summary>
+        /// 码云图床
+        /// </summary>
+        /// <param name="stream"></param>
+        /// <param name="file"></param>
+        /// <returns></returns>
+        public async Task<(string url, bool success)> UploadGitee(Stream stream, string file)
+        {
+            string base64String = Convert.ToBase64String(stream.ToByteArray());
+            string path = $"{DateTime.Now:yyyyMMdd}/{Path.GetFileName(file)}";
+            using (var resp = await _httpClient.PostAsJsonAsync(AppConfig.GiteeConfig.ApiUrl + HttpUtility.UrlEncode(path), new
+            {
+                access_token = AppConfig.GiteeConfig.AccessToken,
+                content = base64String,
+                message = "上传一张图片"
+            }))
+            {
+                if (resp.IsSuccessStatusCode || (await resp.Content.ReadAsStringAsync()).Contains("already exists"))
+                {
+                    return (AppConfig.GiteeConfig.RawUrl + path, true);
+                }
+            }
+
+            return await UploadSmms(stream, file);
+        }
+
+        /// <summary>
+        /// gitlab图床
+        /// </summary>
+        /// <param name="stream"></param>
+        /// <param name="file"></param>
+        /// <returns></returns>
+        public async Task<(string url, bool success)> UploadGitlab(Stream stream, string file)
+        {
+            string base64String = Convert.ToBase64String(stream.ToByteArray());
+            _httpClient.DefaultRequestHeaders.Add("PRIVATE-TOKEN", AppConfig.GitlabConfig.AccessToken);
+            string path = $"{DateTime.Now:yyyyMMdd}/{Path.GetFileName(file)}";
+            using (var resp = await _httpClient.PostAsJsonAsync(AppConfig.GitlabConfig.ApiUrl + HttpUtility.UrlEncode(path), new
+            {
+                branch = AppConfig.GitlabConfig.Branch,
+                author_email = "[email protected]",
+                author_name = "ldqk",
+                encoding = "base64",
+                content = base64String,
+                commit_message = "上传一张图片"
+            }))
+            {
+                if (resp.IsSuccessStatusCode || (await resp.Content.ReadAsStringAsync()).Contains("already exists"))
+                {
+                    return (AppConfig.GitlabConfig.RawUrl + path, true);
+                }
+            }
+
+            return await UploadSmms(stream, file);
+        }
+
+        /// <summary>
+        /// 阿里云Oss图床
+        /// </summary>
+        /// <param name="stream"></param>
+        /// <param name="file"></param>
+        /// <returns></returns>
+        public async Task<(string url, bool success)> UploadOss(Stream stream, string file)
+        {
+            var objectName = DateTime.Now.ToString("yyyyMMdd") + "/" + SnowFlake.NewId + Path.GetExtension(file);
+            var result = Policy.Handle<Exception>().Retry(5, (e, i) =>
+            {
+                Console.ForegroundColor = ConsoleColor.Red;
+                Console.WriteLine(e.Message);
+                Console.ResetColor();
+            }).Execute(() => OssClient.PutObject(AppConfig.AliOssConfig.BucketName, objectName, stream));
+            return result.HttpStatusCode == HttpStatusCode.OK ? (AppConfig.AliOssConfig.BucketDomain + "/" + objectName, true) : await UploadSmms(stream, file);
+        }
+
+        /// <summary>
+        /// 上传图片到sm图床
+        /// </summary>
+        /// <returns></returns>
+        public async Task<(string url, bool success)> UploadSmms(Stream stream, string file)
+        {
+            string url = string.Empty;
+            bool success = false;
+            _httpClient.DefaultRequestHeaders.UserAgent.Add(ProductInfoHeaderValue.Parse("Mozilla/5.0"));
+            using (var bc = new StreamContent(stream))
+            {
+                bc.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
+                {
+                    FileName = Path.GetFileName(file),
+                    Name = "smfile"
+                };
+                using (var content = new MultipartFormDataContent { bc })
+                {
+                    var code = await _httpClient.PostAsync("https://sm.ms/api/upload?inajax=1&ssl=1", content).ContinueWith(t =>
+                    {
+                        if (t.IsCanceled || t.IsFaulted)
+                        {
+                            return 0;
+                        }
+
+                        var res = t.Result;
+                        if (res.IsSuccessStatusCode)
+                        {
+                            try
+                            {
+                                string s = res.Content.ReadAsStringAsync().Result;
+                                var token = JObject.Parse(s);
+                                url = (string)token["data"]["url"];
+                                return 1;
+                            }
+                            catch
+                            {
+                                return 2;
+                            }
+                        }
+
+                        return 2;
+                    });
+                    if (code == 1)
+                    {
+                        success = true;
+                    }
+                }
+            }
+
+            return success ? (url, true) : await UploadPeople(stream, file);
+        }
+
+        /// <summary>
+        /// 上传图片到人民网图床
+        /// </summary>
+        /// <param name="stream"></param>
+        /// <param name="file"></param>
+        /// <returns></returns>
+        public async Task<(string url, bool success)> UploadPeople(Stream stream, string file)
+        {
+            bool success = false;
+            _httpClient.DefaultRequestHeaders.UserAgent.Add(ProductInfoHeaderValue.Parse("Chrome/72.0.3626.96"));
+            using (var sc = new StreamContent(stream))
+            {
+                using (var mc = new MultipartFormDataContent
+                {
+                    { sc, "Filedata", Path.GetFileName(file) },
+                    {new StringContent("."+Path.GetExtension(file)),"filetype"}
+                })
+                {
+                    var str = await _httpClient.PostAsync("http://bbs1.people.com.cn/postImageUpload.do", mc).ContinueWith(t =>
+                    {
+                        if (t.IsCompletedSuccessfully)
+                        {
+                            var res = t.Result;
+                            if (res.IsSuccessStatusCode)
+                            {
+                                string result = res.Content.ReadAsStringAsync().Result;
+                                string url = "http://bbs1.people.com.cn" + (string)JObject.Parse(result)["imageUrl"];
+                                if (url.EndsWith(Path.GetExtension(file)))
+                                {
+                                    success = true;
+                                    return url;
+                                }
+                            }
+                        }
+
+                        return "";
+                    });
+                    return (str, success);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 替换img标签的src属性
+        /// </summary>
+        /// <param name="content"></param>
+        /// <returns></returns>
+        public async Task<string> ReplaceImgSrc(string content)
+        {
+            var srcs = content.MatchImgSrcs();
+            foreach (string src in srcs)
+            {
+                if (!src.StartsWith("http"))
+                {
+                    var path = Path.Combine(AppContext.BaseDirectory + "wwwroot", src.Replace("/", @"\").Substring(1));
+                    if (File.Exists(path))
+                    {
+                        using (var stream = File.OpenRead(path))
+                        {
+                            var (url, success) = await UploadImage(stream, path);
+                            if (success)
+                            {
+                                content = content.Replace(src, url);
+                                BackgroundJob.Enqueue(() => File.Delete(path));
+                            }
+                        }
+                    }
+                }
+            }
+
+            return content;
+        }
+    }
+}

+ 10 - 5
src/Masuit.MyBlogs.Core/Controllers/MiscController.cs

@@ -13,7 +13,9 @@ using Microsoft.Net.Http.Headers;
 using System;
 using System;
 using System.IO;
 using System.IO;
 using System.Linq;
 using System.Linq;
+using System.Net.Http;
 using System.Text.RegularExpressions;
 using System.Text.RegularExpressions;
+using System.Threading.Tasks;
 
 
 namespace Masuit.MyBlogs.Core.Controllers
 namespace Masuit.MyBlogs.Core.Controllers
 {
 {
@@ -33,6 +35,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         public IDonateService DonateService { get; set; }
         public IDonateService DonateService { get; set; }
 
 
         private readonly IHostingEnvironment _hostingEnvironment;
         private readonly IHostingEnvironment _hostingEnvironment;
+        private readonly ImagebedClient _imagebedClient;
 
 
         /// <summary>
         /// <summary>
         /// 杂项页
         /// 杂项页
@@ -40,11 +43,13 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <param name="miscService"></param>
         /// <param name="miscService"></param>
         /// <param name="donateService"></param>
         /// <param name="donateService"></param>
         /// <param name="hostingEnvironment"></param>
         /// <param name="hostingEnvironment"></param>
-        public MiscController(IMiscService miscService, IDonateService donateService, IHostingEnvironment hostingEnvironment)
+        /// <param name="httpClientFactory"></param>
+        public MiscController(IMiscService miscService, IDonateService donateService, IHostingEnvironment hostingEnvironment, IHttpClientFactory httpClientFactory)
         {
         {
             MiscService = miscService;
             MiscService = miscService;
             DonateService = donateService;
             DonateService = donateService;
             _hostingEnvironment = hostingEnvironment;
             _hostingEnvironment = hostingEnvironment;
+            _imagebedClient = new ImagebedClient(httpClientFactory.CreateClient());
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -126,9 +131,9 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <param name="model"></param>
         /// <param name="model"></param>
         /// <returns></returns>
         /// <returns></returns>
         [Authority]
         [Authority]
-        public ActionResult Write(Misc model)
+        public async Task<ActionResult> Write(Misc model)
         {
         {
-            model.Content = CommonHelper.ReplaceImgSrc(Regex.Replace(model.Content?.Trim(), @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>")).Replace("/thumb150/", "/large/");
+            model.Content = (await _imagebedClient.ReplaceImgSrc(Regex.Replace(model.Content?.Trim(), @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>"))).Replace("/thumb150/", "/large/");
             var e = MiscService.AddEntitySaved(model);
             var e = MiscService.AddEntitySaved(model);
             if (e != null)
             if (e != null)
             {
             {
@@ -175,12 +180,12 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <param name="misc"></param>
         /// <param name="misc"></param>
         /// <returns></returns>
         /// <returns></returns>
         [Authority]
         [Authority]
-        public ActionResult Edit(Misc misc)
+        public async Task<ActionResult> Edit(Misc misc)
         {
         {
             var entity = MiscService.GetById(misc.Id);
             var entity = MiscService.GetById(misc.Id);
             entity.ModifyDate = DateTime.Now;
             entity.ModifyDate = DateTime.Now;
             entity.Title = misc.Title;
             entity.Title = misc.Title;
-            entity.Content = CommonHelper.ReplaceImgSrc(Regex.Replace(misc.Content, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>")).Replace("/thumb150/", "/large/");
+            entity.Content = (await _imagebedClient.ReplaceImgSrc(Regex.Replace(misc.Content, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>"))).Replace("/thumb150/", "/large/");
             bool b = MiscService.UpdateEntitySaved(entity);
             bool b = MiscService.UpdateEntitySaved(entity);
             return ResultData(null, b, b ? "修改成功" : "修改失败");
             return ResultData(null, b, b ? "修改成功" : "修改失败");
         }
         }

+ 10 - 5
src/Masuit.MyBlogs.Core/Controllers/NoticeController.cs

@@ -15,7 +15,9 @@ using Microsoft.Net.Http.Headers;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
+using System.Net.Http;
 using System.Text.RegularExpressions;
 using System.Text.RegularExpressions;
+using System.Threading.Tasks;
 
 
 namespace Masuit.MyBlogs.Core.Controllers
 namespace Masuit.MyBlogs.Core.Controllers
 {
 {
@@ -31,15 +33,18 @@ namespace Masuit.MyBlogs.Core.Controllers
 
 
         private readonly IHostingEnvironment _hostingEnvironment;
         private readonly IHostingEnvironment _hostingEnvironment;
 
 
+        private readonly ImagebedClient _imagebedClient;
+
         /// <summary>
         /// <summary>
         /// 网站公告
         /// 网站公告
         /// </summary>
         /// </summary>
         /// <param name="noticeService"></param>
         /// <param name="noticeService"></param>
         /// <param name="hostingEnvironment"></param>
         /// <param name="hostingEnvironment"></param>
-        public NoticeController(INoticeService noticeService, IHostingEnvironment hostingEnvironment)
+        public NoticeController(INoticeService noticeService, IHostingEnvironment hostingEnvironment, IHttpClientFactory httpClientFactory)
         {
         {
             NoticeService = noticeService;
             NoticeService = noticeService;
             _hostingEnvironment = hostingEnvironment;
             _hostingEnvironment = hostingEnvironment;
+            _imagebedClient = new ImagebedClient(httpClientFactory.CreateClient());
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -97,9 +102,9 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <param name="notice"></param>
         /// <param name="notice"></param>
         /// <returns></returns>
         /// <returns></returns>
         [Authority]
         [Authority]
-        public ActionResult Write(Notice notice)
+        public async Task<ActionResult> Write(Notice notice)
         {
         {
-            notice.Content = CommonHelper.ReplaceImgSrc(Regex.Replace(notice.Content, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>")).Replace("/thumb150/", "/large/");
+            notice.Content = (await _imagebedClient.ReplaceImgSrc(Regex.Replace(notice.Content, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>"))).Replace("/thumb150/", "/large/");
             Notice e = NoticeService.AddEntitySaved(notice);
             Notice e = NoticeService.AddEntitySaved(notice);
             if (e != null)
             if (e != null)
             {
             {
@@ -146,12 +151,12 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <param name="notice"></param>
         /// <param name="notice"></param>
         /// <returns></returns>
         /// <returns></returns>
         [Authority]
         [Authority]
-        public ActionResult Edit(Notice notice)
+        public async Task<ActionResult> Edit(Notice notice)
         {
         {
             Notice entity = NoticeService.GetById(notice.Id);
             Notice entity = NoticeService.GetById(notice.Id);
             entity.ModifyDate = DateTime.Now;
             entity.ModifyDate = DateTime.Now;
             entity.Title = notice.Title;
             entity.Title = notice.Title;
-            entity.Content = CommonHelper.ReplaceImgSrc(Regex.Replace(notice.Content, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>")).Replace("/thumb150/", "/large/");
+            entity.Content = (await _imagebedClient.ReplaceImgSrc(Regex.Replace(notice.Content, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>"))).Replace("/thumb150/", "/large/");
             bool b = NoticeService.UpdateEntitySaved(entity);
             bool b = NoticeService.UpdateEntitySaved(entity);
             return ResultData(null, b, b ? "修改成功" : "修改失败");
             return ResultData(null, b, b ? "修改成功" : "修改失败");
         }
         }

+ 11 - 7
src/Masuit.MyBlogs.Core/Controllers/PostController.cs

@@ -27,7 +27,9 @@ using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.IO;
 using System.IO;
 using System.Linq;
 using System.Linq;
+using System.Net.Http;
 using System.Text.RegularExpressions;
 using System.Text.RegularExpressions;
+using System.Threading.Tasks;
 
 
 namespace Masuit.MyBlogs.Core.Controllers
 namespace Masuit.MyBlogs.Core.Controllers
 {
 {
@@ -44,6 +46,7 @@ namespace Masuit.MyBlogs.Core.Controllers
 
 
         private readonly IHostingEnvironment _hostingEnvironment;
         private readonly IHostingEnvironment _hostingEnvironment;
         private readonly ISearchEngine<DataContext> _searchEngine;
         private readonly ISearchEngine<DataContext> _searchEngine;
+        private readonly ImagebedClient _imagebedClient;
 
 
         /// <summary>
         /// <summary>
         /// 文章管理
         /// 文章管理
@@ -55,7 +58,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <param name="postHistoryVersionService"></param>
         /// <param name="postHistoryVersionService"></param>
         /// <param name="hostingEnvironment"></param>
         /// <param name="hostingEnvironment"></param>
         /// <param name="searchEngine"></param>
         /// <param name="searchEngine"></param>
-        public PostController(IPostService postService, ICategoryService categoryService, IBroadcastService broadcastService, ISeminarService seminarService, IPostHistoryVersionService postHistoryVersionService, IHostingEnvironment hostingEnvironment, ISearchEngine<DataContext> searchEngine)
+        public PostController(IPostService postService, ICategoryService categoryService, IBroadcastService broadcastService, ISeminarService seminarService, IPostHistoryVersionService postHistoryVersionService, IHostingEnvironment hostingEnvironment, ISearchEngine<DataContext> searchEngine, IHttpClientFactory httpClientFactory)
         {
         {
             PostService = postService;
             PostService = postService;
             CategoryService = categoryService;
             CategoryService = categoryService;
@@ -64,6 +67,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             PostHistoryVersionService = postHistoryVersionService;
             PostHistoryVersionService = postHistoryVersionService;
             _hostingEnvironment = hostingEnvironment;
             _hostingEnvironment = hostingEnvironment;
             _searchEngine = searchEngine;
             _searchEngine = searchEngine;
+            _imagebedClient = new ImagebedClient(httpClientFactory.CreateClient());
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -271,7 +275,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <param name="post"></param>
         /// <param name="post"></param>
         /// <returns></returns>
         /// <returns></returns>
         [HttpPost, ValidateAntiForgeryToken]
         [HttpPost, ValidateAntiForgeryToken]
-        public ActionResult Publish(PostInputDto post)
+        public async Task<ActionResult> Publish(PostInputDto post)
         {
         {
             if (Regex.Match(post.Content, CommonHelper.BanRegex).Length > 0)
             if (Regex.Match(post.Content, CommonHelper.BanRegex).Length > 0)
             {
             {
@@ -306,7 +310,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             }
             }
             else
             else
             {
             {
-                post.Content = CommonHelper.ReplaceImgSrc(Regex.Replace(post.Content.HtmlSantinizerStandard(), @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>")).Replace("/thumb150/", "/large/");
+                post.Content = (await _imagebedClient.ReplaceImgSrc(Regex.Replace(post.Content.HtmlSantinizerStandard(), @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>"))).Replace("/thumb150/", "/large/");
             }
             }
 
 
             ViewBag.CategoryId = new SelectList(CategoryService.LoadEntitiesNoTracking(c => c.Status == Status.Available), "Id", "Name", post.CategoryId);
             ViewBag.CategoryId = new SelectList(CategoryService.LoadEntitiesNoTracking(c => c.Status == Status.Available), "Id", "Name", post.CategoryId);
@@ -765,9 +769,9 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <param name="reserve"></param>
         /// <param name="reserve"></param>
         /// <returns></returns>
         /// <returns></returns>
         [HttpPost, Authority]
         [HttpPost, Authority]
-        public ActionResult Edit(PostInputDto post, bool notify = true, bool reserve = true)
+        public async Task<ActionResult> Edit(PostInputDto post, bool notify = true, bool reserve = true)
         {
         {
-            post.Content = CommonHelper.ReplaceImgSrc(Regex.Replace(post.Content.Trim(), @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>"));
+            post.Content = await _imagebedClient.ReplaceImgSrc(Regex.Replace(post.Content.Trim(), @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>"));
             if (!CategoryService.Any(c => c.Id == post.CategoryId && c.Status == Status.Available))
             if (!CategoryService.Any(c => c.Id == post.CategoryId && c.Status == Status.Available))
             {
             {
                 return ResultData(null, message: "请选择一个分类");
                 return ResultData(null, message: "请选择一个分类");
@@ -868,9 +872,9 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <param name="schedule"></param>
         /// <param name="schedule"></param>
         /// <returns></returns>
         /// <returns></returns>
         [Authority, HttpPost]
         [Authority, HttpPost]
-        public ActionResult Write(PostInputDto post, DateTime? timespan, bool schedule = false)
+        public async Task<ActionResult> Write(PostInputDto post, DateTime? timespan, bool schedule = false)
         {
         {
-            post.Content = CommonHelper.ReplaceImgSrc(Regex.Replace(post.Content.Trim(), @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>")).Replace("/thumb150/", "/large/"); //提取img标签,提取src属性并重新创建个只包含src属性的img标签
+            post.Content = (await _imagebedClient.ReplaceImgSrc(Regex.Replace(post.Content.Trim(), @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>"))).Replace("/thumb150/", "/large/"); //提取img标签,提取src属性并重新创建个只包含src属性的img标签
             if (!CategoryService.Any(c => c.Id == post.CategoryId && c.Status == Status.Available))
             if (!CategoryService.Any(c => c.Id == post.CategoryId && c.Status == Status.Available))
             {
             {
                 return ResultData(null, message: "请选择一个分类");
                 return ResultData(null, message: "请选择一个分类");

+ 14 - 10
src/Masuit.MyBlogs.Core/Controllers/UploadController.cs

@@ -1,5 +1,4 @@
-using Hangfire;
-using Masuit.MyBlogs.Core.Common;
+using Masuit.MyBlogs.Core.Common;
 using Masuit.MyBlogs.Core.Extensions.UEditor;
 using Masuit.MyBlogs.Core.Extensions.UEditor;
 using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.MyBlogs.Core.Models.ViewModel;
@@ -16,9 +15,11 @@ using Microsoft.AspNetCore.Mvc;
 using Newtonsoft.Json;
 using Newtonsoft.Json;
 using System;
 using System;
 using System.IO;
 using System.IO;
+using System.Net.Http;
 using System.Text;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Text.RegularExpressions;
 using System.Threading;
 using System.Threading;
+using System.Threading.Tasks;
 
 
 namespace Masuit.MyBlogs.Core.Controllers
 namespace Masuit.MyBlogs.Core.Controllers
 {
 {
@@ -30,13 +31,16 @@ namespace Masuit.MyBlogs.Core.Controllers
     {
     {
         private readonly IHostingEnvironment _hostingEnvironment;
         private readonly IHostingEnvironment _hostingEnvironment;
 
 
+        private readonly ImagebedClient _imagebedClient;
+
         /// <summary>
         /// <summary>
         /// 文件上传
         /// 文件上传
         /// </summary>
         /// </summary>
         /// <param name="hostingEnvironment"></param>
         /// <param name="hostingEnvironment"></param>
-        public UploadController(IHostingEnvironment hostingEnvironment)
+        public UploadController(IHostingEnvironment hostingEnvironment, IHttpClientFactory httpClientFactory)
         {
         {
             _hostingEnvironment = hostingEnvironment;
             _hostingEnvironment = hostingEnvironment;
+            _imagebedClient = new ImagebedClient(httpClientFactory.CreateClient());
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -245,13 +249,19 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <param name="file"></param>
         /// <param name="file"></param>
         /// <returns></returns>
         /// <returns></returns>
         [HttpPost("upload"), ApiExplorerSettings(IgnoreApi = false)]
         [HttpPost("upload"), ApiExplorerSettings(IgnoreApi = false)]
-        public ActionResult UploadFile(IFormFile file)
+        public async Task<ActionResult> UploadFile(IFormFile file)
         {
         {
             string path;
             string path;
             string filename = SnowFlake.GetInstance().GetUniqueId() + Path.GetExtension(file.FileName);
             string filename = SnowFlake.GetInstance().GetUniqueId() + Path.GetExtension(file.FileName);
             switch (file.ContentType)
             switch (file.ContentType)
             {
             {
                 case var _ when file.ContentType.StartsWith("image"):
                 case var _ when file.ContentType.StartsWith("image"):
+                    var (url, success) = await _imagebedClient.UploadImage(file.OpenReadStream(), file.FileName);
+                    if (success)
+                    {
+                        //BackgroundJob.Enqueue(() => System.IO.File.Delete(path));
+                        return ResultData(url);
+                    }
                     path = Path.Combine(_hostingEnvironment.WebRootPath, "upload", "images", filename);
                     path = Path.Combine(_hostingEnvironment.WebRootPath, "upload", "images", filename);
                     var dir = Path.GetDirectoryName(path);
                     var dir = Path.GetDirectoryName(path);
                     if (!Directory.Exists(dir))
                     if (!Directory.Exists(dir))
@@ -262,12 +272,6 @@ namespace Masuit.MyBlogs.Core.Controllers
                     {
                     {
                         file.CopyTo(fs);
                         file.CopyTo(fs);
                     }
                     }
-                    var (url, success) = CommonHelper.UploadImage(path);
-                    if (success)
-                    {
-                        BackgroundJob.Enqueue(() => System.IO.File.Delete(path));
-                        return ResultData(url);
-                    }
                     break;
                     break;
                 case var _ when file.ContentType.StartsWith("audio") || file.ContentType.StartsWith("video"):
                 case var _ when file.ContentType.StartsWith("audio") || file.ContentType.StartsWith("video"):
                     path = Path.Combine(_hostingEnvironment.WebRootPath, "upload", "media", filename);
                     path = Path.Combine(_hostingEnvironment.WebRootPath, "upload", "media", filename);

+ 20 - 13
src/Masuit.MyBlogs.Core/Extensions/UEditor/CrawlerHandler.cs

@@ -7,6 +7,7 @@ using System;
 using System.IO;
 using System.IO;
 using System.Linq;
 using System.Linq;
 using System.Net;
 using System.Net;
+using System.Net.Http;
 
 
 namespace Masuit.MyBlogs.Core.Extensions.UEditor
 namespace Masuit.MyBlogs.Core.Extensions.UEditor
 {
 {
@@ -84,20 +85,26 @@ namespace Masuit.MyBlogs.Core.Extensions.UEditor
                     using (var stream = response.GetResponseStream())
                     using (var stream = response.GetResponseStream())
                     {
                     {
                         var savePath = AppContext.BaseDirectory + "wwwroot" + ServerUrl;
                         var savePath = AppContext.BaseDirectory + "wwwroot" + ServerUrl;
-                        if (!Directory.Exists(Path.GetDirectoryName(savePath)))
+                        using (var httpClient = new HttpClient())
                         {
                         {
-                            Directory.CreateDirectory(Path.GetDirectoryName(savePath));
-                        }
-                        using (var ms = new MemoryStream())
-                        {
-                            stream.CopyTo(ms);
-                            File.WriteAllBytes(savePath, ms.GetBuffer());
-                        }
-                        var (url, success) = CommonHelper.UploadImage(savePath);
-                        if (success)
-                        {
-                            BackgroundJob.Enqueue(() => File.Delete(savePath));
-                            ServerUrl = url;
+                            var (url, success) = new ImagebedClient(httpClient).UploadImage(stream, savePath).Result;
+                            if (success)
+                            {
+                                BackgroundJob.Enqueue(() => File.Delete(savePath));
+                                ServerUrl = url;
+                            }
+                            else
+                            {
+                                if (!Directory.Exists(Path.GetDirectoryName(savePath)))
+                                {
+                                    Directory.CreateDirectory(Path.GetDirectoryName(savePath));
+                                }
+                                using (var ms = new MemoryStream())
+                                {
+                                    stream.CopyTo(ms);
+                                    File.WriteAllBytes(savePath, ms.GetBuffer());
+                                }
+                            }
                         }
                         }
                         State = "SUCCESS";
                         State = "SUCCESS";
                     }
                     }

+ 32 - 25
src/Masuit.MyBlogs.Core/Extensions/UEditor/UploadHandler.cs

@@ -1,9 +1,9 @@
-using Hangfire;
-using Masuit.MyBlogs.Core.Common;
+using Masuit.MyBlogs.Core.Common;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Http;
 using System;
 using System;
 using System.IO;
 using System.IO;
 using System.Linq;
 using System.Linq;
+using System.Net.Http;
 
 
 namespace Masuit.MyBlogs.Core.Extensions.UEditor
 namespace Masuit.MyBlogs.Core.Extensions.UEditor
 {
 {
@@ -40,16 +40,17 @@ namespace Masuit.MyBlogs.Core.Extensions.UEditor
                 return WriteResult();
                 return WriteResult();
             }
             }
 
 
-            var uploadFileBytes = new byte[file.Length];
-            try
-            {
-                file.OpenReadStream().Read(uploadFileBytes, 0, (int)file.Length);
-            }
-            catch (Exception)
-            {
-                Result.State = UploadState.NetworkError;
-                return WriteResult();
-            }
+            //var uploadFileBytes = new byte[file.Length];
+            //try
+            //{
+            //    file.OpenReadStream().Read(uploadFileBytes, 0, (int)file.Length);
+            //}
+            //catch (Exception)
+            //{
+            //    Result.State = UploadState.NetworkError;
+            //    return WriteResult();
+            //}
+
             Result.OriginFileName = uploadFileName;
             Result.OriginFileName = uploadFileName;
             var savePath = PathFormatter.Format(uploadFileName, UploadConfig.PathFormat);
             var savePath = PathFormatter.Format(uploadFileName, UploadConfig.PathFormat);
             var localPath = AppContext.BaseDirectory + "wwwroot" + savePath;
             var localPath = AppContext.BaseDirectory + "wwwroot" + savePath;
@@ -57,20 +58,26 @@ namespace Masuit.MyBlogs.Core.Extensions.UEditor
             {
             {
                 if (UploadConfig.AllowExtensions.Contains(Path.GetExtension(uploadFileName)))
                 if (UploadConfig.AllowExtensions.Contains(Path.GetExtension(uploadFileName)))
                 {
                 {
-                    if (!Directory.Exists(Path.GetDirectoryName(localPath)))
-                    {
-                        Directory.CreateDirectory(Path.GetDirectoryName(localPath));
-                    }
-                    File.WriteAllBytes(localPath, file.OpenReadStream().ToByteArray());
-                    var (url, success) = CommonHelper.UploadImage(localPath);
-                    if (success)
-                    {
-                        BackgroundJob.Enqueue(() => File.Delete(localPath));
-                        Result.Url = url;
-                    }
-                    else
+                    using (Stream stream = file.OpenReadStream())
                     {
                     {
-                        Result.Url = savePath;
+                        using (var httpClient = new HttpClient())
+                        {
+                            var (url, success) = new ImagebedClient(httpClient).UploadImage(stream, localPath).Result;
+                            if (success)
+                            {
+                                //BackgroundJob.Enqueue(() => File.Delete(localPath));
+                                Result.Url = url;
+                            }
+                            else
+                            {
+                                if (!Directory.Exists(Path.GetDirectoryName(localPath)))
+                                {
+                                    Directory.CreateDirectory(Path.GetDirectoryName(localPath));
+                                }
+                                File.WriteAllBytes(localPath, stream.ToByteArray());
+                                Result.Url = savePath;
+                            }
+                        }
                     }
                     }
                 }
                 }
                 else
                 else

+ 8 - 4
src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.csproj

@@ -23,6 +23,10 @@
     <None Remove="wwwroot\upload\**" />
     <None Remove="wwwroot\upload\**" />
   </ItemGroup>
   </ItemGroup>
 
 
+  <ItemGroup>
+    <Compile Remove="Controllers\TestController.cs" />
+  </ItemGroup>
+
   <ItemGroup>
   <ItemGroup>
     <Content Remove="bundleconfig.json" />
     <Content Remove="bundleconfig.json" />
   </ItemGroup>
   </ItemGroup>
@@ -65,10 +69,10 @@
     <PackageReference Include="Aspose.Words" Version="18.11.0" />
     <PackageReference Include="Aspose.Words" Version="18.11.0" />
     <PackageReference Include="Autofac" Version="4.9.2" />
     <PackageReference Include="Autofac" Version="4.9.2" />
     <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.4.0" />
     <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.4.0" />
-    <PackageReference Include="AutoMapper" Version="8.1.0" />
+    <PackageReference Include="AutoMapper" Version="8.1.1" />
     <PackageReference Include="CacheManager.Microsoft.Extensions.Caching.Memory" Version="1.2.0" />
     <PackageReference Include="CacheManager.Microsoft.Extensions.Caching.Memory" Version="1.2.0" />
     <PackageReference Include="CacheManager.Serialization.Json" Version="1.2.0" />
     <PackageReference Include="CacheManager.Serialization.Json" Version="1.2.0" />
-    <PackageReference Include="CSRedisCore" Version="3.0.59" />
+    <PackageReference Include="CSRedisCore" Version="3.0.60" />
     <PackageReference Include="EFSecondLevelCache.Core" Version="2.3.0" />
     <PackageReference Include="EFSecondLevelCache.Core" Version="2.3.0" />
     <PackageReference Include="Hangfire" Version="1.7.3" />
     <PackageReference Include="Hangfire" Version="1.7.3" />
     <PackageReference Include="Hangfire.Autofac" Version="2.3.1" />
     <PackageReference Include="Hangfire.Autofac" Version="2.3.1" />
@@ -83,8 +87,8 @@
     <PackageReference Include="Polly" Version="7.1.0" />
     <PackageReference Include="Polly" Version="7.1.0" />
     <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
     <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
     <PackageReference Include="WilderMinds.RssSyndication" Version="1.5.0" />
     <PackageReference Include="WilderMinds.RssSyndication" Version="1.5.0" />
-    <PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="2.3.5" />
-    <PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="1.9.0" />
+    <PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="2.4.0" />
+    <PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="1.9.1" />
     <PackageReference Include="Z.ExtensionMethods" Version="2.1.1" />
     <PackageReference Include="Z.ExtensionMethods" Version="2.1.1" />
   </ItemGroup>
   </ItemGroup>
 
 

+ 74 - 70
src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.xml

@@ -82,59 +82,6 @@
             <param name="content">内容</param>
             <param name="content">内容</param>
             <param name="tos">收件人</param>
             <param name="tos">收件人</param>
         </member>
         </member>
-        <member name="P:Masuit.MyBlogs.Core.Common.CommonHelper.OssClient">
-            <summary>
-            OSS客户端
-            </summary>
-        </member>
-        <member name="M:Masuit.MyBlogs.Core.Common.CommonHelper.UploadImage(System.String)">
-            <summary>
-            上传图片
-            </summary>
-            <param name="file"></param>
-            <returns></returns>
-        </member>
-        <member name="M:Masuit.MyBlogs.Core.Common.CommonHelper.UploadGitee(System.String)">
-            <summary>
-            码云图床
-            </summary>
-            <param name="file"></param>
-            <returns></returns>
-        </member>
-        <member name="M:Masuit.MyBlogs.Core.Common.CommonHelper.UploadGitlab(System.String)">
-            <summary>
-            gitlab图床
-            </summary>
-            <param name="file"></param>
-            <returns></returns>
-        </member>
-        <member name="M:Masuit.MyBlogs.Core.Common.CommonHelper.UploadOss(System.String)">
-            <summary>
-            阿里云Oss图床
-            </summary>
-            <param name="file"></param>
-            <returns></returns>
-        </member>
-        <member name="M:Masuit.MyBlogs.Core.Common.CommonHelper.UploadSmms(System.String)">
-            <summary>
-            上传图片到sm图床
-            </summary>
-            <returns></returns>
-        </member>
-        <member name="M:Masuit.MyBlogs.Core.Common.CommonHelper.UploadPeople(System.String)">
-            <summary>
-            上传图片到人民网图床
-            </summary>
-            <param name="file"></param>
-            <returns></returns>
-        </member>
-        <member name="M:Masuit.MyBlogs.Core.Common.CommonHelper.ReplaceImgSrc(System.String)">
-            <summary>
-            替换img标签的src属性
-            </summary>
-            <param name="content"></param>
-            <returns></returns>
-        </member>
         <member name="M:Masuit.MyBlogs.Core.Common.CommonHelper.IsRobot(Microsoft.AspNetCore.Http.HttpRequest)">
         <member name="M:Masuit.MyBlogs.Core.Common.CommonHelper.IsRobot(Microsoft.AspNetCore.Http.HttpRequest)">
             <summary>
             <summary>
             是否是机器人访问
             是否是机器人访问
@@ -226,6 +173,75 @@
             <param name="args">调用参数</param>
             <param name="args">调用参数</param>
             <returns></returns>
             <returns></returns>
         </member>
         </member>
+        <member name="T:Masuit.MyBlogs.Core.Common.ImagebedClient">
+            <summary>
+            图床客户端
+            </summary>
+        </member>
+        <member name="M:Masuit.MyBlogs.Core.Common.ImagebedClient.#ctor(System.Net.Http.HttpClient)">
+            <summary>
+            图床客户端
+            </summary>
+            <param name="httpClient"></param>
+        </member>
+        <member name="P:Masuit.MyBlogs.Core.Common.ImagebedClient.OssClient">
+            <summary>
+            OSS客户端
+            </summary>
+        </member>
+        <member name="M:Masuit.MyBlogs.Core.Common.ImagebedClient.UploadImage(System.IO.Stream,System.String)">
+            <summary>
+            上传图片
+            </summary>
+            <param name="stream"></param>
+            <param name="file"></param>
+            <returns></returns>
+        </member>
+        <member name="M:Masuit.MyBlogs.Core.Common.ImagebedClient.UploadGitee(System.IO.Stream,System.String)">
+            <summary>
+            码云图床
+            </summary>
+            <param name="stream"></param>
+            <param name="file"></param>
+            <returns></returns>
+        </member>
+        <member name="M:Masuit.MyBlogs.Core.Common.ImagebedClient.UploadGitlab(System.IO.Stream,System.String)">
+            <summary>
+            gitlab图床
+            </summary>
+            <param name="stream"></param>
+            <param name="file"></param>
+            <returns></returns>
+        </member>
+        <member name="M:Masuit.MyBlogs.Core.Common.ImagebedClient.UploadOss(System.IO.Stream,System.String)">
+            <summary>
+            阿里云Oss图床
+            </summary>
+            <param name="stream"></param>
+            <param name="file"></param>
+            <returns></returns>
+        </member>
+        <member name="M:Masuit.MyBlogs.Core.Common.ImagebedClient.UploadSmms(System.IO.Stream,System.String)">
+            <summary>
+            上传图片到sm图床
+            </summary>
+            <returns></returns>
+        </member>
+        <member name="M:Masuit.MyBlogs.Core.Common.ImagebedClient.UploadPeople(System.IO.Stream,System.String)">
+            <summary>
+            上传图片到人民网图床
+            </summary>
+            <param name="stream"></param>
+            <param name="file"></param>
+            <returns></returns>
+        </member>
+        <member name="M:Masuit.MyBlogs.Core.Common.ImagebedClient.ReplaceImgSrc(System.String)">
+            <summary>
+            替换img标签的src属性
+            </summary>
+            <param name="content"></param>
+            <returns></returns>
+        </member>
         <member name="T:Masuit.MyBlogs.Core.Configs.AppConfig">
         <member name="T:Masuit.MyBlogs.Core.Configs.AppConfig">
             <summary>
             <summary>
             应用程序配置
             应用程序配置
@@ -947,13 +963,14 @@
             捐赠
             捐赠
             </summary>
             </summary>
         </member>
         </member>
-        <member name="M:Masuit.MyBlogs.Core.Controllers.MiscController.#ctor(Masuit.MyBlogs.Core.Infrastructure.Services.Interface.IMiscService,Masuit.MyBlogs.Core.Infrastructure.Services.Interface.IDonateService,Microsoft.AspNetCore.Hosting.IHostingEnvironment)">
+        <member name="M:Masuit.MyBlogs.Core.Controllers.MiscController.#ctor(Masuit.MyBlogs.Core.Infrastructure.Services.Interface.IMiscService,Masuit.MyBlogs.Core.Infrastructure.Services.Interface.IDonateService,Microsoft.AspNetCore.Hosting.IHostingEnvironment,System.Net.Http.IHttpClientFactory)">
             <summary>
             <summary>
             杂项页
             杂项页
             </summary>
             </summary>
             <param name="miscService"></param>
             <param name="miscService"></param>
             <param name="donateService"></param>
             <param name="donateService"></param>
             <param name="hostingEnvironment"></param>
             <param name="hostingEnvironment"></param>
+            <param name="httpClientFactory"></param>
         </member>
         </member>
         <member name="M:Masuit.MyBlogs.Core.Controllers.MiscController.Index(System.Int32)">
         <member name="M:Masuit.MyBlogs.Core.Controllers.MiscController.Index(System.Int32)">
             <summary>
             <summary>
@@ -1147,7 +1164,7 @@
             公告
             公告
             </summary>
             </summary>
         </member>
         </member>
-        <member name="M:Masuit.MyBlogs.Core.Controllers.NoticeController.#ctor(Masuit.MyBlogs.Core.Infrastructure.Services.Interface.INoticeService,Microsoft.AspNetCore.Hosting.IHostingEnvironment)">
+        <member name="M:Masuit.MyBlogs.Core.Controllers.NoticeController.#ctor(Masuit.MyBlogs.Core.Infrastructure.Services.Interface.INoticeService,Microsoft.AspNetCore.Hosting.IHostingEnvironment,System.Net.Http.IHttpClientFactory)">
             <summary>
             <summary>
             网站公告
             网站公告
             </summary>
             </summary>
@@ -1290,7 +1307,7 @@
             文章管理
             文章管理
             </summary>
             </summary>
         </member>
         </member>
-        <member name="M:Masuit.MyBlogs.Core.Controllers.PostController.#ctor(Masuit.MyBlogs.Core.Infrastructure.Services.Interface.IPostService,Masuit.MyBlogs.Core.Infrastructure.Services.Interface.ICategoryService,Masuit.MyBlogs.Core.Infrastructure.Services.Interface.IBroadcastService,Masuit.MyBlogs.Core.Infrastructure.Services.Interface.ISeminarService,Masuit.MyBlogs.Core.Infrastructure.Services.Interface.IPostHistoryVersionService,Microsoft.AspNetCore.Hosting.IHostingEnvironment,Masuit.LuceneEFCore.SearchEngine.Interfaces.ISearchEngine{Masuit.MyBlogs.Core.Infrastructure.DataContext})">
+        <member name="M:Masuit.MyBlogs.Core.Controllers.PostController.#ctor(Masuit.MyBlogs.Core.Infrastructure.Services.Interface.IPostService,Masuit.MyBlogs.Core.Infrastructure.Services.Interface.ICategoryService,Masuit.MyBlogs.Core.Infrastructure.Services.Interface.IBroadcastService,Masuit.MyBlogs.Core.Infrastructure.Services.Interface.ISeminarService,Masuit.MyBlogs.Core.Infrastructure.Services.Interface.IPostHistoryVersionService,Microsoft.AspNetCore.Hosting.IHostingEnvironment,Masuit.LuceneEFCore.SearchEngine.Interfaces.ISearchEngine{Masuit.MyBlogs.Core.Infrastructure.DataContext},System.Net.Http.IHttpClientFactory)">
             <summary>
             <summary>
             文章管理
             文章管理
             </summary>
             </summary>
@@ -1934,19 +1951,6 @@
             <param name="ip"></param>
             <param name="ip"></param>
             <returns></returns>
             <returns></returns>
         </member>
         </member>
-        <member name="M:Masuit.MyBlogs.Core.Controllers.TestController.Test">
-            <summary>
-            迁移图床
-            </summary>
-            <returns></returns>
-        </member>
-        <member name="M:Masuit.MyBlogs.Core.Controllers.TestController.UploadGitlab(System.IO.Stream,System.String)">
-            <summary>
-            gitlab图床
-            </summary>
-            <param name="file"></param>
-            <returns></returns>
-        </member>
         <member name="T:Masuit.MyBlogs.Core.Controllers.ToolsController">
         <member name="T:Masuit.MyBlogs.Core.Controllers.ToolsController">
             <summary>
             <summary>
             黑科技
             黑科技
@@ -1979,7 +1983,7 @@
             文件上传
             文件上传
             </summary>
             </summary>
         </member>
         </member>
-        <member name="M:Masuit.MyBlogs.Core.Controllers.UploadController.#ctor(Microsoft.AspNetCore.Hosting.IHostingEnvironment)">
+        <member name="M:Masuit.MyBlogs.Core.Controllers.UploadController.#ctor(Microsoft.AspNetCore.Hosting.IHostingEnvironment,System.Net.Http.IHttpClientFactory)">
             <summary>
             <summary>
             文件上传
             文件上传
             </summary>
             </summary>

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

@@ -7,7 +7,7 @@
     Layout = "~/Views/Shared/_Layout.cshtml";
     Layout = "~/Views/Shared/_Layout.cshtml";
 }
 }
 <link href="~/Content/common/btnstyle.css" rel="stylesheet" />
 <link href="~/Content/common/btnstyle.css" rel="stylesheet" />
-<div class="container min-height780">
+<div class="container min-height610">
     <ol class="cd-breadcrumb triangle">
     <ol class="cd-breadcrumb triangle">
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li class="current"><em>@ViewBag.Title</em></li>
         <li class="current"><em>@ViewBag.Title</em></li>

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Links/Index_Admin.cshtml

@@ -7,7 +7,7 @@
     Layout = "~/Views/Shared/_Layout.cshtml";
     Layout = "~/Views/Shared/_Layout.cshtml";
 }
 }
 <link href="~/Content/common/btnstyle.css" rel="stylesheet" />
 <link href="~/Content/common/btnstyle.css" rel="stylesheet" />
-<div class="container min-height780">
+<div class="container min-height610">
     <ol class="cd-breadcrumb triangle">
     <ol class="cd-breadcrumb triangle">
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li class="current"><em>@ViewBag.Title</em></li>
         <li class="current"><em>@ViewBag.Title</em></li>

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

@@ -5,7 +5,7 @@
 }
 }
 <link href="~/Assets/layui/css/layui.min.css" rel="stylesheet" />
 <link href="~/Assets/layui/css/layui.min.css" rel="stylesheet" />
 <script src="~/Assets/layui/layui.all.js"></script>
 <script src="~/Assets/layui/layui.all.js"></script>
-<div class="container min-height780">
+<div class="container min-height610">
     <ol class="cd-breadcrumb triangle">
     <ol class="cd-breadcrumb triangle">
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li class="current">
         <li class="current">

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Msg/Index_Admin.cshtml

@@ -9,7 +9,7 @@
 }
 }
 <link href="~/Assets/layui/css/layui.min.css" rel="stylesheet" />
 <link href="~/Assets/layui/css/layui.min.css" rel="stylesheet" />
 <script src="~/Assets/layui/layui.all.js"></script>
 <script src="~/Assets/layui/layui.all.js"></script>
-<div class="container min-height780">
+<div class="container min-height610">
     <ol class="cd-breadcrumb triangle">
     <ol class="cd-breadcrumb triangle">
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li class="current"><em>@ViewBag.Title</em></li>
         <li class="current"><em>@ViewBag.Title</em></li>

+ 19 - 36
src/Masuit.MyBlogs.Core/Views/Notice/Index.cshtml

@@ -1,14 +1,10 @@
-@using System.Text.RegularExpressions
-@using Masuit.MyBlogs.Core.Common
-@using Masuit.MyBlogs.Core.Models.DTO
+@using Masuit.MyBlogs.Core.Models.DTO
 @model IList<Masuit.MyBlogs.Core.Models.DTO.NoticeOutputDto>
 @model IList<Masuit.MyBlogs.Core.Models.DTO.NoticeOutputDto>
 @{
 @{
     ViewBag.Title = "网站公告栏";
     ViewBag.Title = "网站公告栏";
     Layout = "~/Views/Shared/_Layout.cshtml";
     Layout = "~/Views/Shared/_Layout.cshtml";
 }
 }
-<link href="~/Assets/timeline.css" rel="stylesheet" />
-<link href="~/Assets/UEditor/third-party/SyntaxHighlighter/styles/shCore.min.css" rel="stylesheet" />
-<div class="container min-height780">
+<div class="container min-height610">
     <ol class="cd-breadcrumb triangle">
     <ol class="cd-breadcrumb triangle">
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li class="current"><em>@ViewBag.Title</em></li>
         <li class="current"><em>@ViewBag.Title</em></li>
@@ -16,40 +12,27 @@
     @{
     @{
         await Html.RenderPartialAsync("_Pagination");
         await Html.RenderPartialAsync("_Pagination");
     }
     }
-    <div class="row">
-        <div class="col-md-12">
-            <div class="main-timeline">
-                @foreach (NoticeOutputDto n in Model)
-                {
-                    <div class="timeline">
-                        <div class="timeline-content">
-                            <div class="circle">
-                                <span><i class="fa fa-globe"></i></span>
-                            </div>
-                            <div class="content">
-                                <span class="year">@n.PostDate.ToString("yyyy-MM-dd HH:mm:ss")</span>
-                                <h4 class="title">@n.Title</h4>
-                                <p class="description">
-                                    <a href="/n/@n.Id" class="tippy-scale" title="查看详情">@Html.Raw(Regex.Replace(n.Content, "\\s(title|alt)=['\"].+?['\"]", String.Empty).Replace("img src=", $"img title='{CommonHelper.SystemSettings["Title"]}' data-original="))</a>
-                                </p>
-                                <div class="icon">
-                                    <span></span>
-                                </div>
-                            </div>
-                        </div>
+    <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
+        @foreach (NoticeOutputDto n in Model)
+        {
+            <div class="panel panel-default">
+                <div class="panel-heading" role="tab" id="[email protected]">
+                    <h4 class="panel-title">
+                        <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#[email protected]" aria-expanded="false" aria-controls="[email protected]">
+                            @n.ModifyDate.ToString("yyyy-MM-dd") @n.Title
+                        </a>
+                    </h4>
+                </div>
+                <div id="[email protected]" class="panel-collapse collapse" role="tabpanel" aria-labelledby="[email protected]">
+                    <div class="panel-body">
+                        @Html.Raw(n.Content)
                     </div>
                     </div>
-                }
+                </div>
             </div>
             </div>
-        </div>
+        }
     </div>
     </div>
     @{
     @{
         await Html.RenderPartialAsync("_Pagination");
         await Html.RenderPartialAsync("_Pagination");
     }
     }
 
 
-</div>
-<script src="~/Assets/UEditor/third-party/SyntaxHighlighter/scripts/shCore.min.js"></script>
-<script src="~/Assets/UEditor/third-party/SyntaxHighlighter/scripts/bundle.min.js"></script>
-<script>
-    SyntaxHighlighter.all();
-    SyntaxHighlighter.defaults['toolbar'] = false;
-</script>
+</div>

+ 20 - 35
src/Masuit.MyBlogs.Core/Views/Notice/Index_Admin.cshtml

@@ -4,9 +4,7 @@
     ViewBag.Title = "网站公告栏";
     ViewBag.Title = "网站公告栏";
     Layout = "~/Views/Shared/_Layout.cshtml";
     Layout = "~/Views/Shared/_Layout.cshtml";
 }
 }
-<link href="~/Assets/timeline.css" rel="stylesheet" />
-<link href="~/Assets/UEditor/third-party/SyntaxHighlighter/styles/shCore.min.css" rel="stylesheet" />
-<div class="container min-height780">
+<div class="container min-height610">
     <ol class="cd-breadcrumb triangle">
     <ol class="cd-breadcrumb triangle">
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li class="current"><em>@ViewBag.Title</em></li>
         <li class="current"><em>@ViewBag.Title</em></li>
@@ -15,47 +13,34 @@
         await Html.RenderPartialAsync("_Pagination");
         await Html.RenderPartialAsync("_Pagination");
     }
     }
     <a href="/dashboard#/notice/index" class="btn btn-info">发布新公告</a>
     <a href="/dashboard#/notice/index" class="btn btn-info">发布新公告</a>
-    <div class="row">
-        <div class="col-md-12">
-            <div class="main-timeline">
-                @foreach (NoticeOutputDto n in Model)
-                {
-                    <div class="timeline">
-                        <div class="timeline-content">
-                            <div class="circle">
-                                <span><i class="fa fa-globe"></i></span>
-                            </div>
-                            <div class="content">
-                                <span class="year">@n.PostDate.ToString("yyyy-MM-dd HH:mm:ss")</span>
-                                <div class="title">
-                                    <span>@n.Title</span>
-                                    <div class="btn-group">
-                                        <button class="btn btn-danger" onclick="del(@n.Id,'@n.Title')">删除</button>
-                                        <a class="btn btn-info" href="/dashboard#/notice/[email protected]" target="_blank">修改</a>
-                                    </div>
-                                </div>
-                                <p class="description">
-                                    <a href="/n/@n.Id" class="tippy-scale" title="查看详情">@Html.Raw(n.Content)</a>
-                                </p>
-                                <div class="icon">
-                                    <span></span>
-                                </div>
-                            </div>
+    <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
+        @foreach (NoticeOutputDto n in Model)
+        {
+            <div class="panel panel-default">
+                <div class="panel-heading" role="tab" id="[email protected]">
+                    <h4 class="panel-title">
+                        <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#[email protected]" aria-expanded="false" aria-controls="[email protected]">
+                            @n.ModifyDate.ToString("yyyy-MM-dd") @n.Title
+                        </a>
+                    </h4>
+                </div>
+                <div id="[email protected]" class="panel-collapse collapse" role="tabpanel" aria-labelledby="[email protected]">
+                    <div class="panel-body">
+                        <div class="btn-group">
+                            <a class="btn btn-info" onclick="del(@n.Id,'@n.Title')">删除</a>
+                            <a class="btn btn-danger" href="/dashboard#/notice/[email protected]" target="_blank">修改</a>
                         </div>
                         </div>
+                        @Html.Raw(n.Content)
                     </div>
                     </div>
-                }
+                </div>
             </div>
             </div>
-        </div>
+        }
     </div>
     </div>
     @{
     @{
         await Html.RenderPartialAsync("_Pagination");
         await Html.RenderPartialAsync("_Pagination");
     }
     }
 </div>
 </div>
-<script src="~/Assets/UEditor/third-party/SyntaxHighlighter/scripts/shCore.min.js"></script>
-<script src="~/Assets/UEditor/third-party/SyntaxHighlighter/scripts/bundle.min.js"></script>
 <script>
 <script>
-    SyntaxHighlighter.all();
-    SyntaxHighlighter.defaults['toolbar'] = false;
     function del(id, title) {
     function del(id, title) {
         swal({
         swal({
             title: "确认删除这条公告吗?",
             title: "确认删除这条公告吗?",

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Search/Search.cshtml

@@ -9,7 +9,7 @@
     Layout = "~/Views/Shared/_Layout.cshtml";
     Layout = "~/Views/Shared/_Layout.cshtml";
     List<KeywordsRankOutputDto> hotSearches = ViewBag.hotSearches;
     List<KeywordsRankOutputDto> hotSearches = ViewBag.hotSearches;
 }
 }
-<div class="container min-height780">
+<div class="container min-height610">
     <ol class="cd-breadcrumb triangle">
     <ol class="cd-breadcrumb triangle">
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li class="current"><em>@ViewBag.Title</em></li>
         <li class="current"><em>@ViewBag.Title</em></li>

+ 1 - 1
src/Masuit.MyBlogs.Core/wwwroot/Content/common/app.css

@@ -37,7 +37,7 @@ body {
 
 
 /*#endregion */
 /*#endregion */
 
 
-.min-height780 {
+.min-height610 {
     min-height: 758px;
     min-height: 758px;
 }
 }
 .footer {
 .footer {

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
src/Masuit.MyBlogs.Core/wwwroot/Content/common/app.min.css


+ 2 - 2
src/Masuit.MyBlogs.Core/wwwroot/Content/common/style.css

@@ -37,8 +37,8 @@ body {
 
 
 /*#endregion */
 /*#endregion */
 
 
-.min-height780 {
-    min-height: 758px;
+.min-height610 {
+    min-height: 610px;
 }
 }
 .footer {
 .footer {
     margin-top: 10px;
     margin-top: 10px;

Деякі файли не було показано, через те що забагато файлів було змінено