Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add information about file size #40

Merged
merged 6 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<Unit> Handle(UploadChunks command, CancellationToken cancellat
await _fileService.MergeFiles(persisted.Id, savedChunks, chunk.ChunkDirectory);


persisted.AddFile(new SecureSendFile(chunk.Chunk.FileName, chunk.ContentType));
persisted.AddFile(new SecureSendFile(chunk.Chunk.FileName, chunk.ContentType, chunk.Chunk.Length));
await _repository.SaveChanges(cancellationToken);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
{
SecureUploadId = upload.Id,
UploadDate = upload.UploadDate,
ExpiryDate = upload.ExpiryDate,

Check warning on line 28 in SecureSend.Application/Commands/Handlers/ViewSecureUploadHandler.cs

View workflow job for this annotation

GitHub Actions / build-ubuntu-latest

Possible null reference argument for parameter 'secureSendExpiryDate' in 'SecureSendExpiryDate.implicit operator DateTime?(SecureSendExpiryDate secureSendExpiryDate)'.

Check warning on line 28 in SecureSend.Application/Commands/Handlers/ViewSecureUploadHandler.cs

View workflow job for this annotation

GitHub Actions / build-windows-latest

Possible null reference argument for parameter 'secureSendExpiryDate' in 'SecureSendExpiryDate.implicit operator DateTime?(SecureSendExpiryDate secureSendExpiryDate)'.

Check warning on line 28 in SecureSend.Application/Commands/Handlers/ViewSecureUploadHandler.cs

View workflow job for this annotation

GitHub Actions / build-macOS-latest

Possible null reference argument for parameter 'secureSendExpiryDate' in 'SecureSendExpiryDate.implicit operator DateTime?(SecureSendExpiryDate secureSendExpiryDate)'.
Files = upload.Files.Select(f => new SecureFileDto { ContentType = f.ContentType, FileName = f.FileName })
Files = upload.Files.Select(f => new SecureFileDto { ContentType = f.ContentType, FileName = f.FileName, FileSize = f.FileSize})

};

Expand Down
1 change: 1 addition & 0 deletions SecureSend.Application/DTO/SecureUploadDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public class SecureFileDto
{
public string? FileName { get; set; }
public string? ContentType { get; set; }
public long FileSize { get; set; }
}
}
4 changes: 3 additions & 1 deletion SecureSend.Domain/ValueObjects/SecureSendFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ public record SecureSendFile
{
public string FileName { get; }
public string ContentType { get; }
public long FileSize { get; set; }

public SecureSendFile(string fileName, string contentType)
public SecureSendFile(string fileName, string contentType, long fileSize)
{
if (string.IsNullOrEmpty(fileName)) throw new EmptyFileNameException();
FileName = fileName;
ContentType = contentType;
FileSize = fileSize;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void Configure(EntityTypeBuilder<SecureSendUpload> builder)
fileBuilder.HasKey("Id");
fileBuilder.Property(p => p.FileName);
fileBuilder.Property(p => p.ContentType);
fileBuilder.Property(p => p.FileSize);

fileBuilder.ToTable("UploadedFiles");

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace SecureSend.PostgresMigrations.Migrations
{
/// <inheritdoc />
public partial class AddFileSize : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<long>(
name: "FileSize",
schema: "upload",
table: "UploadedFiles",
type: "bigint",
nullable: false,
defaultValue: 0L);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "FileSize",
schema: "upload",
table: "UploadedFiles");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.IsRequired()
.HasColumnType("text");

b1.Property<long>("FileSize")
.HasColumnType("bigint");

b1.Property<Guid>("SecureSendUploadId")
.HasColumnType("uuid");

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace SecureSend.SqlServerMigration.Migrations
{
/// <inheritdoc />
public partial class AddFileSize : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<long>(
name: "FileSize",
schema: "upload",
table: "UploadedFiles",
type: "bigint",
nullable: false,
defaultValue: 0L);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "FileSize",
schema: "upload",
table: "UploadedFiles");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.IsRequired()
.HasColumnType("nvarchar(max)");

b1.Property<long>("FileSize")
.HasColumnType("bigint");

b1.Property<Guid>("SecureSendUploadId")
.HasColumnType("uniqueidentifier");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CancelUploadHandlerTests()
[Fact]
public async void Handle_Succeeds()
{
upload.AddFile(new SecureSendFile("test.txt", "text/plain"));
upload.AddFile(new SecureSendFile("test.txt", "text/plain", new long()));
var command = new CancelUpload(Guid.NewGuid(), "test.txt");
_repository.Setup(x => x.GetAsync(command.id, It.IsAny<CancellationToken>()))
.ReturnsAsync(upload);
Expand Down
10 changes: 5 additions & 5 deletions SecureSend.Test/Domain/SecureSendUploadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SecureSendUploadTests()
[Fact]
public void AddFile_Succeeds()
{
upload.AddFile(new SecureSendFile("test_file", "application/octet-stream"));
upload.AddFile(new SecureSendFile("test_file", "application/octet-stream", new long()));
Assert.Single(upload.Files);
}

Expand All @@ -33,7 +33,7 @@ public void AddMultipleFiles_Succeeds()
IList<SecureSendFile> files = new List<SecureSendFile>();
for (int i = 0; i < 5; i++)
{
files.Add(new SecureSendFile($"{i}_test_file", "application/octet-stream"));
files.Add(new SecureSendFile($"{i}_test_file", "application/octet-stream", new long()));
}
upload.AddMultipleFiles(files);
Assert.Collection(upload.Files,
Expand All @@ -48,8 +48,8 @@ public void AddMultipleFiles_Succeeds()
[Fact]
public void AddFile_Throws_FileAlreadyExistsException()
{
upload.AddFile(new SecureSendFile("test_file", "application/octet-stream"));
var exception = Record.Exception(() => upload.AddFile(new SecureSendFile("test_file", "application/octet-stream")));
upload.AddFile(new SecureSendFile("test_file", "application/octet-stream", new long()));
var exception = Record.Exception(() => upload.AddFile(new SecureSendFile("test_file", "application/octet-stream", new long())));
Assert.NotNull(exception);
Assert.IsType<FileAlreadyExistsException>(exception);
}
Expand All @@ -58,7 +58,7 @@ public void AddFile_Throws_FileAlreadyExistsException()
public void RemoveFile_Succeeds()
{

upload.AddFile(new SecureSendFile("test_file", "application/octet-stream"));
upload.AddFile(new SecureSendFile("test_file", "application/octet-stream", new long()));
Assert.Single(upload.Files);
upload.RemoveFile("test_file");
Assert.Empty(upload.Files);
Expand Down
1 change: 1 addition & 0 deletions SecureSend/ClientApp/src/models/SecureFileDto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface SecureFileDto {
fileName: string | null;
contentType: string | null;
fileSize: number;
}
1 change: 1 addition & 0 deletions SecureSend/ClientApp/src/views/FileDownloadView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const isPasswordValidComputed = computed(
v-for="file in secureUpload.files"
:key="(file.fileName as string)"
:file-name="file.fileName!"
:size="file.fileSize"
>
<template #cardBottom>
<a
Expand Down
2 changes: 1 addition & 1 deletion SecureSend/ClientApp/src/views/LandingView.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div
class="max-w-5xl mx-auto pt-20 sm:pt-24 lg:pt-32 flex flex-col gap-4 items-center"
class="max-w-5xl mx-auto lg:pt-52 pt-32 flex flex-col gap-4 items-center h-screen w-[90%] md:w-full"
>
<h1
class="font-extrabold text-4xl sm:text-5xl lg:text-6xl tracking-tight text-center"
Expand Down
Loading