Skip to content

Commit

Permalink
Merge pull request #55 from skni-kod/refactor/#54-refactor-file-storage
Browse files Browse the repository at this point in the history
refactor file storage
  • Loading branch information
Comply5000 authored Feb 9, 2024
2 parents 24da3d4 + fedcae1 commit dbbed80
Show file tree
Hide file tree
Showing 10 changed files with 821 additions and 19 deletions.
14 changes: 2 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
context: .
dockerfile: Dockerfile
depends_on:
- createBucket
- db
ports:
- '5000:80'

Expand Down Expand Up @@ -35,17 +35,7 @@ services:
- MINIO_ROOT_USER=admin
- MINIO_ROOT_PASSWORD=1qazXSW@
command: server --console-address ":9001" --address ":9000" /data

createBucket:
image: minio/mc
depends_on:
- db
entrypoint: >
/bin/sh -c "
/usr/bin/mc alias set myminio http://minio:9000 admin 1qazXSW@;
/usr/bin/mc mb myminio/skit;
exit 0;"

volumes:
minio_data:
driver: local
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task<UploadFileResponse> Handle(UploadFileCommand request, Cancella
{
var s3Key = await _s3StorageService.UploadFileAsync(request.File, cancellationToken);

var file = SystemFile.Create(request.File.FileName, request.Type, request.File.Length, s3Key);
var file = SystemFile.Create(request.File.FileName, request.Type, request.File.Length, s3Key, request.File.ContentType);

var result = await _fileRepository.AddAsync(file, cancellationToken);

Expand Down
2 changes: 1 addition & 1 deletion skit.Application/Files/Queries/GetFile/GetFileResponse.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace skit.Application.Files.Queries.GetFile;

public sealed record GetFileResponse(string FileUrl);
public sealed record GetFileResponse(MemoryStream Content, string ContentType, string FileName);
8 changes: 5 additions & 3 deletions skit.Core/Files/Entities/SystemFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ public sealed class SystemFile : Entity
public FileType Type { get; private set; }
public long Size { get; private set; }
public string S3Key { get; private set; }
public string ContentType { get; private set; }

private SystemFile() { }

private SystemFile(string name, FileType type, long size, string s3Key)
private SystemFile(string name, FileType type, long size, string s3Key, string contentType)
{
Name = name;
Type = type;
Size = size;
S3Key = s3Key;
ContentType = contentType;
}

public static SystemFile Create(string name, FileType type, long size, string s3Key)
=> new(name, type, size, s3Key);
public static SystemFile Create(string name, FileType type, long size, string s3Key, string contentType)
=> new(name, type, size, s3Key, contentType);
}
1 change: 1 addition & 0 deletions skit.Core/Files/Services/IS3StorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public interface IS3StorageService
{
Task<string> UploadFileAsync(IFormFile file, CancellationToken cancellationToken);
string GetFileUrl(string fileKey, string fileName);
Task<MemoryStream> GetFileAsync(string fileKey, CancellationToken cancellationToken);
}
Loading

0 comments on commit dbbed80

Please sign in to comment.