Skip to content

Commit

Permalink
Merge pull request #340 from decaf-dev/dev
Browse files Browse the repository at this point in the history
1.44.1
  • Loading branch information
decaf-dev authored Sep 11, 2024
2 parents 4903588 + cf84535 commit 245da7c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "vault-explorer",
"name": "Vault Explorer",
"version": "1.44.0",
"version": "1.44.1",
"minAppVersion": "1.4.13",
"description": "Explore your vault in visual format",
"author": "DecafDev",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-vault-explorer",
"version": "1.44.0",
"version": "1.44.1",
"description": "Explore your vault in visual format",
"main": "main.js",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ export default class VaultExplorerPlugin extends Plugin {
localStorage.removeItem(LOCAL_STORAGE_LICENSE_KEY);
}
if (isVersionLessThan(loadedVersion, "1.37.1")) {
console.log("Clearing image cache");
await clearSMICache();
}
if (isVersionLessThan(loadedVersion, "1.44.1")) {
//socialMediaImageUrl -> smiUrl
console.log("Clearing image cache");
await clearSMICache();
}
}
Expand Down
24 changes: 15 additions & 9 deletions src/svelte/app/components/grid-card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
type SocialMediaImageResult = {
status: "SUCCESS" | "NOT_FOUND" | "EXPIRED" | "NO_IMAGE";
url?: string; // Only present when status is 'SUCCESS'
websiteUrl: string;
smiUrl: string | null;
};
export let displayName: string;
Expand Down Expand Up @@ -184,24 +185,29 @@
async function getCachedSocialMediaImageUrl(
websiteUrl: string,
): Promise<SocialMediaImageResult> {
Logger.trace({
fileName: "grid-card.svelte",
functionName: "getCachedSocialMediaUrl",
message: "result",
});
const entry = await getSMICacheEntry(websiteUrl);
if (entry) {
const { socialMediaImageUrl } = entry;
const { smiUrl } = entry;
if (socialMediaImageUrl) {
if (smiUrl) {
const isExpired = await isSMICacheEntryExpired(entry);
if (!isExpired) {
return { status: "SUCCESS", url: socialMediaImageUrl };
return { status: "SUCCESS", websiteUrl, smiUrl };
} else {
return { status: "EXPIRED" }; // Image found but expired
return { status: "EXPIRED", websiteUrl, smiUrl }; // Image found but expired
}
} else {
return { status: "NO_IMAGE" }; // Social image was fetched but doesn't exist
return { status: "NO_IMAGE", websiteUrl, smiUrl }; // Image was previously cached but doesn't exist
}
}
return { status: "NOT_FOUND" }; // Image not cached
return { status: "NOT_FOUND", websiteUrl, smiUrl: null }; // Website URL doesn't have a cached image
}
$: if (imageUrl) {
Expand All @@ -218,9 +224,9 @@
},
);
const { status, url } = result;
const { status, smiUrl } = result;
if (status === "SUCCESS") {
imgSrc = url!;
imgSrc = smiUrl;
} else if (status === "EXPIRED" || status === "NOT_FOUND") {
imgSrc = imageUrl;
} else if (status === "NO_IMAGE") {
Expand Down
22 changes: 19 additions & 3 deletions src/svelte/app/services/smi-cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DBSchema, IDBPDatabase, openDB } from "idb";
import { DBSchema, openDB } from "idb";
import Logger from "js-logger";
import { Notice } from "obsidian";

Expand All @@ -9,7 +9,7 @@ const ENTRY_EXPIRATION_TIME = ONE_WEEK_MILLIS;

interface SocialMediaImageEntry {
url: string;
socialMediaImageUrl: string | null; // null if no social media image found
smiUrl: string | null; // null if no social media image found
timestamp: number;
}

Expand All @@ -28,6 +28,22 @@ export const isSMICacheEntryExpired = async (entry: SocialMediaImageEntry) => {
};

export const getSMICacheEntry = async (websiteUrl: string) => {
Logger.trace({
fileName: "smi-cache.ts",
functionName: "getSMICacheEntry",
message: "called",
});

Logger.debug(
{
fileName: "grid-card.svelte",
functionName: "getCachedSocialMediaUrl",
message: "getting cached entry",
},
{
websiteUrl,
}
);
const db = await openDatabase();
const cachedEntry = await db.get(STORE_NAME, websiteUrl);
return cachedEntry ?? null;
Expand Down Expand Up @@ -60,7 +76,7 @@ export const putSMICacheEntry = async (url: string, smiUrl: string | null) => {
const db = await openDatabase();
await db.put(STORE_NAME, {
url,
socialMediaImageUrl: smiUrl,
smiUrl,
timestamp: Date.now(),
});
};
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,6 @@
"1.42.1": "1.4.13",
"1.43.0": "1.4.13",
"1.43.1": "1.4.13",
"1.44.0": "1.4.13"
"1.44.0": "1.4.13",
"1.44.1": "1.4.13"
}

0 comments on commit 245da7c

Please sign in to comment.