mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-02 19:02:28 +00:00
Fix watch history session actor initialization
This commit is contained in:
1 parent
cd96e3a2b4
commit
1e3da7aebc
3 files changed
+102
-9
No files matched your search
+26
-2
@@ -200,8 +200,32 @@
|
||||
<!-- Additional Scripts -->
|
||||
<script src="js/libs/nostr.bundle.js"></script>
|
||||
<script type="module">
|
||||
import { nip19, SimplePool } from "https://esm.sh/[email protected]";
|
||||
window.NostrTools = { nip19, SimplePool };
|
||||
import * as nostrTools from "https://esm.sh/[email protected]";
|
||||
|
||||
const existing =
|
||||
typeof window !== "undefined" &&
|
||||
window.NostrTools &&
|
||||
typeof window.NostrTools === "object"
|
||||
? window.NostrTools
|
||||
: {};
|
||||
|
||||
const merged = { ...existing, ...nostrTools };
|
||||
|
||||
if (
|
||||
!merged.generatePrivateKey &&
|
||||
typeof merged.generateSecretKey === "function"
|
||||
) {
|
||||
merged.generatePrivateKey = merged.generateSecretKey.bind(merged);
|
||||
}
|
||||
|
||||
if (
|
||||
!merged.generateSecretKey &&
|
||||
typeof merged.generatePrivateKey === "function"
|
||||
) {
|
||||
merged.generateSecretKey = merged.generatePrivateKey.bind(merged);
|
||||
}
|
||||
|
||||
window.NostrTools = merged;
|
||||
</script>
|
||||
<script type="module" src="js/config.js"></script>
|
||||
<script type="module" src="js/lists.js"></script>
|
||||
|
||||
@@ -378,7 +378,6 @@ function handleHashChange() {
|
||||
if (typeof initFn === "function") {
|
||||
initFn();
|
||||
}
|
||||
recordView("most-recent-videos");
|
||||
});
|
||||
});
|
||||
return;
|
||||
|
||||
+76
-6
@@ -979,10 +979,19 @@ class NostrClient {
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!window?.NostrTools?.generatePrivateKey ||
|
||||
typeof window.NostrTools.getPublicKey !== "function"
|
||||
) {
|
||||
const nostrTools = window?.NostrTools || {};
|
||||
const keyGenerator =
|
||||
typeof nostrTools.generatePrivateKey === "function"
|
||||
? nostrTools.generatePrivateKey
|
||||
: typeof nostrTools.generateSecretKey === "function"
|
||||
? nostrTools.generateSecretKey
|
||||
: null;
|
||||
const pubkeyDeriver =
|
||||
typeof nostrTools.getPublicKey === "function"
|
||||
? nostrTools.getPublicKey
|
||||
: null;
|
||||
|
||||
if (!keyGenerator || !pubkeyDeriver) {
|
||||
if (isDevMode) {
|
||||
console.warn(
|
||||
"[nostr] Unable to generate session actor: missing NostrTools helpers."
|
||||
@@ -991,8 +1000,69 @@ class NostrClient {
|
||||
return "";
|
||||
}
|
||||
|
||||
const privateKey = window.NostrTools.generatePrivateKey();
|
||||
const pubkey = window.NostrTools.getPublicKey(privateKey);
|
||||
let privateKey = keyGenerator();
|
||||
if (privateKey && typeof privateKey !== "string") {
|
||||
const hasLength =
|
||||
typeof privateKey === "object" &&
|
||||
privateKey !== null &&
|
||||
typeof privateKey.length === "number";
|
||||
if (nostrTools.utils?.bytesToHex && hasLength) {
|
||||
try {
|
||||
privateKey = nostrTools.utils.bytesToHex(privateKey);
|
||||
} catch (error) {
|
||||
if (isDevMode) {
|
||||
console.warn(
|
||||
"[nostr] Failed to normalize generated private key:",
|
||||
error
|
||||
);
|
||||
}
|
||||
privateKey = "";
|
||||
}
|
||||
} else {
|
||||
privateKey = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof privateKey !== "string" || !privateKey) {
|
||||
if (isDevMode) {
|
||||
console.warn(
|
||||
"[nostr] Unable to generate session actor: invalid private key output."
|
||||
);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
let pubkey = pubkeyDeriver(privateKey);
|
||||
if (pubkey && typeof pubkey !== "string") {
|
||||
const hasLength =
|
||||
typeof pubkey === "object" &&
|
||||
pubkey !== null &&
|
||||
typeof pubkey.length === "number";
|
||||
if (nostrTools.utils?.bytesToHex && hasLength) {
|
||||
try {
|
||||
pubkey = nostrTools.utils.bytesToHex(pubkey);
|
||||
} catch (error) {
|
||||
if (isDevMode) {
|
||||
console.warn(
|
||||
"[nostr] Failed to normalize generated public key:",
|
||||
error
|
||||
);
|
||||
}
|
||||
pubkey = "";
|
||||
}
|
||||
} else {
|
||||
pubkey = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof pubkey !== "string" || !pubkey) {
|
||||
if (isDevMode) {
|
||||
console.warn(
|
||||
"[nostr] Unable to generate session actor: invalid public key output."
|
||||
);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
this.sessionActor = { pubkey, privateKey };
|
||||
|
||||
|
||||
Reference in new issue
Block a user