/// <summary> /// /// </summary> /// <param name="fileSetting"></param> public FileModule(FileSetting fileSetting) { if (!string.IsNullOrEmpty(fileSetting.FileDirectory)) { fileDirectory = fileSetting.FileDirectory; } else { var basePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); fileDirectory = Path.Combine(basePath, "file"); } var dir = new DirectoryInfo(fileDirectory); if (!dir.Exists) { dir.Create(); } allowExts = new HashSet <string>(); foreach (var item in fileSetting.AllowExts) { if (item == "*") { all = true; } else { allowExts.Add(item.Trim().ToLower()); } } }
/// <summary> /// /// </summary> /// <param name="configuration"></param> /// <returns></returns> public static FileSetting LoadSettings(IConfiguration configuration) { var fileSetting = new FileSetting(); var fileDirectory = Environment.GetEnvironmentVariable("FILE_DIRECTORY"); if (string.IsNullOrEmpty(fileDirectory)) { fileDirectory = configuration["FileDirectory"]; } if (!string.IsNullOrEmpty(fileDirectory)) { fileSetting.FileDirectory = fileDirectory; } var allowExts = Environment.GetEnvironmentVariable("ALLOW_EXTS"); if (string.IsNullOrEmpty(allowExts)) { allowExts = configuration["AllowExts"]; } if (!string.IsNullOrEmpty(allowExts)) { fileSetting.AllowExts = allowExts.Split(',', StringSplitOptions.RemoveEmptyEntries); } else { fileSetting.AllowExts = new string[0]; } return(fileSetting); }
/// <summary> /// /// </summary> /// <param name="configuration"></param> /// <returns></returns> public static Settings LoadSettings(IConfiguration configuration) { var settings = new Settings(); var size = Environment.GetEnvironmentVariable("MAX_UPLOAD_SIZE"); if (string.IsNullOrEmpty(size)) { size = configuration["MaxUploadSize"]; } if (!string.IsNullOrEmpty(size)) { if (Utils.TryParseByteNumber(size, out long value)) { settings.MaxUploadSize = value; } else { throw new ConfigurationException("MaxUploadSize Variable Error"); } } try { var useLog = Environment.GetEnvironmentVariable("USE_LOG"); if (!string.IsNullOrEmpty(useLog)) { settings.UseLog = bool.Parse(useLog); } else { settings.UseLog = configuration.GetValue <bool>("UseLog"); } } catch (Exception ex) { throw new ConfigurationException("UseLog Variable Error", ex); } try { var useSwagger = Environment.GetEnvironmentVariable("USE_SWAGGER"); if (!string.IsNullOrEmpty(useSwagger)) { settings.UseSwagger = bool.Parse(useSwagger); } else { settings.UseSwagger = configuration.GetValue <bool>("UseSwagger"); } } catch (Exception ex) { throw new ConfigurationException("UseSwagger Variable Error", ex); } settings.AuthSetting = AuthSetting.LoadSettings(configuration); settings.FileSetting = FileSetting.LoadSettings(configuration); settings.ThumbnailSetting = ThumbnailSetting.LoadSettings(configuration); settings.MimeSetting = MimeSetting.LoadSettings(configuration); settings.CacheSetting = CacheSetting.LoadSettings(configuration); return(settings); }