Add file size to file metadata

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/14/head
trivernis 3 years ago
parent fd1d3e128c
commit 6e150a3701
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,6 +1,6 @@
[package]
name = "mediarepo-api"
version = "0.30.0"
version = "0.31.0"
edition = "2018"
license = "gpl-3"

@ -58,6 +58,7 @@ pub struct FileMetadataResponse {
pub creation_time: NaiveDateTime,
pub change_time: NaiveDateTime,
pub import_time: NaiveDateTime,
pub size: u64,
}
#[derive(Clone, Debug, Serialize, Deserialize)]

@ -23,6 +23,7 @@ impl FromModel<FileMetadataDto> for FileMetadataResponse {
creation_time: model.creation_time().to_owned(),
change_time: model.change_time().to_owned(),
import_time: model.import_time().to_owned(),
size: model.size() as u64,
}
}
}

@ -68,9 +68,10 @@ export type FileMetadata = {
file_id: number,
name?: string,
comment?: string,
creation_time: Date,
change_time: Date,
import_time: Date,
creation_time: string,
change_time: string,
import_time: string,
size: number,
};
export type FileOsMetadata = {

@ -24,6 +24,7 @@ import {FlexLayoutModule} from "@angular/flex-layout";
import {MatRippleModule} from "@angular/material/core";
import {FlapButtonComponent} from "./flap-button/flap-button.component";
import {MiddleCenteredComponent} from "./middle-centered/middle-centered.component";
import {FormatBytesPipe} from "./pipes/format-bytes.pipe";
@NgModule({
@ -42,6 +43,7 @@ import {MiddleCenteredComponent} from "./middle-centered/middle-centered.compone
DrawerPageContentComponent,
FlapButtonComponent,
MiddleCenteredComponent,
FormatBytesPipe,
],
exports: [
ConfirmDialogComponent,
@ -57,6 +59,7 @@ import {MiddleCenteredComponent} from "./middle-centered/middle-centered.compone
DrawerPageContentComponent,
FlapButtonComponent,
MiddleCenteredComponent,
FormatBytesPipe,
],
imports: [
CommonModule,

@ -0,0 +1,8 @@
import {FormatBytesPipe} from "./format-bytes.pipe";
describe("FormatBytesPipe", () => {
it("create an instance", () => {
const pipe = new FormatBytesPipe();
expect(pipe).toBeTruthy();
});
});

@ -0,0 +1,24 @@
import {Pipe, PipeTransform} from "@angular/core";
@Pipe({
name: "formatBytes"
})
export class FormatBytesPipe implements PipeTransform {
static round(number: number, decimals: number) {
return Math.round(number * (10 ** decimals)) / (10 ** decimals);
}
transform(value: number): string {
const units = ["B", "KiB", "MiB", "GiB"];
let formattedValue = value;
for (const unit of units) {
if (formattedValue < 1000) {
return `${formattedValue} ${unit}`;
}
formattedValue = FormatBytesPipe.round(formattedValue / 1024, 2);
}
return formattedValue + " GiB";
}
}

@ -12,12 +12,17 @@
attributeName="Name"></app-editable-metadata-entry>
<app-metadata-entry attributeName="Content Descriptor (CD)">{{file.cd}}</app-metadata-entry>
<app-metadata-entry attributeName="Mime Type">{{file.mimeType}}</app-metadata-entry>
<app-metadata-entry *ngIf="fileMetadata"
attributeName="Imported at">{{fileMetadata.import_time.toLocaleString()}}</app-metadata-entry>
<app-metadata-entry *ngIf="fileMetadata"
attributeName="Created at">{{fileMetadata.creation_time.toLocaleString()}}</app-metadata-entry>
<app-metadata-entry *ngIf="fileMetadata"
attributeName="Changed at">{{fileMetadata.change_time.toLocaleString()}}</app-metadata-entry>
<ng-container *ngIf="fileMetadata">
<app-metadata-entry
attributeName="Size">{{fileMetadata.size | formatBytes}}</app-metadata-entry>
<app-metadata-entry
attributeName="Imported at">{{fileMetadata.import_time | date: 'dd.MM.yy HH:mm:ss' }}</app-metadata-entry>
<app-metadata-entry
attributeName="Created at">{{fileMetadata.creation_time | date: 'dd.MM.yy HH:mm:ss'}}</app-metadata-entry>
<app-metadata-entry
attributeName="Changed at">{{fileMetadata.change_time | date: 'dd.MM.yy HH:mm:ss'}}</app-metadata-entry>
</ng-container>
</div>
</div>
</app-busy-indicator>

Loading…
Cancel
Save