mirror of https://github.com/abpframework/abp.git
22 changed files with 350 additions and 52 deletions
@ -0,0 +1,15 @@ |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.IO |
|||
{ |
|||
public class FileHelper_Tests |
|||
{ |
|||
[Fact] |
|||
public void GetExtension() |
|||
{ |
|||
FileHelper.GetExtension("test").ShouldBeNull(); |
|||
FileHelper.GetExtension("te.st").ShouldBe("st"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Docs.Documents |
|||
{ |
|||
public class DocumentResourceDto |
|||
{ |
|||
public byte[] Content { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Docs.Projects; |
|||
|
|||
namespace Volo.Docs.Documents |
|||
{ |
|||
public class GetDocumentResourceInput |
|||
{ |
|||
public Guid ProjectId { get; set; } |
|||
|
|||
[Required] |
|||
[StringLength(DocumentConsts.MaxNameLength)] |
|||
public string Name { get; set; } |
|||
|
|||
[StringLength(ProjectConsts.MaxVersionNameLength)] |
|||
public string Version { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using System; |
|||
using System.Runtime.Serialization; |
|||
using Volo.Abp; |
|||
|
|||
namespace Volo.Docs |
|||
{ |
|||
[Serializable] |
|||
public class ResourceNotFoundException : BusinessException |
|||
{ |
|||
public string ResourceName { get; set; } |
|||
|
|||
public ResourceNotFoundException(SerializationInfo serializationInfo, StreamingContext context) |
|||
: base(serializationInfo, context) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public ResourceNotFoundException(string resourceName) |
|||
{ |
|||
ResourceName = resourceName; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
namespace Volo.Docs.Documents |
|||
{ |
|||
public class DocumentResource |
|||
{ |
|||
public byte[] Content { get; } |
|||
|
|||
public DocumentResource(byte[] content) |
|||
{ |
|||
Content = content; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Services; |
|||
using Volo.Docs.Documents; |
|||
using Volo.Docs.FileSystem.Projects; |
|||
using Volo.Docs.Projects; |
|||
|
|||
namespace Volo.Docs.FileSystem.Documents |
|||
{ |
|||
public class FileSystemDocumentStore : DomainService, IDocumentStore |
|||
{ |
|||
public const string Type = "FileSystem"; |
|||
|
|||
public async Task<Document> GetDocument(Project project, string documentName, string version) |
|||
{ |
|||
var path = Path.Combine(project.GetFileSystemPath(), documentName); |
|||
var content = File.ReadAllText(path); //TODO: async!
|
|||
var localDirectory = ""; |
|||
|
|||
if (documentName.Contains("/")) |
|||
{ |
|||
localDirectory = documentName.Substring(0, documentName.LastIndexOf('/')); |
|||
} |
|||
|
|||
return new Document |
|||
{ |
|||
Content = content, |
|||
FileName = Path.GetFileName(path), |
|||
Format = project.Format, |
|||
LocalDirectory = localDirectory, |
|||
Title = documentName, |
|||
RawRootUrl = $"/document-resources?projectId={project.Id.ToString()}&version={version}&name=", |
|||
RootUrl = "/" |
|||
}; |
|||
} |
|||
|
|||
public Task<List<VersionInfo>> GetVersions(Project project) |
|||
{ |
|||
return Task.FromResult(new List<VersionInfo>()); |
|||
} |
|||
|
|||
public async Task<DocumentResource> GetResource(Project project, string resourceName, string version) |
|||
{ |
|||
var path = Path.Combine(project.GetFileSystemPath(), resourceName); |
|||
return new DocumentResource(File.ReadAllBytes(path)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp; |
|||
using Volo.Docs.FileSystem.Documents; |
|||
using Volo.Docs.Projects; |
|||
|
|||
namespace Volo.Docs.FileSystem.Projects |
|||
{ |
|||
public static class ProjectFileSystemExtensions |
|||
{ |
|||
public static string GetFileSystemPath([NotNull] this Project project) |
|||
{ |
|||
CheckFileSystemProject(project); |
|||
return project.ExtraProperties["Path"] as string; |
|||
} |
|||
|
|||
public static void SetFileSystemPath([NotNull] this Project project, string value) |
|||
{ |
|||
CheckFileSystemProject(project); |
|||
project.ExtraProperties["Path"] = value; |
|||
} |
|||
|
|||
private static void CheckFileSystemProject(Project project) |
|||
{ |
|||
Check.NotNull(project, nameof(project)); |
|||
|
|||
if (project.DocumentStoreType != FileSystemDocumentStore.Type) |
|||
{ |
|||
throw new ApplicationException("Given project has not a FileSystem document store!"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
using Volo.Abp.Http; |
|||
using Volo.Abp.IO; |
|||
using Volo.Docs.Documents; |
|||
|
|||
namespace Volo.Docs.Areas.Documents |
|||
{ |
|||
[RemoteService] |
|||
[Area("docs")] |
|||
[ControllerName("DocumentResource")] |
|||
[Route("document-resources")] |
|||
public class DocumentResourceController : AbpController |
|||
{ |
|||
private readonly IDocumentAppService _documentAppService; |
|||
|
|||
public DocumentResourceController(IDocumentAppService documentAppService) |
|||
{ |
|||
_documentAppService = documentAppService; |
|||
} |
|||
|
|||
[HttpGet] |
|||
[Route("")] |
|||
//[Produces(MimeTypes.Image.Jpeg, MimeTypes.Image.Png, MimeTypes.Image.Gif)]
|
|||
public async Task<FileResult> GetResource(GetDocumentResourceInput input) |
|||
{ |
|||
input.Name = input.Name.RemovePreFix("/"); |
|||
var documentResource = await _documentAppService.GetResourceAsync(input); |
|||
var contentType = MimeTypes.GetByExtension(FileHelper.GetExtension(input.Name)); |
|||
return File(documentResource.Content, contentType); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue