소스 검색

testcommit

admin 1 년 전
부모
커밋
5fdfe74f37

+ 0 - 60
FileHandlers/FwFileProvider.cs

@@ -1,60 +0,0 @@
-using FileStorage;
-using Microsoft.Extensions.Options;
-
-
-namespace FileHandlers
-{
-     public class FwFileProvider:IFwFileProvider
-    {
-        private readonly IFileMetadataRepository _fileMetadataRepository;
-        private readonly IOptionsSnapshot<FileUploadOptions> _fileUploadOptions;
-
-        public FwFileProvider(IFileMetadataRepository fileMetadataRepository,IOptionsSnapshot<FileUploadOptions> fileUploadOptions)
-        {
-            _fileMetadataRepository = fileMetadataRepository;
-            _fileUploadOptions = fileUploadOptions;
-        }
-
-        private IFwFileHandler  CreateFileHandler()
-        {
-            switch (_fileUploadOptions.Value.SaveFileMode)
-            {
-                case "Local":
-                    return new FwLocalFileHandler(_fileUploadOptions);
-                default:
-                    return new FwLocalFileHandler(_fileUploadOptions);
-            }
-        }
-
-        public IFileStorage Upload(string fileName, long length, string extraInfo, Stream fileData)
-        {
-            var fh = CreateFileHandler();
-            if(fileName==null)
-            {
-                fileName = "unkown";
-            }
-            fileName = fileName.Replace("<", "").Replace(">", "").Replace(" ", "");
-
-            var rv = fh.Upload(fileName, length, extraInfo,fileData);
-            if(string.IsNullOrEmpty(rv))
-            {
-                FileMetadata fileModel = new FileMetadata();
-                fileModel.FileName = fileName;
-                var ext = string.Empty;
-                if (string.IsNullOrEmpty(fileName) == false)
-                {
-                    var dotPos = fileName.LastIndexOf('.');
-                    ext = fileName[(dotPos + 1)..];
-                }
-                fileModel.FileExt = ext;
-                fileModel.Path = rv;
-                fileModel.Length = length;
-                fileModel.SaveMode = _fileUploadOptions.Value.SaveFileMode;
-                fileModel.ExtraInfo = extraInfo;
-                _fileMetadataRepository.AddAsync(fileModel);
-                return fileModel;
-            }
-            return null;
-        }
-    }
-}

+ 4 - 59
FileHandlers/FwLocalFileHandler.cs

@@ -1,74 +1,19 @@
-using FileStorage;
-using Microsoft.AspNetCore.Hosting;
+
+using FileStorage;
 using Microsoft.Extensions.Options;
 using System.ComponentModel.DataAnnotations;
-using static System.Runtime.InteropServices.JavaScript.JSType;
 
 namespace FileHandlers
 {
     [Display(Name = "local")]
     public class FwLocalFileHandler:FwFileHandlerBase
     {
-        private readonly IOptionsSnapshot<FileUploadOptions> _fileUploadOptions;
+        private readonly IOptionsSnapshot<StorageConfiguration> _fileUploadOptions;
 
-        public FwLocalFileHandler(IOptionsSnapshot<FileUploadOptions> fileUploadOptions)
+        public FwLocalFileHandler(IOptionsSnapshot<StorageConfiguration> fileUploadOptions)
         {
             _fileUploadOptions = fileUploadOptions;
         }
 
-
-        public override string Upload(string fileName, long length, string extraInfo,Stream fileData)
-        {
-
-            var settings = _fileUploadOptions.Value.Settings.Where(x=> x.Key.ToLower()=="local").Select(x=>x.Value).FirstOrDefault();
-            string groupDir = "";
-            if(settings!=null)
-            {
-                groupDir = settings.FirstOrDefault().GroupLocation;
-            }
-            if (string.IsNullOrEmpty(groupDir))
-            {
-                groupDir = "./uploads";
-            }
-            string pathHeader = groupDir;
-
-            string fulldir = GetFullPath(pathHeader);
-            if(!Directory.Exists(fulldir))
-            {
-                Directory.CreateDirectory(fulldir);
-            }
-
-            var ext = string.Empty;
-            if(!string.IsNullOrEmpty(fileName))
-            {
-                var dotPos = fileName.LastIndexOf('.');
-                ext = fileName.Substring(dotPos + 1);
-            }
-            var filename = $"{Guid.NewGuid().ToString().Replace("-",string.Empty)}.{ext}";
-            var fullPath = Path.Combine(fulldir, filename);
-            using (var fileStream = File.Create(fullPath))
-            {
-                fileData.CopyTo(fileStream);
-            }
-            fileData.Dispose();
-
-            return (Path.Combine(pathHeader, filename));
-        }
-
-
-        private string GetFullPath(string path)
-        {
-            string rv = "";
-            if (path.StartsWith("."))
-            {
-                rv = Path.Combine(Directory.GetCurrentDirectory(), path);
-            }
-            else
-            {
-                rv = path;
-            }
-            rv = Path.GetFullPath(rv);
-            return rv;
-        }
     }
 }

+ 0 - 10
FileHandlers/IFwFileProvider.cs

@@ -1,10 +0,0 @@
-using FileStorage;
-
-
-namespace FileHandlers
-{
-    public interface IFwFileProvider
-    {
-        IFileStorage Upload(string fileName, long length, string extraInfo, Stream fileData);
-    }
-}

+ 5 - 24
src/FileStorage.Host/Controllers/WeatherForecastController.cs

@@ -9,40 +9,21 @@ namespace FileStorage.Host.Controllers
     [Route("weather")]
     public class WeatherForecastController : ControllerBase
     {
-
-        private static readonly string[] Summaries = new[]
-        {
-        "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
-         };
-
         private readonly ILogger<WeatherForecastController> _logger;
-        private readonly IFwFileProvider _fwFileProvider;
+        private readonly IFileStorage _fileStorage;
 
-        public WeatherForecastController(ILogger<WeatherForecastController> logger, IFwFileProvider fwFileProvider)
+        public WeatherForecastController(ILogger<WeatherForecastController> logger,IFileStorage fileStorage)
         {
             _logger = logger;
-            _fwFileProvider = fwFileProvider;
-        }
-
-        [HttpGet(Name = "GetWeatherForecast")]
-        public IEnumerable<WeatherForecast> Get()
-        {
-            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
-            {
-                Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
-                TemperatureC = Random.Shared.Next(-20, 55),
-                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
-            })
-            .ToArray();
+            _fileStorage = fileStorage;
         }
 
         [HttpPost("upload")]
         public IActionResult Upload()
         {
             var fileData = Request.Form.Files[0];
-            var file = _fwFileProvider.Upload(fileData.FileName, fileData.Length, "",fileData.OpenReadStream());
-            return Ok(new { Id = file.GetID(), fileName = file.FileName });
-            
+            var file = _fileStorage.Upload(fileData.FileName, fileData.Length, "", fileData.OpenReadStream());
+            return Ok(new { Id = file.Id, fileName = file.FileName });
         }
     }
 }

+ 5 - 4
src/FileStorage.Host/StartupExtensions.cs

@@ -27,13 +27,14 @@ internal static class StartupExtensions
 #endif
 
         services.Configure<StorageConfiguration>(d => configuration.GetSection(nameof(StorageConfiguration)).Bind(d));
-        services.Configure<FileUploadOptions>(d => configuration.GetSection("FileUploadOptions").Bind(d));
-
-        services.AddScoped<IFwFileProvider,FwFileProvider>();
-
+        services.Configure<StorageConfiguration>(d => configuration.GetSection("StorageConfiguration").Bind(d));
         // Add services to the container.
         services.BatchInjectServices();
 
+
+        services.AddScoped<IFileStorage, DefaultFileStorage>();
+
+
         //var storageConfig = configuration.GetSection(nameof(StorageConfiguration)).Get<StorageConfiguration>();
         //if(storageConfig == null || string.IsNullOrEmpty(storageConfig.Impt) || storageConfig.Impt == FileStorageConsts.LocalImpt)
         //{

+ 2 - 2
src/FileStorage.Host/config/appsettings.Development.json

@@ -14,9 +14,9 @@
     "ApplySeed": false
   },
   "StorageConfiguration": {
-    "Impt": "",
+    "Impt": "Local",
     "Local": {
-      "Path": ""
+      "Path": "/Uploads"
     },
     "Aliyun": {
 

+ 12 - 0
src/FileStorage.Host/config/appsettings.json

@@ -12,5 +12,17 @@
   "DatabaseConfiguration": {
     "ApplyDbMigrations": false,
     "ApplySeed": false
+  },
+  "StorageConfiguration": {
+    "Impt": "Local",
+    "Local": {
+      "Path": "/Uploads"
+    },
+    "Aliyun": {
+
+    },
+    "Ctyun": {
+
+    }
   }
 }

+ 13 - 1
src/FileStorage.Host/config/appsettings.shared.json

@@ -25,7 +25,7 @@
           "outputTemplate": "[{Timestamp:HH:mm:ss} {Level}] {SourceContext} [{TraceId}]{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}",
           "theme": "Serilog.Sinks.SystemConsole.Themes.ConsoleTheme::None, Serilog.Sinks.Console"
         }
-      },
+      }
       //{
       //  "Name": "GrafanaLoki",
       //  "Args": {
@@ -70,5 +70,17 @@
       //}
     ],
     "Enrich": [ "FromLogContext", "WithSpan" ]
+  },
+  "StorageConfiguration": {
+    "Impt": "Local",
+    "Local": {
+      "Path": "/uploads"
+    },
+    "Aliyun": {
+
+    },
+    "Ctyun": {
+
+    }
   }
 }

+ 11 - 0
src/FileStorage.Host/uploads/0121b8b6631a4813af2f8a5f6e1c3096.txt

@@ -0,0 +1,11 @@
+V.20230227-1
+1.修复了通话记录同步错误的问题;(需观察测试)
+2.暂时关闭了通知前段排队数量的通道(修复后再开放);
+3.修复了小休时,来电提示设置了免打扰的问题(小休时分机不再分配来电);
+4.重新实现结束休息的方式(结束休息,分机会重新分配来电);
+5.修复了来电分配话机异常的问题(将按分机组预设的分配方式分配);
+6.修复了签入异常时会更改分机组来电分配方式的问题;
+7.修复了签出时可能分机没有移出当前分机组(仍然可以分配到来电);
+8.签出新增验证如果分机正在休息状态不能签出;
+V.20230227-2
+1.修复了签入签出可能影响其他分机休息状态的问题;

+ 11 - 0
src/FileStorage.Host/uploads/1ac44c83a9514a23bf036a69c530578a.txt

@@ -0,0 +1,11 @@
+V.20230227-1
+1.修复了通话记录同步错误的问题;(需观察测试)
+2.暂时关闭了通知前段排队数量的通道(修复后再开放);
+3.修复了小休时,来电提示设置了免打扰的问题(小休时分机不再分配来电);
+4.重新实现结束休息的方式(结束休息,分机会重新分配来电);
+5.修复了来电分配话机异常的问题(将按分机组预设的分配方式分配);
+6.修复了签入异常时会更改分机组来电分配方式的问题;
+7.修复了签出时可能分机没有移出当前分机组(仍然可以分配到来电);
+8.签出新增验证如果分机正在休息状态不能签出;
+V.20230227-2
+1.修复了签入签出可能影响其他分机休息状态的问题;

+ 11 - 0
src/FileStorage.Host/uploads/3197a8affcd34b54986328008319ad54.txt

@@ -0,0 +1,11 @@
+V.20230227-1
+1.修复了通话记录同步错误的问题;(需观察测试)
+2.暂时关闭了通知前段排队数量的通道(修复后再开放);
+3.修复了小休时,来电提示设置了免打扰的问题(小休时分机不再分配来电);
+4.重新实现结束休息的方式(结束休息,分机会重新分配来电);
+5.修复了来电分配话机异常的问题(将按分机组预设的分配方式分配);
+6.修复了签入异常时会更改分机组来电分配方式的问题;
+7.修复了签出时可能分机没有移出当前分机组(仍然可以分配到来电);
+8.签出新增验证如果分机正在休息状态不能签出;
+V.20230227-2
+1.修复了签入签出可能影响其他分机休息状态的问题;

+ 11 - 0
src/FileStorage.Host/uploads/5adc18668bb34fadbc5352510e32f7ad.txt

@@ -0,0 +1,11 @@
+V.20230227-1
+1.修复了通话记录同步错误的问题;(需观察测试)
+2.暂时关闭了通知前段排队数量的通道(修复后再开放);
+3.修复了小休时,来电提示设置了免打扰的问题(小休时分机不再分配来电);
+4.重新实现结束休息的方式(结束休息,分机会重新分配来电);
+5.修复了来电分配话机异常的问题(将按分机组预设的分配方式分配);
+6.修复了签入异常时会更改分机组来电分配方式的问题;
+7.修复了签出时可能分机没有移出当前分机组(仍然可以分配到来电);
+8.签出新增验证如果分机正在休息状态不能签出;
+V.20230227-2
+1.修复了签入签出可能影响其他分机休息状态的问题;

+ 11 - 0
src/FileStorage.Host/uploads/af0e08b475bc422fbd3a4b895a7c8ebd.txt

@@ -0,0 +1,11 @@
+V.20230227-1
+1.修复了通话记录同步错误的问题;(需观察测试)
+2.暂时关闭了通知前段排队数量的通道(修复后再开放);
+3.修复了小休时,来电提示设置了免打扰的问题(小休时分机不再分配来电);
+4.重新实现结束休息的方式(结束休息,分机会重新分配来电);
+5.修复了来电分配话机异常的问题(将按分机组预设的分配方式分配);
+6.修复了签入异常时会更改分机组来电分配方式的问题;
+7.修复了签出时可能分机没有移出当前分机组(仍然可以分配到来电);
+8.签出新增验证如果分机正在休息状态不能签出;
+V.20230227-2
+1.修复了签入签出可能影响其他分机休息状态的问题;

+ 11 - 0
src/FileStorage.Host/uploads/f13e568f412b43e5953c03bb531ca08b.txt

@@ -0,0 +1,11 @@
+V.20230227-1
+1.修复了通话记录同步错误的问题;(需观察测试)
+2.暂时关闭了通知前段排队数量的通道(修复后再开放);
+3.修复了小休时,来电提示设置了免打扰的问题(小休时分机不再分配来电);
+4.重新实现结束休息的方式(结束休息,分机会重新分配来电);
+5.修复了来电分配话机异常的问题(将按分机组预设的分配方式分配);
+6.修复了签入异常时会更改分机组来电分配方式的问题;
+7.修复了签出时可能分机没有移出当前分机组(仍然可以分配到来电);
+8.签出新增验证如果分机正在休息状态不能签出;
+V.20230227-2
+1.修复了签入签出可能影响其他分机休息状态的问题;

+ 93 - 12
src/FileStorage/DefaultFileStorage.cs

@@ -1,20 +1,101 @@
-using XF.Domain.Dependency;
+using Microsoft.Extensions.Options;
+using XF.Domain.Dependency;
 
 namespace FileStorage;
 
 public class DefaultFileStorage : IFileStorage, IScopeDependency
 {
-    public string Path { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
-    public string FileName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
-    public string FileExt { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
-    public long Length { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
-    public string SaveMode { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
-    public string ExtraInfo { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
-    public Stream DataStream { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
-    public DateTime UploadTime { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
-
-    public string GetID()
+
+    private readonly IFileMetadataRepository _fileMetadataRepository;
+    private readonly IOptionsSnapshot<StorageConfiguration> _fileUploadOptions;
+
+    public DefaultFileStorage(IFileMetadataRepository fileMetadataRepository,IOptionsSnapshot<StorageConfiguration> optionsSnapshot)
+    {
+        _fileMetadataRepository = fileMetadataRepository;
+        _fileUploadOptions = optionsSnapshot;
+    }
+
+
+    public FileMetadata Upload(string fileName, long length, string extraInfo, Stream fileData)
+    {
+        if (fileName == null)
+        {
+            fileName = "unkown";
+        }
+        fileName = fileName.Replace("<", "").Replace(">", "").Replace(" ", "");
+
+        var rv = UploadLoca(fileName, length, extraInfo, fileData);
+        if (string.IsNullOrEmpty(rv))
+        {
+            FileMetadata fileModel = new FileMetadata();
+            fileModel.FileName = fileName;
+            var ext = string.Empty;
+            if (string.IsNullOrEmpty(fileName) == false)
+            {
+                var dotPos = fileName.LastIndexOf('.');
+                ext = fileName[(dotPos + 1)..];
+            }
+            fileModel.FileExt = ext;
+            fileModel.Path = rv;
+            fileModel.Length = length;
+            fileModel.SaveMode = _fileUploadOptions.Value.Impt;
+            fileModel.ExtraInfo = extraInfo;
+            _fileMetadataRepository.AddAsync(fileModel);
+            return fileModel;
+        }
+        return null;
+    }
+
+
+    private string UploadLoca(string fileName, long length, string extraInfo, Stream fileData)
+    {
+        var settings = _fileUploadOptions.Value.Local;
+        string groupDir = "";
+        if (settings != null)
+        {
+            groupDir = settings.Path;
+        }
+        if (string.IsNullOrEmpty(groupDir))
+        {
+            groupDir = "./uploads";
+        }
+        string pathHeader = groupDir;
+
+        string fulldir = GetFullPath(pathHeader);
+        if (!Directory.Exists(fulldir))
+        {
+            Directory.CreateDirectory(fulldir);
+        }
+
+        var ext = string.Empty;
+        if (!string.IsNullOrEmpty(fileName))
+        {
+            var dotPos = fileName.LastIndexOf('.');
+            ext = fileName.Substring(dotPos + 1);
+        }
+        var filename = $"{Guid.NewGuid().ToString().Replace("-", string.Empty)}.{ext}";
+        var fullPath = Path.Combine(fulldir, filename);
+        using (var fileStream = File.Create(fullPath))
+        {
+            fileData.CopyTo(fileStream);
+        }
+        fileData.Dispose();
+
+        return (Path.Combine(pathHeader, filename));
+    }
+
+    private string GetFullPath(string path)
     {
-        throw new NotImplementedException();
+        string rv = "";
+        if (path.StartsWith("."))
+        {
+            rv = Path.Combine(Directory.GetCurrentDirectory(), path);
+        }
+        else
+        {
+            rv = path;
+        }
+        rv = Path.GetFullPath(rv);
+        return rv;
     }
 }

+ 3 - 7
src/FileStorage/FileMetadata.cs

@@ -1,4 +1,5 @@
 using Newtonsoft.Json;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations.Schema;
@@ -13,7 +14,7 @@ namespace FileStorage
     /// <summary>
     /// 文件数据
     /// </summary>
-    public class FileMetadata : CreationEntity, IFileStorage,IDisposable
+    public class FileMetadata : CreationEntity,IDisposable
     {
         /// <summary>
         /// 所属客户端
@@ -53,8 +54,7 @@ namespace FileStorage
         /// <summary>
         /// 文件流
         /// </summary>
-        [NotMapped]
-        [JsonIgnore]
+        [SugarColumn( IsIgnore = true)]
         public Stream DataStream { get; set; }
 
         /// <summary>
@@ -71,9 +71,5 @@ namespace FileStorage
                 DataStream.Dispose();
         }
 
-        string IFileStorage.GetID()
-        {
-            return base.Id.ToString();
-        }
     }
 }

+ 0 - 31
src/FileStorage/FileUploadOptions.cs

@@ -1,31 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace FileStorage
-{
-    public class FileUploadOptions
-    {
-        /// <summary>
-        /// 存储方式
-        /// </summary>
-        public string SaveFileMode { get; set; }
-
-        public Dictionary<string, List<FileHandlerOptions>> Settings { get; set; }
-    }
-
-    public class FileHandlerOptions
-    {
-        public string GroupName { get; set; }
-
-        public string GroupLocation { get; set; }
-
-        public string ServerUrl { get; set; }
-
-        public string Key { get; set; }
-
-        public string Secret { get; set; }
-    }
-}

+ 1 - 17
src/FileStorage/IFileStorage.cs

@@ -2,24 +2,8 @@
 {
     public interface IFileStorage
     {
-        string Path { get; set; }
-
-        string FileName { get; set; }
-
-        string FileExt { get; set; }
-
-        long Length { get; set; }
-
-        string SaveMode { get; set; }
-
-        string ExtraInfo { get; set; }
-
-        Stream DataStream { get; set; }
-
-        DateTime UploadTime { get; set; }
-
-        string GetID();
 
+        FileMetadata Upload(string fileName, long length, string extraInfo, Stream fileData);
 
         //string Upload(//...);
     }

+ 39 - 0
src/FileStorage/StorageConfiguration.cs

@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FileStorage
+{
+    public class StorageConfiguration
+    {
+        /// <summary>
+        /// 存储方式
+        /// </summary>
+        public string Impt { get; set; }
+
+        public Local Local { get; set; }
+
+        public Aliyun Aliyun { get; set; }
+
+        public Ctyun Ctyun { get; set; }
+    }
+
+    public class Local
+    {
+        public string Path { get; set; }
+    }
+
+    public class Aliyun
+    {
+
+    }
+
+    public class Ctyun
+    {
+
+    }
+
+
+}