Skip to content

Commit 838a6c7

Browse files
committed
fix: video conversion e.get error (#215)
not entirely sure because i can't reproduce it, but this seems like the only logical reason this could be happening
1 parent 5088040 commit 838a6c7

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

src/lib/converters/vertd.svelte.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,15 @@ export class VertdConverter extends Converter {
290290
}
291291

292292
private blocked(hash: string): boolean {
293-
const blockedHashes = Settings.instance.settings.vertdBlockedHashes;
293+
let blockedHashes = Settings.instance.settings.vertdBlockedHashes;
294+
295+
// ensure it's a map
296+
// this might fix the "e.get" isn't a function error, but i can't reproduce it
297+
if (!(blockedHashes instanceof Map) || blockedHashes === null) {
298+
blockedHashes = new Map(Object.entries(blockedHashes || {}));
299+
Settings.instance.settings.vertdBlockedHashes = blockedHashes;
300+
Settings.instance.save();
301+
}
294302

295303
const now = new Date();
296304
const dates = blockedHashes.get(hash) || [];
@@ -311,7 +319,15 @@ export class VertdConverter extends Converter {
311319
}
312320

313321
private failure(hash: string): void {
314-
const blockedHashes = Settings.instance.settings.vertdBlockedHashes;
322+
let blockedHashes = Settings.instance.settings.vertdBlockedHashes;
323+
324+
// same as above (blocked())
325+
if (!(blockedHashes instanceof Map) || blockedHashes === null) {
326+
blockedHashes = new Map(Object.entries(blockedHashes || {}));
327+
Settings.instance.settings.vertdBlockedHashes = blockedHashes;
328+
Settings.instance.save();
329+
}
330+
315331
const now = new Date();
316332
const dates = blockedHashes.get(hash) || [];
317333
dates.push(now);

src/lib/sections/settings/index.svelte.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,26 @@ export class Settings {
6060
}
6161

6262
public load() {
63-
VertdInstance.instance.load();
64-
const ls = localStorage.getItem("settings");
65-
if (!ls) return;
66-
const settings: ISettings = JSON.parse(ls);
67-
const vertdBlockedHashes = new Map<string, Date[]>(
68-
Object.entries(
69-
settings.vertdBlockedHashes || this.settings.vertdBlockedHashes,
70-
),
71-
);
63+
try {
64+
VertdInstance.instance.load();
65+
const ls = localStorage.getItem("settings");
66+
if (!ls) return;
67+
const settings: ISettings = JSON.parse(ls);
68+
const vertdBlockedHashes = new Map<string, Date[]>(
69+
Object.entries(
70+
settings.vertdBlockedHashes ||
71+
this.settings.vertdBlockedHashes,
72+
),
73+
);
7274

73-
settings.vertdBlockedHashes = vertdBlockedHashes;
75+
settings.vertdBlockedHashes = vertdBlockedHashes;
7476

75-
this.settings = {
76-
...this.settings,
77-
...settings,
78-
};
77+
this.settings = {
78+
...this.settings,
79+
...settings,
80+
};
81+
} catch {
82+
// ignore errors, use default settings
83+
}
7984
}
8085
}

0 commit comments

Comments
 (0)