lihao il y a 4 ans
Parent
commit
a82b0637f6

+ 1 - 0
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebNoteController.cs

@@ -53,6 +53,7 @@ namespace GxPress.Api.WebControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("search")]
+        [AllowAnonymous]
         public async Task<PagedList<NotePageListRequest>> NotePageList(NoteSearchPageListRequest request)
         {
             request.UserId = _loginContext.AccountId;

+ 59 - 0
gx_api/GxPress/Infrastructure/GxPress.Common/Tools/ImFileHelper.cs

@@ -0,0 +1,59 @@
+using System;
+using System.Drawing;
+using System.IO;
+
+namespace GxPress.Common.Tools
+{
+    public static class ImFileHelper
+    {
+        /// <summary>
+        ///     得到图片的 Size 值
+        /// </summary>
+        /// <param name="bytes">图片的二进制数据</param>
+        /// <returns>图片的 Size 值</returns>
+        public static Size GetSize(byte[] bytes)
+        {
+            var size = Size.Empty;
+            if (bytes != null && bytes.Length > 0)
+            {
+                using var ms = new MemoryStream(bytes);
+                size = GetSize(ms);
+            }
+
+            return size;
+        }
+
+        /// <summary>
+        ///     得到图片的 Size 值
+        /// </summary>
+        /// <param name="stream">图片的文件数据流</param>
+        /// <returns>图片的 Size 值</returns>
+        public static Size GetSize(Stream stream)
+        {
+            Size size;
+            using (var originalImage = Image.FromStream(stream))
+            {
+                size = originalImage.Size;
+            }
+            return size;
+        }
+
+        /// <summary>
+        ///     保存文件
+        /// </summary>
+        /// <param name="path">文件保存路径</param>
+        /// <param name="bytes">文件二进制数据</param>
+        /// <returns>保存文件是否成功!</returns>
+        public static void Save(string path, byte[] bytes)
+        {
+            if (string.IsNullOrWhiteSpace(path))
+                throw new ArgumentException("文件保存路径不能为空");
+            if (bytes == null || bytes.Length == 0)
+                throw new ArgumentException("文件二进制数据不能为空");
+            var info = new FileInfo(path);
+            if (info.Directory != null && !info.Directory.Exists) info.Directory.Create();
+            info.Delete();
+            File.WriteAllBytes(info.FullName, bytes);
+        }
+    }
+}

+ 8 - 2
gx_api/GxPress/Service/GxPress.Service.Implement/Note/NoteService.cs

@@ -244,13 +244,19 @@ namespace GxPress.Service.Implement.Note
         /// <returns></returns>
         public async Task<PagedList<NotePageListRequest>> NotePageListAsync(NoteSearchPageListRequest request)
         {
+            var middle = new Entity.Middle.Middle();
+            if (request.FolderId > 0 && middle != null)
+            {
+                middle = await _middleRepository.GetMiddleAsync(request.FolderId);
+                if (request.UserId <= 0)
+                    request.UserId = middle.UserId;
+            }
             var result = await _noteRepository.NotePageListAsync(request);
             result.DraftCount = await _noteRepository.GetDraftCountAsync(request.UserId, request.TypeValue == 1);
             result.IsDraft = result.DraftCount > 0;
             result.DraftId = await _noteRepository.GetNoteIdByDraftAsync(request.UserId, request.TypeValue == 1);
-            if (request.FolderId > 0)
+            if (request.FolderId > 0 && middle != null)
             {
-                var middle = await _middleRepository.GetMiddleAsync(request.FolderId);
                 result.RoleId = middle != null ? middle.RoleId : 0;
                 result.ParentId = middle != null ? middle.ParentId : 0;
             }