diff options
author | crupest <crupest@outlook.com> | 2020-08-31 22:22:57 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-08-31 22:22:57 +0800 |
commit | c73388256aad039239cf3977d7b079e3f9323258 (patch) | |
tree | c8f4b17ebb6623a6bafc03a2417d18b8615f94a0 /Timeline | |
parent | 12410a51fb2e5f55e8d83415bc3c4053a146ce3b (diff) | |
download | timeline-c73388256aad039239cf3977d7b079e3f9323258.tar.gz timeline-c73388256aad039239cf3977d7b079e3f9323258.tar.bz2 timeline-c73388256aad039239cf3977d7b079e3f9323258.zip |
Now uesr avatar put api returns etag.
Diffstat (limited to 'Timeline')
-rw-r--r-- | Timeline/Controllers/UserAvatarController.cs | 6 | ||||
-rw-r--r-- | Timeline/Services/UserAvatarService.cs | 14 |
2 files changed, 12 insertions, 8 deletions
diff --git a/Timeline/Controllers/UserAvatarController.cs b/Timeline/Controllers/UserAvatarController.cs index 97c4bdb8..bc4afa30 100644 --- a/Timeline/Controllers/UserAvatarController.cs +++ b/Timeline/Controllers/UserAvatarController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
+using Microsoft.Net.Http.Headers;
using System;
using System.Threading.Tasks;
using Timeline.Auth;
@@ -105,7 +106,7 @@ namespace Timeline.Controllers try
{
- await _service.SetAvatar(id, new Avatar
+ var etag = await _service.SetAvatar(id, new Avatar
{
Data = body.Data,
Type = body.ContentType
@@ -113,6 +114,9 @@ namespace Timeline.Controllers _logger.LogInformation(Log.Format(LogPutSuccess,
("Username", username), ("Mime Type", Request.ContentType)));
+
+ Response.Headers.Append("ETag", new EntityTagHeaderValue($"\"{etag}\"").ToString());
+
return Ok();
}
catch (ImageException e)
diff --git a/Timeline/Services/UserAvatarService.cs b/Timeline/Services/UserAvatarService.cs index 2bf8bddc..b41c45fd 100644 --- a/Timeline/Services/UserAvatarService.cs +++ b/Timeline/Services/UserAvatarService.cs @@ -71,9 +71,10 @@ namespace Timeline.Services /// </summary>
/// <param name="id">The id of the user to set avatar for.</param>
/// <param name="avatar">The avatar. Can be null to delete the saved avatar.</param>
+ /// <returns>The etag of the avatar.</returns>
/// <exception cref="ArgumentException">Thrown if any field in <paramref name="avatar"/> is null when <paramref name="avatar"/> is not null.</exception>
/// <exception cref="ImageException">Thrown if avatar is of bad format.</exception>
- Task SetAvatar(long id, Avatar? avatar);
+ Task<string> SetAvatar(long id, Avatar? avatar);
}
// TODO! : Make this configurable.
@@ -199,7 +200,7 @@ namespace Timeline.Services return defaultAvatar;
}
- public async Task SetAvatar(long id, Avatar? avatar)
+ public async Task<string> SetAvatar(long id, Avatar? avatar)
{
if (avatar != null)
{
@@ -213,11 +214,7 @@ namespace Timeline.Services if (avatar == null)
{
- if (avatarEntity == null || avatarEntity.DataTag == null)
- {
- return;
- }
- else
+ if (avatarEntity != null && avatarEntity.DataTag != null)
{
await _dataManager.FreeEntry(avatarEntity.DataTag);
avatarEntity.DataTag = null;
@@ -226,6 +223,7 @@ namespace Timeline.Services await _database.SaveChangesAsync();
_logger.LogInformation(Resources.Services.UserAvatarService.LogUpdateEntity);
}
+ return await _defaultUserAvatarProvider.GetDefaultAvatarETag();
}
else
{
@@ -250,6 +248,8 @@ namespace Timeline.Services {
await _dataManager.FreeEntry(oldTag);
}
+
+ return avatarEntity.DataTag;
}
}
}
|