Merge branch 'master' of https://gitea.nxsir.cn/nanxun/IM_NEW
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using FileService.Application.UploadFile;
|
||||
using FileService.Infrastructure;
|
||||
using IM.ASPNETCore;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace FileService.WebApi.Controllers.File
|
||||
{
|
||||
@@ -9,7 +13,63 @@ namespace FileService.WebApi.Controllers.File
|
||||
[ApiController]
|
||||
public class FileController : ControllerBase
|
||||
{
|
||||
//[HttpGet]
|
||||
//public async
|
||||
private readonly UploadFileService service;
|
||||
|
||||
public FileController(UploadFileService service)
|
||||
{
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单次直传(小文件:头像/封面等)。isPublic=true 落公开桶,返回直链。
|
||||
/// 支持秒传:若相同 checksum 的文件已存在,直接返回已有记录,跳过上传。
|
||||
/// </summary>
|
||||
[HttpPost("simple-upload")]
|
||||
[UnitOfWork(typeof(FileDbContext))]
|
||||
public async Task<IActionResult> SimpleUpload([FromForm] IFormFile file, [FromForm] bool isPublic)
|
||||
{
|
||||
if (file == null || file.Length == 0)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
await using var stream = file.OpenReadStream();
|
||||
var res = await service.SimpleUploadAsync(new SimpleUploadCommand(
|
||||
OwnerId: Guid.Parse(userId),
|
||||
FileName: file.FileName,
|
||||
ContentType: file.ContentType,
|
||||
FileSize: file.Length,
|
||||
Content: stream,
|
||||
IsPublic: isPublic));
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件信息(含直链 Url;私有文件 Url 为 null)。
|
||||
/// </summary>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IActionResult> Get(Guid id)
|
||||
{
|
||||
var res = await service.GetFileInfoAsync(id);
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 鉴权下载文件内容(私有文件预览/下载走这里)。
|
||||
/// </summary>
|
||||
[HttpGet("{id}/content")]
|
||||
public async Task<IActionResult> GetContent(Guid id)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var res = await service.OpenDownloadAsync(id, Guid.Parse(userId));
|
||||
if (res.Data == null)
|
||||
{
|
||||
return NotFound(res);
|
||||
}
|
||||
|
||||
Response.Headers["Cache-Control"] = "private,max-age=86400";
|
||||
return File(res.Data.Content, res.Data.ContentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,14 @@ namespace FileService.WebApi.Controllers.FileTask
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
[HttpGet("progress")]
|
||||
public async Task<IActionResult> Progress(string sessionId)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var res = await service.GetProgressAsync(sessionId, Guid.Parse(userId));
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
[HttpGet("Getuploadurl")]
|
||||
public async Task<IActionResult> GetUploadUrl(string sessionId, int partNum)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user