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]] [[package]]
name = "mediarepo-api" name = "mediarepo-api"
version = "0.7.0" version = "0.10.0"
source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=acda7307dc58e9ac489b12bab61561a1cbf951eb#acda7307dc58e9ac489b12bab61561a1cbf951eb" source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=3e8a415a4cf1c04e3e7ccefbcdd56b650ad40c85#3e8a415a4cf1c04e3e7ccefbcdd56b650ad40c85"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"chrono", "chrono",

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

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

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

@ -35,58 +35,6 @@ export class FileService {
this.displayedFiles.next(files); 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> { public async updateFileName(file: File, name: string): Promise<File> {
return await invoke<File>("plugin:mediarepo|update_file_name", {id: file.id, name}) return await invoke<File>("plugin:mediarepo|update_file_name", {id: file.id, name})
} }

Loading…
Cancel
Save