summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-05 18:09:34 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-05 18:09:34 +1100
commit7ace0bf1a2d94f3f60b4a99d1f3bced2f22009ad (patch)
treec011fa7b5991214886c8eff09edafe4322b3e53b
parentlauncher: fix wallpaper categories (diff)
downloadcaelestia-shell-7ace0bf1a2d94f3f60b4a99d1f3bced2f22009ad.tar.gz
caelestia-shell-7ace0bf1a2d94f3f60b4a99d1f3bced2f22009ad.tar.bz2
caelestia-shell-7ace0bf1a2d94f3f60b4a99d1f3bced2f22009ad.zip
thumbnailer: use sha1sum for caching
-rw-r--r--src/utils/thumbnailer.ts10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/utils/thumbnailer.ts b/src/utils/thumbnailer.ts
index ab1c900..8a879b0 100644
--- a/src/utils/thumbnailer.ts
+++ b/src/utils/thumbnailer.ts
@@ -1,5 +1,4 @@
import { execAsync, Gio, GLib } from "astal";
-import { pathToFileName } from "./strings";
export interface ThumbOpts {
width?: number;
@@ -25,10 +24,11 @@ export default class Thumbnailer {
return opts[opt] ?? this.defaults[opt];
}
- static getThumbPath(path: string, opts: ThumbOpts) {
+ static async getThumbPath(path: string, opts: ThumbOpts) {
+ const hash = (await execAsync(`sha1sum ${path}`)).split(" ")[0];
const size = `${this.getOpt("width", opts)}x${this.getOpt("height", opts)}`;
const exact = this.getOpt("exact", opts) ? "-exact" : "";
- return `${this.thumbnailDir}/${pathToFileName(path, "")}@${size}${exact}.png`;
+ return `${this.thumbnailDir}/${hash}@${size}${exact}.png`;
}
static async shouldThumbnail(path: string, opts: ThumbOpts) {
@@ -37,7 +37,7 @@ export default class Thumbnailer {
}
static async #thumbnail(path: string, opts: ThumbOpts, attempts: number): Promise<string> {
- const thumbPath = this.getThumbPath(path, opts);
+ const thumbPath = await this.getThumbPath(path, opts);
try {
const width = this.getOpt("width", opts);
@@ -60,7 +60,7 @@ export default class Thumbnailer {
static async thumbnail(path: string, opts: ThumbOpts = {}): Promise<string> {
if (!(await this.shouldThumbnail(path, opts))) return path;
- let thumbPath = this.getThumbPath(path, opts);
+ let thumbPath = await this.getThumbPath(path, opts);
// If not lazy (i.e. force gen), delete existing thumbnail
if (!this.lazy) Gio.File.new_for_path(thumbPath).delete(null);