diff --git a/mediarepo-ui/src/app/app.module.ts b/mediarepo-ui/src/app/app.module.ts index 8b1854d..c5a766f 100644 --- a/mediarepo-ui/src/app/app.module.ts +++ b/mediarepo-ui/src/app/app.module.ts @@ -20,6 +20,7 @@ import { FileGridComponent } from './components/file-grid/file-grid.component'; import {MatSidenavModule} from "@angular/material/sidenav"; import {MatGridListModule} from "@angular/material/grid-list"; import { FileGridEntryComponent } from './components/file-grid/file-grid-entry/file-grid-entry.component'; +import {MatProgressBarModule} from "@angular/material/progress-bar"; @NgModule({ declarations: [ @@ -31,21 +32,22 @@ import { FileGridEntryComponent } from './components/file-grid/file-grid-entry/f FileGridComponent, FileGridEntryComponent, ], - imports: [ - BrowserModule, - AppRoutingModule, - BrowserAnimationsModule, - MatCardModule, - MatListModule, - MatButtonModule, - MatToolbarModule, - MatSnackBarModule, - MatFormFieldModule, - MatInputModule, - ReactiveFormsModule, - MatSidenavModule, - MatGridListModule, - ], + imports: [ + BrowserModule, + AppRoutingModule, + BrowserAnimationsModule, + MatCardModule, + MatListModule, + MatButtonModule, + MatToolbarModule, + MatSnackBarModule, + MatFormFieldModule, + MatInputModule, + ReactiveFormsModule, + MatSidenavModule, + MatGridListModule, + MatProgressBarModule, + ], providers: [], bootstrap: [AppComponent] }) diff --git a/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.html b/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.html index 2a71805..92071f6 100644 --- a/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.html +++ b/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.html @@ -1,7 +1,9 @@ {{file?.name}} - - image + + File Image - {{file?.mime_type}}, {{file?.hash}} + + + diff --git a/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.scss b/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.scss index f506f56..b5137b5 100644 --- a/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.scss +++ b/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.scss @@ -1,9 +1,12 @@ -mat-card, mat-card-content { - height: 100%; - width: 100%; +mat-card { + height: calc(100% - 32px); + width: calc(100% - 32px); + padding: 16px; } mat-card-content { + height: 100%; + width: 100%; justify-content: center; text-align: center; } diff --git a/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.ts b/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.ts index 8aca3b5..01d2a13 100644 --- a/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.ts +++ b/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.ts @@ -2,6 +2,7 @@ import {Component, Input, OnInit} from '@angular/core'; import {File} from "../../../models/File"; import {FileService} from "../../../services/file/file.service"; import {ErrorBrokerService} from "../../../services/error-broker/error-broker.service"; +import {SafeResourceUrl} from "@angular/platform-browser"; @Component({ selector: 'app-file-grid-entry', @@ -11,7 +12,7 @@ import {ErrorBrokerService} from "../../../services/error-broker/error-broker.se export class FileGridEntryComponent implements OnInit { @Input() file: File | undefined; - contentUrl: string | undefined; + contentUrl: SafeResourceUrl | undefined; constructor(private fileService: FileService, private errorBroker: ErrorBrokerService) { } async ngOnInit(): Promise { diff --git a/mediarepo-ui/src/app/components/file-grid/file-grid.component.html b/mediarepo-ui/src/app/components/file-grid/file-grid.component.html index b86611e..dc94919 100644 --- a/mediarepo-ui/src/app/components/file-grid/file-grid.component.html +++ b/mediarepo-ui/src/app/components/file-grid/file-grid.component.html @@ -1,4 +1,4 @@ - + diff --git a/mediarepo-ui/src/app/pages/home/home.component.scss b/mediarepo-ui/src/app/pages/home/home.component.scss index 919cc8b..9477b83 100644 --- a/mediarepo-ui/src/app/pages/home/home.component.scss +++ b/mediarepo-ui/src/app/pages/home/home.component.scss @@ -21,3 +21,7 @@ mat-drawer-content { mat-drawer-container { height: 100%; } + +app-file-grid { + padding: 1em; +} diff --git a/mediarepo-ui/src/app/services/file/file.service.ts b/mediarepo-ui/src/app/services/file/file.service.ts index 8e1035c..1400beb 100644 --- a/mediarepo-ui/src/app/services/file/file.service.ts +++ b/mediarepo-ui/src/app/services/file/file.service.ts @@ -1,8 +1,9 @@ -import {Inject, Injectable} from '@angular/core'; +import {Inject, Injectable, Sanitizer} from '@angular/core'; import {BehaviorSubject} from "rxjs"; import {File} from "../../models/File"; import {invoke} from "@tauri-apps/api/tauri"; import {DOCUMENT} from "@angular/common"; +import {DomSanitizer, SafeResourceUrl} from "@angular/platform-browser"; @Injectable({ providedIn: 'root' @@ -11,29 +12,20 @@ export class FileService { displayedFiles = new BehaviorSubject([]); - constructor(@Inject(DOCUMENT) private document: Document) { + constructor(@Inject(DomSanitizer) private sanitizer: DomSanitizer) { } public async getFiles() { let all_files = await invoke("get_all_files"); - this.displayedFiles.next(all_files.slice(0, 50)); + this.displayedFiles.next(all_files.slice(70, 100)); } - public async readFile(hash: string, mime_type: string): Promise { + public async readFile(hash: string, mime_type: string): Promise { const data = await invoke("read_file_by_hash", {hash}); const blob = new Blob([new Uint8Array(data)], {type: mime_type}); - return new Promise((res, rej) => { - const reader = new FileReader(); - reader.onload = (e) => { - const url = e.target?.result - if (url === null) { - res(undefined); - } else { - res(url as string) - } - }; - reader.readAsDataURL(blob); - }) + + const url = URL?.createObjectURL(blob); + return this.sanitizer.bypassSecurityTrustResourceUrl(url); } }