Update plugin

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 3ae96ff98a
commit df9dec296d

@ -1580,8 +1580,8 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]]
name = "mediarepo-api"
version = "0.7.0"
source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=acda7307dc58e9ac489b12bab61561a1cbf951eb#acda7307dc58e9ac489b12bab61561a1cbf951eb"
version = "0.10.0"
source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=3e8a415a4cf1c04e3e7ccefbcdd56b650ad40c85#3e8a415a4cf1c04e3e7ccefbcdd56b650ad40c85"
dependencies = [
"async-trait",
"chrono",

@ -30,7 +30,7 @@ features = ["env-filter"]
[dependencies.mediarepo-api]
git = "https://github.com/Trivernis/mediarepo-api.git"
rev = "acda7307dc58e9ac489b12bab61561a1cbf951eb"
rev = "3e8a415a4cf1c04e3e7ccefbcdd56b650ad40c85"
features = ["tauri-plugin"]
[features]

@ -45,6 +45,6 @@ export class FileGalleryEntryComponent implements OnInit, OnChanges {
private setImageDelayed() {
this.contentUrl = undefined;
clearTimeout(this.urlSetTimeout);
this.urlSetTimeout = setTimeout(() => this.contentUrl = this.fileService.buildThumbnailUrl(this.file.data, 250, 250), 500);
this.urlSetTimeout = setTimeout(() => this.contentUrl = this.fileService.buildThumbnailUrl(this.file.data, 250, 250), 200);
}
}

@ -50,6 +50,6 @@ export class FileGridEntryComponent implements OnInit, OnChanges {
this.contentUrl = undefined;
clearTimeout(this.urlSetTimeout);
this.urlSetTimeout = setTimeout(() => this.contentUrl = this.fileService.buildThumbnailUrl(this.gridEntry.file,
250, 250), 500);
250, 250), 200);
}
}

@ -1,5 +1,5 @@
export type Thumbnail = {
hash: string,
file_hash: string,
height: number,
width: number,
mime_type: string | undefined

@ -35,58 +35,6 @@ export class FileService {
this.displayedFiles.next(files);
}
public async readFile(file: File): Promise<SafeResourceUrl> {
const once_uri = await invoke<string>("plugin:mediarepo|read_file_by_hash",
{id: file.id, hash: file.hash, mimeType: file.mime_type});
return this.sanitizer.bypassSecurityTrustResourceUrl(once_uri);
}
/**
* Returns the thumbnail for a file with a specific size (allowing +-10%)
* If none can be found it asks the backend if it has one or generates one of that size
* @param {File} file
* @param {number} width
* @param {number} height
* @returns {Promise<SafeResourceUrl>}
*/
public async getFileThumbnail(file: File, width: number, height: number): Promise<SafeResourceUrl> {
const thumbnails = await this.getThumbnails(file);
const thumbnail = thumbnails.find(t => t.height >= height * 0.7 && t.width >= width * 0.7 && t.height <= height * 1.3 && t.width <= width * 1.3);
let url;
if (thumbnail) {
url = await this.readThumbnail(thumbnail);
} else {
url = await this.getThumbnailOfSize(file, height * 0.9, width * 0.9, height * 1.1, width * 1.1);
delete this.thumbnailCache[file.id];
}
return url;
}
public async readThumbnail(thumbnail: Thumbnail): Promise<SafeResourceUrl> {
let once_uri = await invoke<string>("plugin:mediarepo|read_thumbnail",
{hash: thumbnail.hash, mimeType: thumbnail.mime_type});
return this.sanitizer.bypassSecurityTrustResourceUrl(once_uri);
}
public async getThumbnailOfSize(file: File, minHeight: number, minWidth: number, maxHeight: number, maxWidth: number): Promise<SafeResourceUrl> {
let once_uri = await invoke<string>("plugin:mediarepo|get_thumbnail_of_size", {fileId: file.id, minSize: [minHeight, minWidth], maxSize: [maxHeight, maxWidth]});
return this.sanitizer.bypassSecurityTrustResourceUrl(once_uri);
}
public async getThumbnails(file: File): Promise<Thumbnail[]> {
const cachedThumbnails = this.thumbnailCache[file.id];
if (cachedThumbnails) {
return cachedThumbnails;
}
const thumbnails = await invoke<Thumbnail[]>("plugin:mediarepo|get_file_thumbnails",
{id: file.id});
this.thumbnailCache[file.id] = thumbnails;
return thumbnails;
}
public async updateFileName(file: File, name: string): Promise<File> {
return await invoke<File>("plugin:mediarepo|update_file_name", {id: file.id, name})
}

Loading…
Cancel
Save