[backend/api] Create all required fields and return EmojiResponse

This commit is contained in:
pancakes 2024-06-22 13:31:28 +10:00 committed by Iceshrimp development
parent ea0f07d459
commit 8a80c69b91
2 changed files with 36 additions and 9 deletions

View file

@ -214,8 +214,8 @@ public class AdminController(
[HttpPost("emoji")]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(Emoji))]
public async Task<IActionResult> UploadEmoji(IFormFile file)
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(EmojiResponse))]
public async Task<IActionResult> UploadEmoji(IFormFile file, [FromServices] IOptions<Config.InstanceSection> config)
{
var user = await sysUserSvc.GetInstanceActorAsync();
var request = new DriveFileCreationRequest
@ -224,20 +224,35 @@ public class AdminController(
MimeType = file.ContentType,
IsSensitive = false
};
var res = await driveSvc.StoreFile(file.OpenReadStream(), user, request);
var driveFile = await driveSvc.StoreFile(file.OpenReadStream(), user, request);
var id = IdHelpers.GenerateSlowflakeId();
var emoji = new Emoji
{
Id = IdHelpers.GenerateSlowflakeId(),
Name = res.Name,
UpdatedAt = DateTime.UtcNow,
OriginalUrl = res.Url,
PublicUrl = res.PublicUrl
Id = id,
Name = id,
UpdatedAt = DateTime.UtcNow,
OriginalUrl = driveFile.Url,
PublicUrl = driveFile.PublicUrl,
Width = driveFile.Properties.Width,
Height = driveFile.Properties.Height
};
emoji.Uri = emoji.GetPublicUri(config.Value);
await db.AddAsync(emoji);
await db.SaveChangesAsync();
return Ok(emoji);
var res = new EmojiResponse
{
Id = emoji.Id,
Name = emoji.Name,
Uri = emoji.Uri,
Aliases = [],
Category = null,
PublicUrl = emoji.PublicUrl,
License = null
};
return Ok(res);
}
}

View file

@ -0,0 +1,12 @@
namespace Iceshrimp.Shared.Schemas;
public class EmojiResponse
{
public required string Id { get; set; }
public required string Name { get; set; }
public required string? Uri { get; set; }
public required List<string> Aliases { get; set; }
public required string? Category { get; set; }
public required string PublicUrl { get; set; }
public required string? License { get; set; }
}