Prechádzať zdrojové kódy

1,文件上传校验真实文件类型
2,修改在线人数显示文字颜色

syxdevcode 3 rokov pred
rodič
commit
5463ac4efa

+ 1 - 0
Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj

@@ -30,6 +30,7 @@
     <PackageReference Include="Furion.Pure" Version="4.3.3" />
     <PackageReference Include="Magicodes.IE.Excel" Version="2.6.4" />
     <PackageReference Include="Magicodes.IE.Pdf" Version="2.6.4" />
+    <PackageReference Include="Masuit.Tools.Core" Version="2.5.4" />
     <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.8" />
     <PackageReference Include="NETCore.MailKit" Version="2.1.0" />
     <PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.1.8" />

+ 16 - 1
Admin.NET/Admin.NET.Core/Service/File/SysFileService.cs

@@ -1,3 +1,4 @@
+using Masuit.Tools.Files.FileDetector;
 using OnceMi.AspNetCore.OSS;
 
 namespace Admin.NET.Core.Service;
@@ -209,8 +210,22 @@ public class SysFileService : IDynamicApiController, ITransient
             var filePath = Path.Combine(App.WebHostEnvironment.WebRootPath, path);
             if (!Directory.Exists(filePath))
                 Directory.CreateDirectory(filePath);
-            using var stream = File.Create(Path.Combine(filePath, finalName));
+
+            var realFile = Path.Combine(filePath, finalName);
+            await using var stream = File.Create(realFile);
             await file.CopyToAsync(stream);
+            var detector = stream.DetectFiletype();
+            var realExt = detector.Extension;//真实扩展名
+
+            // 二次校验扩展名
+            if (!string.Equals(realExt, suffix.Replace(".", ""), StringComparison.OrdinalIgnoreCase))
+            {
+                var delFilePath = Path.Combine(App.WebHostEnvironment.WebRootPath, realFile);
+                if (File.Exists(delFilePath))
+                    File.Delete(delFilePath);
+                throw Oops.Oh(ErrorCodeEnum.D8001);
+            }
+
             //生成外链
             newFile.Url = _commonService.GetFileUrl(newFile);
         }

+ 1 - 1
Vben2/src/extension/components/OnlineUser/OnlineUser.vue

@@ -1,6 +1,6 @@
 <template>
   <div>
-    <div @click="toggleDrawer">{{ onlineUserList.length }}人在线</div>
+    <div @click="toggleDrawer" style="color: green">{{ onlineUserList.length }}人在线</div>
 
     <Drawer title="在线人员" width="600px" v-model:visible="drawerShow">
       <List item-layout="horizontal" :data-source="onlineUserList">