mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
With a persisted ("remember this key") nsec login, uploading a video after a page
reload reported "storage is locked" and then "No signer available to unlock storage."
The reload restores the logged-in pubkey but NOT the in-memory signer (the key is
passphrase-encrypted), and UploadModal.handleUnlock dead-ended on the alert — it never
asked for the passphrase.
Fix (mirrors the storage pane's #36 behavior): handleUnlock now calls
promptStoredNsecUnlock(pubkey) when there's no usable signer. If the active account has
a locked saved nsec key (getStoredSessionActorMetadata), it shows an actionable message
and opens the login modal's existing unlock-saved-key (passphrase) flow via a new
onRequestUnlock hook (wired in initUploadModal -> app.loginModalController.openModal),
instead of the dead-end alert. After the user re-enters their passphrase the signer is
active and the upload proceeds.
Tests: tests/upload-modal-nsec-unlock.test.mjs (5 — detects locked nsec for the active
account + opens unlock; ignores missing/non-nsec/other-account; falls through with no
hook). Build + lint clean.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
93 lines
2.4 KiB
JavaScript
93 lines
2.4 KiB
JavaScript
import { UploadModal } from "./components/UploadModal.js";
|
|
|
|
export function initUploadModal({
|
|
app = null,
|
|
uploadModalOverride = null,
|
|
container = null,
|
|
services = {},
|
|
utilities = {},
|
|
callbacks = {},
|
|
eventTarget = null,
|
|
} = {}) {
|
|
const events = eventTarget instanceof EventTarget ? eventTarget : new EventTarget();
|
|
|
|
const {
|
|
authService = null,
|
|
r2Service = null,
|
|
s3Service = null,
|
|
storageService = null,
|
|
} = services;
|
|
|
|
const {
|
|
removeTrackingScripts: removeTrackingScriptsFn = null,
|
|
setGlobalModalState: setGlobalModalStateFn = null,
|
|
} = utilities;
|
|
|
|
const {
|
|
publishVideoNote = null,
|
|
showError = null,
|
|
showSuccess = null,
|
|
getCurrentPubkey = null,
|
|
safeEncodeNpub = null,
|
|
onSubmit = null,
|
|
} = callbacks;
|
|
|
|
const modal =
|
|
(typeof uploadModalOverride === "function"
|
|
? uploadModalOverride({ app, eventTarget: events })
|
|
: uploadModalOverride) ||
|
|
new UploadModal({
|
|
authService,
|
|
r2Service,
|
|
s3Service,
|
|
storageService,
|
|
publishVideoNote,
|
|
removeTrackingScripts: removeTrackingScriptsFn,
|
|
setGlobalModalState: setGlobalModalStateFn,
|
|
showError,
|
|
showSuccess,
|
|
getCurrentPubkey,
|
|
safeEncodeNpub,
|
|
eventTarget: events,
|
|
container,
|
|
onRequestStorageSettings: () => {
|
|
if (app && app.profileController && typeof app.profileController.show === "function") {
|
|
app.profileController.show("storage");
|
|
}
|
|
},
|
|
// Open the login modal's unlock-saved-key (passphrase) flow when a persisted
|
|
// nsec session is locked after a reload.
|
|
onRequestUnlock: () => {
|
|
try {
|
|
if (typeof app?.initializeLoginModalController === "function") {
|
|
app.initializeLoginModalController();
|
|
}
|
|
const controller = app?.loginModalController;
|
|
if (controller && typeof controller.openModal === "function") {
|
|
return controller.openModal({}) !== false;
|
|
}
|
|
} catch (error) {
|
|
/* best-effort */
|
|
}
|
|
return false;
|
|
},
|
|
});
|
|
|
|
const boundSubmitHandler =
|
|
typeof onSubmit === "function" ? (event) => onSubmit(event) : null;
|
|
|
|
if (boundSubmitHandler && typeof modal?.addEventListener === "function") {
|
|
modal.addEventListener("upload:submit", boundSubmitHandler);
|
|
}
|
|
|
|
return {
|
|
modal,
|
|
events,
|
|
handlers: {
|
|
submit: boundSubmitHandler,
|
|
},
|
|
};
|
|
}
|
|
|
|
export default initUploadModal;
|