| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using molilian.core;
- using dodohold.core;
- using Microsoft.AspNetCore.Mvc;
- using System.Text.Json;
- namespace molilian.api.Controllers
- {
- [ApiController]
- [Route("[controller]/[action]")]
- public class ImgController : ControllerBase
- {
- protected IHttpContextAccessor _accessor;
- public ImgController(IHttpContextAccessor accessor)
- {
- _accessor = accessor;
- }
- [HttpPost("{tokenString}")]
- public async Task<ActionResult> Upfile(string tokenString, IFormFile file)
- {
- if (string.IsNullOrEmpty(tokenString) || file == null || file.Length == 0)
- return new APIResult(new { msg = "参数提交不正确", status = -1 });
- var token = ApiTokenCore.GetOne(tokenString);
- if (token == null)
- return new APIResult(new { msg = "key不正确", status = -2 });
- if (!token.status)
- return new APIResult(new { msg = "账号已经禁用", status = -3 });
- if (token.last_time < DateTime.Now)
- return new APIResult(new { msg = "授权已到期", status = -3 });
- string lockKey = $"lock:{tokenString}";
- if (RedisHelper.Exists(lockKey))
- return new APIResult(new { msg = "请求频率过高", status = -4 });
- using MemoryStream stream = new();
- file.CopyTo(stream);
- var bytes = stream.ToArray();
- var result = await ImageHostingPlus.Dianping(file.FileName, bytes);
- return new APIResult(new { data = result });
- }
- }
- }
|