using System.IO;
using System.Linq;
using Abp.UI;

namespace YGNT.File.Core.Domain.FileFilter
{
    public class ImageFileFilter : IFileFilter
    {
        public const string Filters = ".bmp;.dib;.jpg;.jpeg;.jpe;.jfif;.png;.gif;.tif;.tiff";

        /// <summary>
        /// 验证文件类型
        /// </summary>
        /// <param name="fileFullName">文件全名带后缀</param>
        public void Filter(string fileFullName)
        {
            var extension = Path.GetExtension(fileFullName);
            var pass = Filters.Split(';', System.StringSplitOptions.RemoveEmptyEntries)
                .Any(x => x.ToUpperInvariant() == extension.ToUpperInvariant());
            if (!pass)
                throw new UserFriendlyException($"只支持上传{Filters}格式的图片");
        }
    }
}