aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Timeline.Tests/Helpers/HttpClientExtensions.cs9
-rw-r--r--Timeline.Tests/Helpers/ImageHelper.cs21
-rw-r--r--Timeline.Tests/Helpers/MyTestLoggerFactory.cs14
-rw-r--r--Timeline.Tests/Helpers/MyWebApplicationFactory.cs5
-rw-r--r--Timeline.Tests/IntegratedTests/UserAvatarTests.cs154
-rw-r--r--Timeline.Tests/Mock/Data/TestDatabase.cs46
-rw-r--r--Timeline.Tests/UserAvatarServiceTest.cs232
-rw-r--r--Timeline/Authenticate/PrincipalExtensions.cs13
-rw-r--r--Timeline/Controllers/UserAvatarController.cs135
-rw-r--r--Timeline/Entities/DatabaseContext.cs3
-rw-r--r--Timeline/Entities/UserAvatar.cs18
-rw-r--r--Timeline/Migrations/20190818174505_AddUserAvatar.Designer.cs83
-rw-r--r--Timeline/Migrations/20190818174505_AddUserAvatar.cs62
-rw-r--r--Timeline/Migrations/DatabaseContextModelSnapshot.cs31
-rw-r--r--Timeline/Services/UserAvatarService.cs250
-rw-r--r--Timeline/Startup.cs2
-rw-r--r--Timeline/Timeline.csproj7
-rw-r--r--Timeline/appsettings.Development.json2
-rw-r--r--Timeline/default-avatar.pngbin0 -> 26442 bytes
-rw-r--r--art-src/user.svg4
-rw-r--r--nuget.config7
21 files changed, 1088 insertions, 10 deletions
diff --git a/Timeline.Tests/Helpers/HttpClientExtensions.cs b/Timeline.Tests/Helpers/HttpClientExtensions.cs
index cd40d91e..b9204fcc 100644
--- a/Timeline.Tests/Helpers/HttpClientExtensions.cs
+++ b/Timeline.Tests/Helpers/HttpClientExtensions.cs
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using System.Net.Http;
+using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
@@ -11,5 +12,13 @@ namespace Timeline.Tests.Helpers
{
return client.PatchAsync(url, new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"));
}
+
+ public static Task<HttpResponseMessage> PutByteArrayAsync(this HttpClient client, string url, byte[] body, string mimeType)
+ {
+ var content = new ByteArrayContent(body);
+ content.Headers.ContentLength = body.Length;
+ content.Headers.ContentType = new MediaTypeHeaderValue(mimeType);
+ return client.PutAsync(url, content);
+ }
}
}
diff --git a/Timeline.Tests/Helpers/ImageHelper.cs b/Timeline.Tests/Helpers/ImageHelper.cs
new file mode 100644
index 00000000..c5a9cf17
--- /dev/null
+++ b/Timeline.Tests/Helpers/ImageHelper.cs
@@ -0,0 +1,21 @@
+using SixLabors.ImageSharp;
+using SixLabors.ImageSharp.PixelFormats;
+using System.IO;
+
+namespace Timeline.Tests.Helpers
+{
+ public static class ImageHelper
+ {
+ public static byte[] CreatePngWithSize(int width, int height)
+ {
+ using (var image = new Image<Rgba32>(width, height))
+ {
+ using (var stream = new MemoryStream())
+ {
+ image.SaveAsPng(stream);
+ return stream.ToArray();
+ }
+ }
+ }
+ }
+}
diff --git a/Timeline.Tests/Helpers/MyTestLoggerFactory.cs b/Timeline.Tests/Helpers/MyTestLoggerFactory.cs
new file mode 100644
index 00000000..40c6a77e
--- /dev/null
+++ b/Timeline.Tests/Helpers/MyTestLoggerFactory.cs
@@ -0,0 +1,14 @@
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging.Testing;
+using Xunit.Abstractions;
+
+namespace Timeline.Tests.Helpers
+{
+ public static class MyTestLoggerFactory
+ {
+ public static LoggerFactory Create(ITestOutputHelper outputHelper)
+ {
+ return new LoggerFactory(new[] { new XunitLoggerProvider(outputHelper) });
+ }
+ }
+}
diff --git a/Timeline.Tests/Helpers/MyWebApplicationFactory.cs b/Timeline.Tests/Helpers/MyWebApplicationFactory.cs
index dfadd1ae..e96d11fe 100644
--- a/Timeline.Tests/Helpers/MyWebApplicationFactory.cs
+++ b/Timeline.Tests/Helpers/MyWebApplicationFactory.cs
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
@@ -37,6 +38,10 @@ namespace Timeline.Tests.Helpers
{
var options = new DbContextOptionsBuilder<DatabaseContext>()
.UseSqlite(_databaseConnection)
+ .ConfigureWarnings(builder =>
+ {
+ builder.Throw(RelationalEventId.QueryClientEvaluationWarning);
+ })
.Options;
using (var context = new DatabaseContext(options))
diff --git a/Timeline.Tests/IntegratedTests/UserAvatarTests.cs b/Timeline.Tests/IntegratedTests/UserAvatarTests.cs
new file mode 100644
index 00000000..e282da1b
--- /dev/null
+++ b/Timeline.Tests/IntegratedTests/UserAvatarTests.cs
@@ -0,0 +1,154 @@
+using FluentAssertions;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Mvc.Testing;
+using Microsoft.Extensions.DependencyInjection;
+using SixLabors.ImageSharp.Formats.Png;
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using System.Threading.Tasks;
+using Timeline.Controllers;
+using Timeline.Services;
+using Timeline.Tests.Helpers;
+using Timeline.Tests.Helpers.Authentication;
+using Xunit;
+using Xunit.Abstractions;
+
+namespace Timeline.Tests.IntegratedTests
+{
+ public class UserAvatarUnitTest : IClassFixture<MyWebApplicationFactory<Startup>>, IDisposable
+ {
+ private readonly WebApplicationFactory<Startup> _factory;
+ private readonly Action _disposeAction;
+
+ public UserAvatarUnitTest(MyWebApplicationFactory<Startup> factory, ITestOutputHelper outputHelper)
+ {
+ _factory = factory.WithTestConfig(outputHelper, out _disposeAction);
+ }
+
+ public void Dispose()
+ {
+ _disposeAction();
+ }
+
+ [Fact]
+ public async Task Test()
+ {
+ Avatar mockAvatar = new Avatar
+ {
+ Data = ImageHelper.CreatePngWithSize(100, 100),
+ Type = PngFormat.Instance.DefaultMimeType
+ };
+
+ using (var client = await _factory.CreateClientAsUser())
+ {
+ {
+ var res = await client.GetAsync("users/usernotexist/avatar");
+ res.Should().HaveStatusCodeNotFound()
+ .And.Should().HaveBodyAsCommonResponseWithCode(UserAvatarController.ErrorCodes.Get_UserNotExist);
+ }
+
+ var env = _factory.Server.Host.Services.GetRequiredService<IHostingEnvironment>();
+ var defaultAvatarData = await File.ReadAllBytesAsync(Path.Combine(env.ContentRootPath, "default-avatar.png"));
+
+ async Task GetReturnDefault(string username = "user")
+ {
+ var res = await client.GetAsync($"users/{username}/avatar");
+ res.Should().HaveStatusCodeOk();
+ res.Content.Headers.ContentType.MediaType.Should().Be("image/png");
+ var body = await res.Content.ReadAsByteArrayAsync();
+ body.Should().Equal(defaultAvatarData);
+ }
+
+ await GetReturnDefault();
+ await GetReturnDefault("admin");
+
+ {
+ var res = await client.PutByteArrayAsync("users/user/avatar", new[] { (byte)0x00 }, "image/notaccept");
+ res.Should().HaveStatusCode(HttpStatusCode.UnsupportedMediaType);
+ }
+
+ {
+ var res = await client.PutByteArrayAsync("users/user/avatar", new[] { (byte)0x00 }, "image/notaccept");
+ res.Should().HaveStatusCode(HttpStatusCode.UnsupportedMediaType);
+ }
+
+ {
+ var res = await client.PutByteArrayAsync("users/user/avatar", new[] { (byte)0x00 }, "image/png");
+ res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
+ .And.Should().HaveBodyAsCommonResponseWithCode(UserAvatarController.ErrorCodes.Put_BadFormat_CantDecode);
+ }
+
+ {
+ var res = await client.PutByteArrayAsync("users/user/avatar", mockAvatar.Data, "image/jpeg");
+ res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
+ .And.Should().HaveBodyAsCommonResponseWithCode(UserAvatarController.ErrorCodes.Put_BadFormat_UnmatchedFormat);
+ }
+
+ {
+ var res = await client.PutByteArrayAsync("users/user/avatar", ImageHelper.CreatePngWithSize(100, 200), "image/png");
+ res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
+ .And.Should().HaveBodyAsCommonResponseWithCode(UserAvatarController.ErrorCodes.Put_BadFormat_BadSize);
+ }
+
+ {
+ var res = await client.PutByteArrayAsync("users/user/avatar", mockAvatar.Data, mockAvatar.Type);
+ res.Should().HaveStatusCode(HttpStatusCode.OK);
+
+ var res2 = await client.GetAsync("users/user/avatar");
+ res2.Should().HaveStatusCodeOk();
+ res2.Content.Headers.ContentType.MediaType.Should().Be(mockAvatar.Type);
+ var body = await res2.Content.ReadAsByteArrayAsync();
+ body.Should().Equal(mockAvatar.Data);
+ }
+
+ {
+ var res = await client.PutByteArrayAsync("users/admin/avatar", new[] { (byte)0x00 }, "image/png");
+ res.Should().HaveStatusCode(HttpStatusCode.Forbidden)
+ .And.Should().HaveBodyAsCommonResponseWithCode(UserAvatarController.ErrorCodes.Put_Forbid);
+ }
+
+ {
+ var res = await client.DeleteAsync("users/admin/avatar");
+ res.Should().HaveStatusCode(HttpStatusCode.Forbidden)
+ .And.Should().HaveBodyAsCommonResponseWithCode(UserAvatarController.ErrorCodes.Delete_Forbid);
+ }
+
+ for (int i = 0; i < 2; i++) // double delete should work.
+ {
+ var res = await client.DeleteAsync("users/user/avatar");
+ res.Should().HaveStatusCodeOk();
+ await GetReturnDefault();
+ }
+ }
+
+ // Authorization check.
+ using (var client = await _factory.CreateClientAsAdmin())
+ {
+ {
+ var res = await client.PutByteArrayAsync("users/user/avatar", mockAvatar.Data, mockAvatar.Type);
+ res.Should().HaveStatusCode(HttpStatusCode.OK);
+ }
+
+ {
+ var res = await client.DeleteAsync("users/user/avatar");
+ res.Should().HaveStatusCode(HttpStatusCode.OK);
+ }
+
+ {
+ var res = await client.PutByteArrayAsync("users/usernotexist/avatar", new[] { (byte)0x00 }, "image/png");
+ res.Should().HaveStatusCodeBadRequest()
+ .And.Should().HaveBodyAsCommonResponseWithCode(UserAvatarController.ErrorCodes.Put_UserNotExist);
+ }
+
+ {
+ var res = await client.DeleteAsync("users/usernotexist/avatar");
+ res.Should().HaveStatusCodeBadRequest()
+ .And.Should().HaveBodyAsCommonResponseWithCode(UserAvatarController.ErrorCodes.Delete_UserNotExist);
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Timeline.Tests/Mock/Data/TestDatabase.cs b/Timeline.Tests/Mock/Data/TestDatabase.cs
new file mode 100644
index 00000000..09c77dce
--- /dev/null
+++ b/Timeline.Tests/Mock/Data/TestDatabase.cs
@@ -0,0 +1,46 @@
+using Microsoft.Data.Sqlite;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Diagnostics;
+using System;
+using Timeline.Entities;
+
+namespace Timeline.Tests.Mock.Data
+{
+ public class TestDatabase : IDisposable
+ {
+ private readonly SqliteConnection _databaseConnection;
+ private readonly DatabaseContext _databaseContext;
+
+ public TestDatabase()
+ {
+ _databaseConnection = new SqliteConnection("Data Source=:memory:;");
+ _databaseConnection.Open();
+
+ var options = new DbContextOptionsBuilder<DatabaseContext>()
+ .UseSqlite(_databaseConnection)
+ .ConfigureWarnings(builder =>
+ {
+ builder.Throw(RelationalEventId.QueryClientEvaluationWarning);
+ })
+ .Options;
+
+ _databaseContext = new DatabaseContext(options);
+
+ // init with mock data
+ _databaseContext.Database.EnsureCreated();
+ _databaseContext.Users.AddRange(MockUsers.Users);
+ _databaseContext.SaveChanges();
+ }
+
+ public void Dispose()
+ {
+ _databaseContext.Dispose();
+
+ _databaseConnection.Close();
+ _databaseConnection.Dispose();
+ }
+
+ public SqliteConnection DatabaseConnection => _databaseConnection;
+ public DatabaseContext DatabaseContext => _databaseContext;
+ }
+}
diff --git a/Timeline.Tests/UserAvatarServiceTest.cs b/Timeline.Tests/UserAvatarServiceTest.cs
new file mode 100644
index 00000000..69d6b61c
--- /dev/null
+++ b/Timeline.Tests/UserAvatarServiceTest.cs
@@ -0,0 +1,232 @@
+using FluentAssertions;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging;
+using SixLabors.ImageSharp;
+using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.ImageSharp.Formats.Png;
+using System;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Timeline.Entities;
+using Timeline.Services;
+using Timeline.Tests.Helpers;
+using Timeline.Tests.Mock.Data;
+using Xunit;
+using Xunit.Abstractions;
+
+namespace Timeline.Tests
+{
+ public class MockDefaultUserAvatarProvider : IDefaultUserAvatarProvider
+ {
+ public static Avatar Avatar { get; } = new Avatar { Type = "image/test", Data = Encoding.ASCII.GetBytes("test") };
+
+ public Task<Avatar> GetDefaultAvatar()
+ {
+ return Task.FromResult(Avatar);
+ }
+ }
+
+ public class MockUserAvatarValidator : IUserAvatarValidator
+ {
+ public Task Validate(Avatar avatar)
+ {
+ return Task.CompletedTask;
+ }
+ }
+
+ public class UserAvatarValidatorTest : IClassFixture<UserAvatarValidator>
+ {
+ private readonly UserAvatarValidator _validator;
+
+ public UserAvatarValidatorTest(UserAvatarValidator validator)
+ {
+ _validator = validator;
+ }
+
+ [Fact]
+ public void CantDecode()
+ {
+ Avatar avatar = new Avatar
+ {
+ Data = Encoding.ASCII.GetBytes("This is not a image."),
+ Type = "image/png"
+ };
+ _validator.Awaiting(v => v.Validate(avatar))
+ .Should().Throw<AvatarDataException>()
+ .Where(e => e.Avatar == avatar && e.Error == AvatarDataException.ErrorReason.CantDecode);
+ }
+
+ [Fact]
+ public void UnmatchedFormat()
+ {
+ Avatar avatar = new Avatar
+ {
+ Data = ImageHelper.CreatePngWithSize(100, 100),
+ Type = "image/jpeg"
+ };
+ _validator.Awaiting(v => v.Validate(avatar))
+ .Should().Throw<AvatarDataException>()
+ .Where(e => e.Avatar == avatar && e.Error == AvatarDataException.ErrorReason.UnmatchedFormat);
+ }
+
+ [Fact]
+ public void BadSize()
+ {
+ Avatar avatar = new Avatar
+ {
+ Data = ImageHelper.CreatePngWithSize(100, 200),
+ Type = PngFormat.Instance.DefaultMimeType
+ };
+ _validator.Awaiting(v => v.Validate(avatar))
+ .Should().Throw<AvatarDataException>()
+ .Where(e => e.Avatar == avatar && e.Error == AvatarDataException.ErrorReason.BadSize);
+ }
+
+ [Fact]
+ public void Success()
+ {
+ Avatar avatar = new Avatar
+ {
+ Data = ImageHelper.CreatePngWithSize(100, 100),
+ Type = PngFormat.Instance.DefaultMimeType
+ };
+ _validator.Awaiting(v => v.Validate(avatar))
+ .Should().NotThrow();
+ }
+ }
+
+ public class UserAvatarServiceTest : IDisposable, IClassFixture<MockDefaultUserAvatarProvider>, IClassFixture<MockUserAvatarValidator>
+ {
+ private static Avatar MockAvatar { get; } = new Avatar
+ {
+ Type = "image/testaaa",
+ Data = Encoding.ASCII.GetBytes("amock")
+ };
+
+ private static Avatar MockAvatar2 { get; } = new Avatar
+ {
+ Type = "image/testbbb",
+ Data = Encoding.ASCII.GetBytes("bmock")
+ };
+
+ private readonly MockDefaultUserAvatarProvider _mockDefaultUserAvatarProvider;
+
+ private readonly LoggerFactory _loggerFactory;
+ private readonly TestDatabase _database;
+
+ private readonly UserAvatarService _service;
+
+ public UserAvatarServiceTest(ITestOutputHelper outputHelper, MockDefaultUserAvatarProvider mockDefaultUserAvatarProvider, MockUserAvatarValidator mockUserAvatarValidator)
+ {
+ _mockDefaultUserAvatarProvider = mockDefaultUserAvatarProvider;
+
+ _loggerFactory = MyTestLoggerFactory.Create(outputHelper);
+ _database = new TestDatabase();
+
+ _service = new UserAvatarService(_loggerFactory.CreateLogger<UserAvatarService>(), _database.DatabaseContext, _mockDefaultUserAvatarProvider, mockUserAvatarValidator);
+ }
+
+ public void Dispose()
+ {
+ _loggerFactory.Dispose();
+ _database.Dispose();
+ }
+
+ [Fact]
+ public void GetAvatar_ShouldThrow_ArgumentException()
+ {
+ // no need to await because arguments are checked syncronizedly.
+ _service.Invoking(s => s.GetAvatar(null)).Should().Throw<ArgumentException>()
+ .Where(e => e.ParamName == "username" && e.Message.Contains("null", StringComparison.OrdinalIgnoreCase));
+ _service.Invoking(s => s.GetAvatar("")).Should().Throw<ArgumentException>()
+ .Where(e => e.ParamName == "username" && e.Message.Contains("empty", StringComparison.OrdinalIgnoreCase));
+ }
+
+ [Fact]
+ public void GetAvatar_ShouldThrow_UserNotExistException()
+ {
+ const string username = "usernotexist";
+ _service.Awaiting(s => s.GetAvatar(username)).Should().Throw<UserNotExistException>()
+ .Where(e => e.Username == username);
+ }
+
+ [Fact]
+ public async Task GetAvatar_ShouldReturn_Default()
+ {
+ const string username = MockUsers.UserUsername;
+ (await _service.GetAvatar(username)).Should().BeEquivalentTo(await _mockDefaultUserAvatarProvider.GetDefaultAvatar());
+ }
+
+ [Fact]
+ public async Task GetAvatar_ShouldReturn_Data()
+ {
+ const string username = MockUsers.UserUsername;
+
+ {
+ // create mock data
+ var context = _database.DatabaseContext;
+ var user = await context.Users.Where(u => u.Name == username).Include(u => u.Avatar).SingleAsync();
+ user.Avatar = new UserAvatar
+ {
+ Type = MockAvatar.Type,
+ Data = MockAvatar.Data
+ };
+ await context.SaveChangesAsync();
+ }
+
+ (await _service.GetAvatar(username)).Should().BeEquivalentTo(MockAvatar);
+ }
+
+ [Fact]
+ public void SetAvatar_ShouldThrow_ArgumentException()
+ {
+ // no need to await because arguments are checked syncronizedly.
+ _service.Invoking(s => s.SetAvatar(null, MockAvatar)).Should().Throw<ArgumentException>()
+ .Where(e => e.ParamName == "username" && e.Message.Contains("null", StringComparison.OrdinalIgnoreCase));
+ _service.Invoking(s => s.SetAvatar("", MockAvatar)).Should().Throw<ArgumentException>()
+ .Where(e => e.ParamName == "username" && e.Message.Contains("empty", StringComparison.OrdinalIgnoreCase));
+
+ _service.Invoking(s => s.SetAvatar("aaa", new Avatar { Type = null, Data = new[] { (byte)0x00 } })).Should().Throw<ArgumentException>()
+ .Where(e => e.ParamName == "avatar" && e.Message.Contains("null", StringComparison.OrdinalIgnoreCase));
+ _service.Invoking(s => s.SetAvatar("aaa", new Avatar { Type = "", Data = new[] { (byte)0x00 } })).Should().Throw<ArgumentException>()
+ .Where(e => e.ParamName == "avatar" && e.Message.Contains("empty", StringComparison.OrdinalIgnoreCase));
+
+ _service.Invoking(s => s.SetAvatar("aaa", new Avatar { Type = "aaa", Data = null })).Should().Throw<ArgumentException>()
+ .Where(e => e.ParamName == "avatar" && e.Message.Contains("null", StringComparison.OrdinalIgnoreCase));
+ }
+
+ [Fact]
+ public void SetAvatar_ShouldThrow_UserNotExistException()
+ {
+ const string username = "usernotexist";
+ _service.Awaiting(s => s.SetAvatar(username, MockAvatar)).Should().Throw<UserNotExistException>()
+ .Where(e => e.Username == username);
+ }
+
+ [Fact]
+ public async Task SetAvatar_Should_Work()
+ {
+ const string username = MockUsers.UserUsername;
+
+ var user = await _database.DatabaseContext.Users.Where(u => u.Name == username).Include(u => u.Avatar).SingleAsync();
+
+ // create
+ await _service.SetAvatar(username, MockAvatar);
+ user.Avatar.Should().NotBeNull();
+ user.Avatar.Type.Should().Be(MockAvatar.Type);
+ user.Avatar.Data.Should().Equal(MockAvatar.Data);
+
+ // modify
+ await _service.SetAvatar(username, MockAvatar2);
+ user.Avatar.Should().NotBeNull();
+ user.Avatar.Type.Should().Be(MockAvatar2.Type);
+ user.Avatar.Data.Should().Equal(MockAvatar2.Data);
+
+ // delete
+ await _service.SetAvatar(username, null);
+ user.Avatar.Should().BeNull();
+ }
+ }
+}
diff --git a/Timeline/Authenticate/PrincipalExtensions.cs b/Timeline/Authenticate/PrincipalExtensions.cs
new file mode 100644
index 00000000..fa39ea89
--- /dev/null
+++ b/Timeline/Authenticate/PrincipalExtensions.cs
@@ -0,0 +1,13 @@
+using System.Security.Principal;
+using Timeline.Entities;
+
+namespace Timeline.Authenticate
+{
+ public static class PrincipalExtensions
+ {
+ public static bool IsAdmin(this IPrincipal principal)
+ {
+ return principal.IsInRole(UserRoles.Admin);
+ }
+ }
+}
diff --git a/Timeline/Controllers/UserAvatarController.cs b/Timeline/Controllers/UserAvatarController.cs
new file mode 100644
index 00000000..710ca764
--- /dev/null
+++ b/Timeline/Controllers/UserAvatarController.cs
@@ -0,0 +1,135 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Threading.Tasks;
+using Timeline.Authenticate;
+using Timeline.Models.Http;
+using Timeline.Services;
+
+namespace Timeline.Controllers
+{
+ [ApiController]
+ public class UserAvatarController : Controller
+ {
+ public static class ErrorCodes
+ {
+ public const int Get_UserNotExist = -1001;
+
+ public const int Put_UserNotExist = -2001;
+ public const int Put_Forbid = -2002;
+ public const int Put_BadFormat_CantDecode = -2011;
+ public const int Put_BadFormat_UnmatchedFormat = -2012;
+ public const int Put_BadFormat_BadSize = -2013;
+
+ public const int Delete_UserNotExist = -3001;
+ public const int Delete_Forbid = -3002;
+
+
+ public static int From(AvatarDataException.ErrorReason error)
+ {
+ switch (error)
+ {
+ case AvatarDataException.ErrorReason.CantDecode:
+ return Put_BadFormat_CantDecode;
+ case AvatarDataException.ErrorReason.UnmatchedFormat:
+ return Put_BadFormat_UnmatchedFormat;
+ case AvatarDataException.ErrorReason.BadSize:
+ return Put_BadFormat_BadSize;
+ default:
+ throw new Exception("Unknown AvatarDataException.ErrorReason value.");
+ }
+ }
+ }
+
+ private readonly ILogger<UserAvatarController> _logger;
+
+ private readonly IUserAvatarService _service;
+
+ public UserAvatarController(ILogger<UserAvatarController> logger, IUserAvatarService service)
+ {
+ _logger = logger;
+ _service = service;
+ }
+
+ [HttpGet("users/{username}/avatar")]
+ [Authorize]
+ public async Task<IActionResult> Get(string username)
+ {
+ try
+ {
+ var avatar = await _service.GetAvatar(username);
+ return File(avatar.Data, avatar.Type);
+ }
+ catch (UserNotExistException e)
+ {
+ _logger.LogInformation(e, $"Attempt to get a avatar of a non-existent user failed. Username: {username} .");
+ return NotFound(new CommonResponse(ErrorCodes.Get_UserNotExist, "User does not exist."));
+ }
+ }
+
+ [HttpPut("users/{username}/avatar")]
+ [Authorize]
+ [Consumes("image/png", "image/jpeg", "image/gif", "image/webp")]
+ public async Task<IActionResult> Put(string username)
+ {
+ if (!User.IsAdmin() && User.Identity.Name != username)
+ {
+ _logger.LogInformation($"Attempt to put a avatar of other user as a non-admin failed. Operator Username: {User.Identity.Name} ; Username To Put Avatar: {username} .");
+ return StatusCode(StatusCodes.Status403Forbidden,
+ new CommonResponse(ErrorCodes.Put_Forbid, "Normal user can't change other's avatar."));
+ }
+
+ try
+ {
+ var data = new byte[Convert.ToInt32(Request.ContentLength)];
+ await Request.Body.ReadAsync(data, 0, data.Length);
+
+ await _service.SetAvatar(username, new Avatar
+ {
+ Data = data,
+ Type = Request.ContentType
+ });
+
+ _logger.LogInformation($"Succeed to put a avatar of a user. Username: {username} ; Mime Type: {Request.ContentType} .");
+ return Ok();
+ }
+ catch (UserNotExistException e)
+ {
+ _logger.LogInformation(e, $"Attempt to put a avatar of a non-existent user failed. Username: {username} .");
+ return BadRequest(new CommonResponse(ErrorCodes.Put_UserNotExist, "User does not exist."));
+ }
+ catch (AvatarDataException e)
+ {
+ _logger.LogInformation(e, $"Attempt to put a avatar of a bad format failed. Username: {username} .");
+ return BadRequest(new CommonResponse(ErrorCodes.From(e.Error), "Bad format."));
+ }
+ }
+
+ [HttpDelete("users/{username}/avatar")]
+ [Authorize]
+ public async Task<IActionResult> Delete(string username)
+ {
+ if (!User.IsAdmin() && User.Identity.Name != username)
+ {
+ _logger.LogInformation($"Attempt to delete a avatar of other user as a non-admin failed. Operator Username: {User.Identity.Name} ; Username To Put Avatar: {username} .");
+ return StatusCode(StatusCodes.Status403Forbidden,
+ new CommonResponse(ErrorCodes.Delete_Forbid, "Normal user can't delete other's avatar."));
+ }
+
+ try
+ {
+ await _service.SetAvatar(username, null);
+
+ _logger.LogInformation($"Succeed to delete a avatar of a user. Username: {username} .");
+ return Ok();
+ }
+ catch (UserNotExistException e)
+ {
+ _logger.LogInformation(e, $"Attempt to delete a avatar of a non-existent user failed. Username: {username} .");
+ return BadRequest(new CommonResponse(ErrorCodes.Delete_UserNotExist, "User does not exist."));
+ }
+ }
+ }
+}
diff --git a/Timeline/Entities/DatabaseContext.cs b/Timeline/Entities/DatabaseContext.cs
index 3629e821..f32e5992 100644
--- a/Timeline/Entities/DatabaseContext.cs
+++ b/Timeline/Entities/DatabaseContext.cs
@@ -27,6 +27,8 @@ namespace Timeline.Entities
[Column("version"), Required]
public long Version { get; set; }
+
+ public UserAvatar Avatar { get; set; }
}
public class DatabaseContext : DbContext
@@ -44,5 +46,6 @@ namespace Timeline.Entities
}
public DbSet<User> Users { get; set; }
+ public DbSet<UserAvatar> UserAvatars { get; set; }
}
}
diff --git a/Timeline/Entities/UserAvatar.cs b/Timeline/Entities/UserAvatar.cs
new file mode 100644
index 00000000..d7c24403
--- /dev/null
+++ b/Timeline/Entities/UserAvatar.cs
@@ -0,0 +1,18 @@
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace Timeline.Entities
+{
+ [Table("user_avatars")]
+ public class UserAvatar
+ {
+ [Column("id"), Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
+ public long Id { get; set; }
+
+ [Column("data"), Required]
+ public byte[] Data { get; set; }
+
+ [Column("type"), Required]
+ public string Type { get; set; }
+ }
+}
diff --git a/Timeline/Migrations/20190818174505_AddUserAvatar.Designer.cs b/Timeline/Migrations/20190818174505_AddUserAvatar.Designer.cs
new file mode 100644
index 00000000..b0a105d0
--- /dev/null
+++ b/Timeline/Migrations/20190818174505_AddUserAvatar.Designer.cs
@@ -0,0 +1,83 @@
+// <auto-generated />
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Timeline.Entities;
+
+namespace Timeline.Migrations
+{
+ [DbContext(typeof(DatabaseContext))]
+ [Migration("20190818174505_AddUserAvatar")]
+ partial class AddUserAvatar
+ {
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "2.2.6-servicing-10079")
+ .HasAnnotation("Relational:MaxIdentifierLength", 64);
+
+ modelBuilder.Entity("Timeline.Entities.User", b =>
+ {
+ b.Property<long>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnName("id");
+
+ b.Property<long?>("AvatarId");
+
+ b.Property<string>("EncryptedPassword")
+ .IsRequired()
+ .HasColumnName("password");
+
+ b.Property<string>("Name")
+ .IsRequired()
+ .HasColumnName("name")
+ .HasMaxLength(26);
+
+ b.Property<string>("RoleString")
+ .IsRequired()
+ .HasColumnName("roles");
+
+ b.Property<long>("Version")
+ .ValueGeneratedOnAdd()
+ .HasColumnName("version")
+ .HasDefaultValue(0L);
+
+ b.HasKey("Id");
+
+ b.HasIndex("AvatarId");
+
+ b.ToTable("users");
+ });
+
+ modelBuilder.Entity("Timeline.Entities.UserAvatar", b =>
+ {
+ b.Property<long>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnName("id");
+
+ b.Property<byte[]>("Data")
+ .IsRequired()
+ .HasColumnName("data");
+
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasColumnName("type");
+
+ b.HasKey("Id");
+
+ b.ToTable("user_avatars");
+ });
+
+ modelBuilder.Entity("Timeline.Entities.User", b =>
+ {
+ b.HasOne("Timeline.Entities.UserAvatar", "Avatar")
+ .WithMany()
+ .HasForeignKey("AvatarId");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Timeline/Migrations/20190818174505_AddUserAvatar.cs b/Timeline/Migrations/20190818174505_AddUserAvatar.cs
new file mode 100644
index 00000000..7e0843c4
--- /dev/null
+++ b/Timeline/Migrations/20190818174505_AddUserAvatar.cs
@@ -0,0 +1,62 @@
+using System;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace Timeline.Migrations
+{
+ public partial class AddUserAvatar : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn<long>(
+ name: "AvatarId",
+ table: "users",
+ nullable: true);
+
+ migrationBuilder.CreateTable(
+ name: "user_avatars",
+ columns: table => new
+ {
+ id = table.Column<long>(nullable: false)
+ .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
+ data = table.Column<byte[]>(nullable: false),
+ type = table.Column<string>(nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_user_avatars", x => x.id);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_users_AvatarId",
+ table: "users",
+ column: "AvatarId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_users_user_avatars_AvatarId",
+ table: "users",
+ column: "AvatarId",
+ principalTable: "user_avatars",
+ principalColumn: "id",
+ onDelete: ReferentialAction.Restrict);
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_users_user_avatars_AvatarId",
+ table: "users");
+
+ migrationBuilder.DropTable(
+ name: "user_avatars");
+
+ migrationBuilder.DropIndex(
+ name: "IX_users_AvatarId",
+ table: "users");
+
+ migrationBuilder.DropColumn(
+ name: "AvatarId",
+ table: "users");
+ }
+ }
+}
diff --git a/Timeline/Migrations/DatabaseContextModelSnapshot.cs b/Timeline/Migrations/DatabaseContextModelSnapshot.cs
index e1de451c..152bdea4 100644
--- a/Timeline/Migrations/DatabaseContextModelSnapshot.cs
+++ b/Timeline/Migrations/DatabaseContextModelSnapshot.cs
@@ -1,4 +1,5 @@
// <auto-generated />
+using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
@@ -22,6 +23,8 @@ namespace Timeline.Migrations
.ValueGeneratedOnAdd()
.HasColumnName("id");
+ b.Property<long?>("AvatarId");
+
b.Property<string>("EncryptedPassword")
.IsRequired()
.HasColumnName("password");
@@ -42,8 +45,36 @@ namespace Timeline.Migrations
b.HasKey("Id");
+ b.HasIndex("AvatarId");
+
b.ToTable("users");
});
+
+ modelBuilder.Entity("Timeline.Entities.UserAvatar", b =>
+ {
+ b.Property<long>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnName("id");
+
+ b.Property<byte[]>("Data")
+ .IsRequired()
+ .HasColumnName("data");
+
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasColumnName("type");
+
+ b.HasKey("Id");
+
+ b.ToTable("user_avatars");
+ });
+
+ modelBuilder.Entity("Timeline.Entities.User", b =>
+ {
+ b.HasOne("Timeline.Entities.UserAvatar", "Avatar")
+ .WithMany()
+ .HasForeignKey("AvatarId");
+ });
#pragma warning restore 612, 618
}
}
diff --git a/Timeline/Services/UserAvatarService.cs b/Timeline/Services/UserAvatarService.cs
new file mode 100644
index 00000000..dd0e5e7c
--- /dev/null
+++ b/Timeline/Services/UserAvatarService.cs
@@ -0,0 +1,250 @@
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using SixLabors.ImageSharp;
+using SixLabors.ImageSharp.Formats;
+using System;
+using System.IO;
+using System.Linq;
+using System.Threading.Tasks;
+using Timeline.Entities;
+
+namespace Timeline.Services
+{
+ public class Avatar
+ {
+ public string Type { get; set; }
+ public byte[] Data { get; set; }
+ }
+
+ /// <summary>
+ /// Thrown when avatar is of bad format.
+ /// </summary>
+ [Serializable]
+ public class AvatarDataException : Exception
+ {
+ public enum ErrorReason
+ {
+ /// <summary>
+ /// Decoding image failed.
+ /// </summary>
+ CantDecode,
+ /// <summary>
+ /// Decoding succeeded but the real type is not the specified type.
+ /// </summary>
+ UnmatchedFormat,
+ /// <summary>
+ /// Image is not a square.
+ /// </summary>
+ BadSize
+ }
+
+ public AvatarDataException(Avatar avatar, ErrorReason error, string message) : base(message) { Avatar = avatar; Error = error; }
+ public AvatarDataException(Avatar avatar, ErrorReason error, string message, Exception inner) : base(message, inner) { Avatar = avatar; Error = error; }
+ protected AvatarDataException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
+
+ public ErrorReason Error { get; set; }
+ public Avatar Avatar { get; set; }
+ }
+
+ /// <summary>
+ /// Provider for default user avatar.
+ /// </summary>
+ /// <remarks>
+ /// Mainly for unit tests.
+ /// </remarks>
+ public interface IDefaultUserAvatarProvider
+ {
+ /// <summary>
+ /// Get the default avatar.
+ /// </summary>
+ Task<Avatar> GetDefaultAvatar();
+ }
+
+ public interface IUserAvatarValidator
+ {
+ /// <summary>
+ /// Validate a avatar's format and size info.
+ /// </summary>
+ /// <param name="avatar">The avatar to validate.</param>
+ /// <exception cref="AvatarDataException">Thrown when validation failed.</exception>
+ Task Validate(Avatar avatar);
+ }
+
+ public interface IUserAvatarService
+ {
+ /// <summary>
+ /// Get avatar of a user. If the user has no avatar, a default one is returned.
+ /// </summary>
+ /// <param name="username">The username of the user to get avatar of.</param>
+ /// <returns>The avatar.</returns>
+ /// <exception cref="ArgumentException">Thrown if <paramref name="username"/> is null or empty.</exception>
+ /// <exception cref="UserNotExistException">Thrown if the user does not exist.</exception>
+ Task<Avatar> GetAvatar(string username);
+
+ /// <summary>
+ /// Set avatar for a user.
+ /// </summary>
+ /// <param name="username">The username of the user to set avatar for.</param>
+ /// <param name="avatar">The avatar. Can be null to delete the saved avatar.</param>
+ /// <exception cref="ArgumentException">Throw if <paramref name="username"/> is null or empty.
+ /// Or thrown if <paramref name="avatar"/> is not null but <see cref="Avatar.Type"/> is null or empty or <see cref="Avatar.Data"/> is null.</exception>
+ /// <exception cref="UserNotExistException">Thrown if the user does not exist.</exception>
+ /// <exception cref="AvatarDataException">Thrown if avatar is of bad format.</exception>
+ Task SetAvatar(string username, Avatar avatar);
+ }
+
+ public class DefaultUserAvatarProvider : IDefaultUserAvatarProvider
+ {
+ private readonly IHostingEnvironment _environment;
+
+ public DefaultUserAvatarProvider(IHostingEnvironment environment)
+ {
+ _environment = environment;
+ }
+
+ public async Task<Avatar> GetDefaultAvatar()
+ {
+ return new Avatar
+ {
+ Type = "image/png",
+ Data = await File.ReadAllBytesAsync(Path.Combine(_environment.ContentRootPath, "default-avatar.png"))
+ };
+ }
+ }
+
+ public class UserAvatarValidator : IUserAvatarValidator
+ {
+ public Task Validate(Avatar avatar)
+ {
+ return Task.Run(() =>
+ {
+ try
+ {
+ using (var image = Image.Load(avatar.Data, out IImageFormat format))
+ {
+ if (!format.MimeTypes.Contains(avatar.Type))
+ throw new AvatarDataException(avatar, AvatarDataException.ErrorReason.UnmatchedFormat, "Image's actual mime type is not the specified one.");
+ if (image.Width != image.Height)
+ throw new AvatarDataException(avatar, AvatarDataException.ErrorReason.BadSize, "Image is not a square, aka, width is not equal to height.");
+ }
+ }
+ catch (UnknownImageFormatException e)
+ {
+ throw new AvatarDataException(avatar, AvatarDataException.ErrorReason.CantDecode, "Failed to decode image. See inner exception.", e);
+ }
+ });
+ }
+ }
+
+ public class UserAvatarService : IUserAvatarService
+ {
+
+ private readonly ILogger<UserAvatarService> _logger;
+
+ private readonly DatabaseContext _database;
+
+ private readonly IDefaultUserAvatarProvider _defaultUserAvatarProvider;
+ private readonly IUserAvatarValidator _avatarValidator;
+
+ public UserAvatarService(ILogger<UserAvatarService> logger, DatabaseContext database, IDefaultUserAvatarProvider defaultUserAvatarProvider, IUserAvatarValidator avatarValidator)
+ {
+ _logger = logger;
+ _database = database;
+ _defaultUserAvatarProvider = defaultUserAvatarProvider;
+ _avatarValidator = avatarValidator;
+ }
+
+ public async Task<Avatar> GetAvatar(string username)
+ {
+ if (string.IsNullOrEmpty(username))
+ throw new ArgumentException("Username is null or empty.", nameof(username));
+
+ var user = await _database.Users.Where(u => u.Name == username).SingleOrDefaultAsync();
+ if (user == null)
+ throw new UserNotExistException(username);
+
+ await _database.Entry(user).Reference(u => u.Avatar).LoadAsync();
+ var avatar = user.Avatar;
+
+ if (avatar == null)
+ {
+ return await _defaultUserAvatarProvider.GetDefaultAvatar();
+ }
+ else
+ {
+ return new Avatar
+ {
+ Type = avatar.Type,
+ Data = avatar.Data
+ };
+ }
+ }
+
+ public async Task SetAvatar(string username, Avatar avatar)
+ {
+ if (string.IsNullOrEmpty(username))
+ throw new ArgumentException("Username is null or empty.", nameof(username));
+
+ if (avatar != null)
+ {
+ if (string.IsNullOrEmpty(avatar.Type))
+ throw new ArgumentException("Type of avatar is null or empty.", nameof(avatar));
+ if (avatar.Data == null)
+ throw new ArgumentException("Data of avatar is null.", nameof(avatar));
+ }
+
+ var user = await _database.Users.Where(u => u.Name == username).SingleOrDefaultAsync();
+ if (user == null)
+ throw new UserNotExistException(username);
+
+ await _database.Entry(user).Reference(u => u.Avatar).LoadAsync();
+ var avatarEntity = user.Avatar;
+
+ if (avatar == null)
+ {
+ if (avatarEntity == null)
+ return;
+ else
+ {
+ _database.UserAvatars.Remove(avatarEntity);
+ await _database.SaveChangesAsync();
+ _logger.LogInformation("Removed an entry in user_avatars.");
+ }
+ }
+ else
+ {
+ await _avatarValidator.Validate(avatar);
+
+ if (avatarEntity == null)
+ {
+ user.Avatar = new UserAvatar
+ {
+ Type = avatar.Type,
+ Data = avatar.Data
+ };
+ }
+ else
+ {
+ avatarEntity.Type = avatar.Type;
+ avatarEntity.Data = avatar.Data;
+ }
+ await _database.SaveChangesAsync();
+ _logger.LogInformation("Added or modified an entry in user_avatars.");
+ }
+ }
+ }
+
+ public static class UserAvatarServiceCollectionExtensions
+ {
+ public static void AddUserAvatarService(this IServiceCollection services)
+ {
+ services.AddScoped<IUserAvatarService, UserAvatarService>();
+ services.AddSingleton<IDefaultUserAvatarProvider, DefaultUserAvatarProvider>();
+ services.AddSingleton<IUserAvatarValidator, UserAvatarValidator>();
+ }
+ }
+}
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs
index 414bc705..afc06d9b 100644
--- a/Timeline/Startup.cs
+++ b/Timeline/Startup.cs
@@ -58,6 +58,8 @@ namespace Timeline
services.AddTransient<IPasswordService, PasswordService>();
services.AddTransient<IClock, Clock>();
+ services.AddUserAvatarService();
+
var databaseConfig = Configuration.GetSection(nameof(DatabaseConfig)).Get<DatabaseConfig>();
services.AddDbContext<DatabaseContext>(options =>
diff --git a/Timeline/Timeline.csproj b/Timeline/Timeline.csproj
index 1f70c634..3855e0d1 100644
--- a/Timeline/Timeline.csproj
+++ b/Timeline/Timeline.csproj
@@ -5,12 +5,6 @@
<UserSecretsId>1f6fb74d-4277-4bc0-aeea-b1fc5ffb0b43</UserSecretsId>
<Authors>crupest</Authors>
</PropertyGroup>
- <ItemGroup>
- <Compile Remove="Migrations\20190817094126_Enhance.cs" />
- <Compile Remove="Migrations\20190817094126_Enhance.Designer.cs" />
- <Compile Remove="Migrations\20190817094254_Enhance.cs" />
- <Compile Remove="Migrations\20190817094254_Enhance.Designer.cs" />
- </ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
@@ -18,5 +12,6 @@
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" />
+ <PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-dev002868" />
</ItemGroup>
</Project>
diff --git a/Timeline/appsettings.Development.json b/Timeline/appsettings.Development.json
index db4b074a..424b3885 100644
--- a/Timeline/appsettings.Development.json
+++ b/Timeline/appsettings.Development.json
@@ -7,6 +7,6 @@
}
},
"JwtConfig": {
- "SigningKey": "crupest hahahahahahahhahahahahaha"
+ "SigningKey": "this is very very very very very long secret"
}
}
diff --git a/Timeline/default-avatar.png b/Timeline/default-avatar.png
new file mode 100644
index 00000000..4086e1d2
--- /dev/null
+++ b/Timeline/default-avatar.png
Binary files differ
diff --git a/art-src/user.svg b/art-src/user.svg
new file mode 100644
index 00000000..acbd3c8a
--- /dev/null
+++ b/art-src/user.svg
@@ -0,0 +1,4 @@
+<svg viewbox="0 0 100 100" stroke-width="5" stroke="#000000" fill="transparent">
+ <circle cx="50" cy="30" r="20"/>
+ <path d="M 10,90 A 40 40 180 1 1 90,90"/>
+</svg>
diff --git a/nuget.config b/nuget.config
index 22519a86..e1fc7cfe 100644
--- a/nuget.config
+++ b/nuget.config
@@ -1,8 +1,9 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
- <clear/>
- <add key="nuget.org" value="https://api.nuget.org/v3/index.json"/>
+ <clear />
+ <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="aspnetcore-dev" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" />
+ <add key="imagesharp-dev" value="https://www.myget.org/F/sixlabors/api/v3/index.json" />
</packageSources>
</configuration>