2018-09-28 09:54:26 +08:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2017-06-13 11:34:06 +08:00
|
|
|
|
using System.IO;
|
2019-04-29 23:58:38 +08:00
|
|
|
|
using System.Linq;
|
2016-12-10 12:23:59 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Models
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2018-08-10 16:05:24 +08:00
|
|
|
|
public class ProfilesModel : ThemeModel
|
2016-12-10 12:23:59 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-02-27 16:48:19 +08:00
|
|
|
|
/// 获得 头像文件大小
|
2016-12-10 12:23:59 +08:00
|
|
|
|
/// </summary>
|
2017-06-13 11:34:06 +08:00
|
|
|
|
public long Size { get; }
|
2019-02-27 16:48:19 +08:00
|
|
|
|
|
2017-06-13 11:34:06 +08:00
|
|
|
|
/// <summary>
|
2019-02-27 16:48:19 +08:00
|
|
|
|
/// 获得 头像文件名称
|
2016-12-10 12:23:59 +08:00
|
|
|
|
/// </summary>
|
2018-09-28 15:08:01 +08:00
|
|
|
|
public string FileName { get; }
|
2019-02-27 16:48:19 +08:00
|
|
|
|
|
2018-09-28 15:08:01 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2019-03-09 20:04:04 +08:00
|
|
|
|
/// <param name="host"></param>
|
2018-06-07 00:45:47 +08:00
|
|
|
|
/// <param name="controller"></param>
|
2019-03-09 20:04:04 +08:00
|
|
|
|
public ProfilesModel(ControllerBase controller, IHostingEnvironment host) : base(controller)
|
2016-12-10 12:23:59 +08:00
|
|
|
|
{
|
2019-01-17 12:13:30 +08:00
|
|
|
|
if (host != null)
|
2016-12-10 12:23:59 +08:00
|
|
|
|
{
|
2019-03-09 20:04:04 +08:00
|
|
|
|
var fileName = Path.Combine(host.WebRootPath, Icon.TrimStart('~', '/').Replace('/', Path.DirectorySeparatorChar));
|
2019-04-29 23:58:38 +08:00
|
|
|
|
|
|
|
|
|
// 数据库存储的个人图片有后缀 default.jpg?v=1234567
|
|
|
|
|
fileName = fileName.Split('?').FirstOrDefault();
|
2019-01-17 12:13:30 +08:00
|
|
|
|
if (File.Exists(fileName))
|
|
|
|
|
{
|
|
|
|
|
Size = new FileInfo(fileName).Length;
|
|
|
|
|
FileName = Path.GetFileName(fileName);
|
|
|
|
|
}
|
2016-12-10 12:23:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|