Skip to content

Commit 4903588

Browse files
authored
Merge pull request #339 from decaf-dev/dev
1.44.0
2 parents 7754d3d + 1486646 commit 4903588

File tree

8 files changed

+84
-30
lines changed

8 files changed

+84
-30
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "vault-explorer",
33
"name": "Vault Explorer",
4-
"version": "1.43.1",
4+
"version": "1.44.0",
55
"minAppVersion": "1.4.13",
66
"description": "Explore your vault in visual format",
77
"author": "DecafDev",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-vault-explorer",
3-
"version": "1.43.1",
3+
"version": "1.44.0",
44
"description": "Explore your vault in visual format",
55
"main": "main.js",
66
"scripts": {

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { moveFocus } from "./focus-utils";
1818
import { PluginEvent } from "./event/types";
1919
import { isVersionLessThan } from "./utils";
2020
import License from "./svelte/shared/services/license";
21-
import { clearSocialMediaImageCache } from "./svelte/app/services/social-media-image-cache";
21+
import { clearSMICache } from "./svelte/app/services/smi-cache";
2222
import store from "./svelte/shared/services/store";
2323
import "./styles.css";
2424

@@ -210,7 +210,7 @@ export default class VaultExplorerPlugin extends Plugin {
210210
localStorage.removeItem(LOCAL_STORAGE_LICENSE_KEY);
211211
}
212212
if (isVersionLessThan(loadedVersion, "1.37.1")) {
213-
await clearSocialMediaImageCache();
213+
await clearSMICache();
214214
}
215215
}
216216
}

src/obsidian/vault-explorer-settings-tab.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import ImageSourceApp from "../svelte/image-source-app/index.svelte";
2121
import { PluginEvent } from "src/event/types";
2222

2323
import "./styles.css";
24-
import { clearSocialMediaImageCache } from "src/svelte/app/services/social-media-image-cache";
24+
import { clearSMICache } from "src/svelte/app/services/smi-cache";
2525

2626
export default class VaultExplorerSettingsTab extends PluginSettingTab {
2727
plugin: VaultExplorerPlugin;
@@ -697,7 +697,7 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
697697
.setClass("mod-destructive")
698698
.setButtonText("Clear cache")
699699
.onClick(async () => {
700-
await clearSocialMediaImageCache();
700+
await clearSMICache();
701701
})
702702
);
703703
}

src/obsidian/vault-explorer-view.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default class VaultExplorerView extends ItemView {
1414
super(leaf);
1515
this.component = null;
1616
this.plugin = plugin;
17+
this.navigation = true;
1718
}
1819

1920
getIcon(): string {

src/svelte/app/components/grid-card.svelte

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
import Divider from "src/svelte/shared/components/divider.svelte";
1919
import { fetchSocialMediaImage } from "../services/fetch-social-media-image";
2020
import {
21-
getSocialMediaImageEntry,
22-
isSocialMediaImageEntryExpired,
23-
putSocialMediaImageUrl,
24-
} from "../services/social-media-image-cache";
21+
getSMICacheEntry,
22+
isSMICacheEntryExpired,
23+
putSMICacheEntry,
24+
} from "../services/smi-cache";
2525
import { CoverImageFit } from "src/types";
26+
import Logger from "js-logger";
2627
2728
type SocialMediaImageResult = {
2829
status: "SUCCESS" | "NOT_FOUND" | "EXPIRED" | "NO_IMAGE";
@@ -134,35 +135,62 @@
134135
}
135136
136137
async function handleImageError(event: Event) {
138+
Logger.trace({
139+
fileName: "grid-card.svelte",
140+
functionName: "handleImageError",
141+
message: "called",
142+
});
143+
137144
const target = event.target as HTMLImageElement;
138145
target.onerror = null; // Prevent infinite loop
139146
147+
Logger.debug(
148+
{
149+
fileName: "grid-card.svelte",
150+
functionName: "handleImageError",
151+
message: "target.src",
152+
},
153+
{
154+
src: target.src,
155+
},
156+
);
157+
140158
let websiteUrl = target.src;
141159
if (websiteUrl.endsWith("/")) {
142160
websiteUrl = websiteUrl.slice(0, -1); // Remove the trailing slash
143161
}
162+
Logger.debug(
163+
{
164+
fileName: "grid-card.svelte",
165+
functionName: "handleImageError",
166+
message: "websiteUrl",
167+
},
168+
{
169+
websiteUrl,
170+
},
171+
);
144172
145173
if (loadSocialMediaImage) {
146174
const socialUrl = await fetchSocialMediaImage(websiteUrl);
147175
if (socialUrl) {
148-
await putSocialMediaImageUrl(websiteUrl, socialUrl);
176+
await putSMICacheEntry(websiteUrl, socialUrl);
149177
target.src = socialUrl;
150178
} else {
151-
await putSocialMediaImageUrl(websiteUrl, null);
179+
await putSMICacheEntry(websiteUrl, null);
152180
}
153181
}
154182
}
155183
156184
async function getCachedSocialMediaImageUrl(
157185
websiteUrl: string,
158186
): Promise<SocialMediaImageResult> {
159-
const entry = await getSocialMediaImageEntry(websiteUrl);
187+
const entry = await getSMICacheEntry(websiteUrl);
160188
161189
if (entry) {
162190
const { socialMediaImageUrl } = entry;
163191
164192
if (socialMediaImageUrl) {
165-
const isExpired = await isSocialMediaImageEntryExpired(entry);
193+
const isExpired = await isSMICacheEntryExpired(entry);
166194
if (!isExpired) {
167195
return { status: "SUCCESS", url: socialMediaImageUrl };
168196
} else {
@@ -179,6 +207,17 @@
179207
$: if (imageUrl) {
180208
isImageLoaded = false;
181209
getCachedSocialMediaImageUrl(imageUrl).then((result) => {
210+
Logger.debug(
211+
{
212+
fileName: "grid-card.svelte",
213+
functionName: "getCachedSocialMediaImage",
214+
message: "result",
215+
},
216+
{
217+
result,
218+
},
219+
);
220+
182221
const { status, url } = result;
183222
if (status === "SUCCESS") {
184223
imgSrc = url!;

src/svelte/app/services/social-media-image-cache.ts renamed to src/svelte/app/services/smi-cache.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@ interface SocialMediaImageDB extends DBSchema {
2020
};
2121
}
2222

23-
export const isSocialMediaImageEntryExpired = async (
24-
entry: SocialMediaImageEntry
25-
) => {
23+
export const isSMICacheEntryExpired = async (entry: SocialMediaImageEntry) => {
2624
if (Date.now() - entry.timestamp > ENTRY_EXPIRATION_TIME) {
2725
return true;
2826
}
2927
return false;
3028
};
3129

32-
export const getSocialMediaImageEntry = async (url: string) => {
30+
export const getSMICacheEntry = async (websiteUrl: string) => {
3331
const db = await openDatabase();
34-
const cachedEntry = await db.get(STORE_NAME, url);
32+
const cachedEntry = await db.get(STORE_NAME, websiteUrl);
3533
return cachedEntry ?? null;
3634
};
3735

@@ -40,22 +38,37 @@ export const getSocialMediaImageEntry = async (url: string) => {
4038
* @param url - The URL of the page to cache the social media image for
4139
* @param smiUrl - The URL of the social media image
4240
*/
43-
export const putSocialMediaImageUrl = async (
44-
url: string,
45-
socialMediaImageUrl: string | null
46-
) => {
41+
export const putSMICacheEntry = async (url: string, smiUrl: string | null) => {
42+
Logger.trace({
43+
fileName: "smi-cache.ts",
44+
functionName: "putSMICacheEntry",
45+
message: "called",
46+
});
47+
48+
Logger.debug(
49+
{
50+
fileName: "smi-cache.ts",
51+
functionName: "putSMICacheEntry",
52+
message: "putting entry",
53+
},
54+
{
55+
url,
56+
smiUrl,
57+
}
58+
);
59+
4760
const db = await openDatabase();
4861
await db.put(STORE_NAME, {
4962
url,
50-
socialMediaImageUrl,
63+
socialMediaImageUrl: smiUrl,
5164
timestamp: Date.now(),
5265
});
5366
};
5467

55-
export const clearSocialMediaImageCache = async () => {
68+
export const clearSMICache = async () => {
5669
Logger.trace({
57-
fileName: "social-media-image-cache.ts",
58-
functionName: "clearSocialMediaImageCache",
70+
fileName: "smi-cache.ts",
71+
functionName: "clearSMICache",
5972
message: "called",
6073
});
6174
try {
@@ -67,8 +80,8 @@ export const clearSocialMediaImageCache = async () => {
6780
const error = err as Error;
6881
Logger.error(
6982
{
70-
fileName: "social-media-image-cache.ts",
71-
functionName: "clearSocialMediaImageCache",
83+
fileName: "smi-cache.ts",
84+
functionName: "clearSMICache",
7285
message: "failed to clear cache",
7386
},
7487
error.message

versions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,6 @@
140140
"1.42.0": "1.4.13",
141141
"1.42.1": "1.4.13",
142142
"1.43.0": "1.4.13",
143-
"1.43.1": "1.4.13"
143+
"1.43.1": "1.4.13",
144+
"1.44.0": "1.4.13"
144145
}

0 commit comments

Comments
 (0)