|
|
|
@ -2,126 +2,78 @@ |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
|
using System.IO; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
using Volo.Abp.AspNetCore.Mvc; |
|
|
|
using Volo.Abp.Http; |
|
|
|
using Volo.Abp.Content; |
|
|
|
using Volo.Abp.Validation; |
|
|
|
|
|
|
|
namespace LINGYUN.Abp.OssManagement |
|
|
|
{ |
|
|
|
[RemoteService(Name = OssManagementRemoteServiceConsts.RemoteServiceName)] |
|
|
|
[Area("oss-management")] |
|
|
|
[Route("api/files/private")] |
|
|
|
[RemoteService(false)] |
|
|
|
public class PrivateFilesController : AbpController |
|
|
|
public class PrivateFilesController : AbpController, IPrivateFileAppService |
|
|
|
{ |
|
|
|
private readonly IPrivateFileAppService _privateFileAppService; |
|
|
|
private readonly IPrivateFileAppService _service; |
|
|
|
|
|
|
|
public PrivateFilesController( |
|
|
|
IPrivateFileAppService privateFileAppService) |
|
|
|
IPrivateFileAppService service) |
|
|
|
{ |
|
|
|
_privateFileAppService = privateFileAppService; |
|
|
|
_service = service; |
|
|
|
|
|
|
|
LocalizationResource = typeof(AbpOssManagementResource); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
[Route("upload")] |
|
|
|
public virtual async Task UploadAsync([FromForm] UploadOssObjectInput input) |
|
|
|
{ |
|
|
|
await _privateFileAppService.UploadAsync(new UploadFileChunkInput |
|
|
|
public virtual async Task<OssObjectDto> UploadAsync([FromForm] UploadFileInput input) |
|
|
|
{ |
|
|
|
Path = input.Path, |
|
|
|
FileName = input.FileName, |
|
|
|
TotalSize = input.TotalSize, |
|
|
|
ChunkSize = input.ChunkSize, |
|
|
|
ChunkNumber = input.ChunkNumber, |
|
|
|
TotalChunks = input.TotalChunks, |
|
|
|
CurrentChunkSize = input.CurrentChunkSize, |
|
|
|
Content = input.File?.OpenReadStream(), |
|
|
|
}); |
|
|
|
return await _service.UploadAsync(input); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
[Route("{path}")] |
|
|
|
[Route("{path}/{name}")] |
|
|
|
public virtual async Task<OssObjectDto> UploadAsync(string path, string name) |
|
|
|
{ |
|
|
|
if (Request.ContentLength <= 0) |
|
|
|
{ |
|
|
|
ThrowValidationException(L["FileNotBeNullOrEmpty"], "File"); |
|
|
|
} |
|
|
|
|
|
|
|
var file = Request.Form.Files[0]; |
|
|
|
var fileName = name ?? file.FileName; |
|
|
|
|
|
|
|
var createOssObjectInput = new UploadFileInput |
|
|
|
[Route("upload")] |
|
|
|
public virtual async Task UploadAsync(UploadFileChunkInput input) |
|
|
|
{ |
|
|
|
Path = path, |
|
|
|
Object = fileName, |
|
|
|
Content = file.OpenReadStream(), |
|
|
|
Overwrite = true |
|
|
|
}; |
|
|
|
|
|
|
|
return await _privateFileAppService.UploadAsync(createOssObjectInput); |
|
|
|
await _service.UploadAsync(input); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
[Route("search")] |
|
|
|
public virtual async Task<ListResultDto<OssObjectDto>> GetListAsync(GetFilesInput input) |
|
|
|
{ |
|
|
|
return await _privateFileAppService.GetListAsync(input); |
|
|
|
return await _service.GetListAsync(input); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
[Route("{name}")] |
|
|
|
[Route("{name}/{process}")] |
|
|
|
[Route("p/{path}/{name}")] |
|
|
|
[Route("p/{path}/{name}/{process}")] |
|
|
|
public virtual async Task<IActionResult> GetAsync(string path, string name, string process) |
|
|
|
[Route("{Name}")] |
|
|
|
[Route("{Name}/{Process}")] |
|
|
|
[Route("p/{Path}/{Name}")] |
|
|
|
[Route("p/{Path}/{Name}/{Process}")] |
|
|
|
public virtual async Task<IRemoteStreamContent> GetAsync([FromRoute] GetPublicFileInput input) |
|
|
|
{ |
|
|
|
var input = new GetPublicFileInput |
|
|
|
{ |
|
|
|
Name = name, |
|
|
|
Path = path, |
|
|
|
Process = process |
|
|
|
}; |
|
|
|
var fileStream = await _privateFileAppService.GetAsync(input); |
|
|
|
|
|
|
|
if (fileStream.IsNullOrEmpty()) |
|
|
|
{ |
|
|
|
return NotFound(); |
|
|
|
return await _service.GetAsync(input); |
|
|
|
} |
|
|
|
|
|
|
|
return File( |
|
|
|
fileStream, |
|
|
|
MimeTypes.GetByExtension(Path.GetExtension(input.Name)) |
|
|
|
); |
|
|
|
[HttpDelete] |
|
|
|
public virtual async Task DeleteAsync(GetPublicFileInput input) |
|
|
|
{ |
|
|
|
await _service.DeleteAsync(input); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
[Route("share")] |
|
|
|
public virtual async Task<ListResultDto<MyFileShareDto>> GetShareListAsync() |
|
|
|
{ |
|
|
|
return await _privateFileAppService.GetShareListAsync(); |
|
|
|
return await _service.GetShareListAsync(); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
[Route("share")] |
|
|
|
public virtual async Task<FileShareDto> ShareAsync([FromBody] FileShareInput input) |
|
|
|
{ |
|
|
|
return await _privateFileAppService.ShareAsync(input); |
|
|
|
} |
|
|
|
|
|
|
|
private static void ThrowValidationException(string message, string memberName) |
|
|
|
{ |
|
|
|
throw new AbpValidationException(message, |
|
|
|
new List<ValidationResult> |
|
|
|
public virtual async Task<FileShareDto> ShareAsync(FileShareInput input) |
|
|
|
{ |
|
|
|
new ValidationResult(message, new[] {memberName}) |
|
|
|
}); |
|
|
|
return await _service.ShareAsync(input); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|