using Hncore.Infrastructure.WebApi;
using Hncore.Pass.Vpn.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Hncore.Pass.OSS.Controllers
{
    [ApiVersion("1.0")]
    [Route("api/oss/v{version:apiVersion}/ImageCloud/[action]")]
    public class ImageCloudController : HncoreControllerBase
    {
        UploadService m_UploadService;     
     
        public ImageCloudController(UploadService _UploadService)
        {
            m_UploadService = _UploadService;        
        }

        [HttpPost, AllowAnonymous]
        public async Task<ApiResult> Upload()
        {
            var ret = await m_UploadService.GetStreamFromRequest(this.Request);

            if (ret.Item2 == null)
                return Error("没有图片");

            var url = m_UploadService.AliYunUpload(ret.Item1, ret.Item2,ret.Item3);
            return Success(url);
        }
    }
}
