using Blahblah.FlowerStory.Server.Data;
using Microsoft.AspNetCore.Mvc;
namespace Blahblah.FlowerStory.Server.Controller;
///
/// 图片相关服务
///
[Produces("image/png")]
[Route("photo")]
public class ImageController : BaseController
{
///
public ImageController(FlowerDatabase database, ILogger? logger = null) : base(database, logger)
{
}
///
/// 请求用户头像
///
///
/// 请求示例:
///
/// GET /photo/avatar
/// Authorization: authorization id
///
///
/// 认证通过则显示用户头像
/// 返回头像
/// 认证失败
/// 未找到头像
[Route("avatar", Name = "getAvatar")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[HttpGet]
public ActionResult GetUserAvatar()
{
var (result, token) = CheckToken();
if (result != null)
{
return result;
}
if (token == null)
{
return Unauthorized();
}
var avatar = QueryUserAvatar(token.UserId);
if (avatar == null)
{
return NotFound();
}
return File(avatar, "image/png");
}
}