You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
3 years ago
|
import {
|
||
3 years ago
|
Component,
|
||
|
Input,
|
||
|
OnChanges,
|
||
|
OnInit,
|
||
|
SimpleChanges
|
||
|
} from "@angular/core";
|
||
3 years ago
|
import {File} from "../../../../models/File";
|
||
|
import {FileService} from "../../../../services/file/file.service";
|
||
|
import {FileHelper} from "../../../../services/file/file.helper";
|
||
3 years ago
|
import {SafeResourceUrl} from "@angular/platform-browser";
|
||
|
|
||
|
@Component({
|
||
3 years ago
|
selector: "app-file-thumbnail",
|
||
|
templateUrl: "./file-thumbnail.component.html",
|
||
|
styleUrls: ["./file-thumbnail.component.scss"]
|
||
3 years ago
|
})
|
||
|
export class FileThumbnailComponent implements OnInit, OnChanges {
|
||
|
|
||
3 years ago
|
@Input() file!: File;
|
||
3 years ago
|
|
||
3 years ago
|
public thumbUrl: SafeResourceUrl | undefined;
|
||
3 years ago
|
|
||
3 years ago
|
private supportedThumbnailTypes = ["image", "video"]
|
||
3 years ago
|
|
||
3 years ago
|
constructor(private fileService: FileService) {
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
public ngOnInit(): void {
|
||
|
this.thumbUrl = this.fileService.buildThumbnailUrl(this.file, 250, 250);
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
public ngOnChanges(changes: SimpleChanges): void {
|
||
|
if (changes["file"]) {
|
||
|
this.thumbUrl = this.fileService.buildThumbnailUrl(this.file, 250,
|
||
|
250)
|
||
|
}
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
public getThumbnailSupported(): boolean {
|
||
|
const mimeParts = FileHelper.parseMime(this.file.mime_type);
|
||
3 years ago
|
|
||
3 years ago
|
return !!mimeParts && this.supportedThumbnailTypes.includes(
|
||
|
mimeParts[0]);
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
public getFileType(): string {
|
||
|
const mimeParts = FileHelper.parseMime(this.file.mime_type);
|
||
|
return (mimeParts && mimeParts[0]) ?? "other";
|
||
|
}
|
||
3 years ago
|
}
|