Files
bitvid/js/ui/initEditModal.js
T
thePR0M3TH3ANandClaude Fable 5 e32298cc89 uploads: locked-storage file picks unlock inline instead of dead-ending (#56)
All three paths (upload video pick, upload thumbnail pick, edit "Replace
file") now route through the shared signer gate — silent kept-unlocked
restore, else ONE passphrase prompt — then unlock storage and continue the
same pick. Cancel/bad-passphrase abort quietly; a refused thumbnail pick
restores the picker. Unlock glue extracted to uploadModalStorageUnlock.js
(file-size budget); ensureSigner threaded via initUploadModal/initEditModal.

Tests: tests/upload-edit-storage-unlock-gate.test.mjs (12).

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-03 21:01:20 -04:00

87 lines
2.2 KiB
JavaScript

import { EditModal } from "./components/EditModal.js";
export function initEditModal({
app = null,
editModalOverride = null,
container = null,
services = {},
utilities = {},
callbacks = {},
eventTarget = null,
} = {}) {
const events = eventTarget instanceof EventTarget ? eventTarget : new EventTarget();
const {
getMode = null,
sanitizers = {},
r2Service = null,
s3Service = null,
storageService = null,
} = services;
const {
removeTrackingScripts: removeTrackingScriptsFn = null,
setGlobalModalState: setGlobalModalStateFn = null,
escapeHtml = null,
} = utilities;
const {
showError = null,
showSuccess = null,
getCurrentPubkey = null,
safeEncodeNpub = null,
onSubmit = null,
onCancel = null,
} = callbacks;
const modal =
(typeof editModalOverride === "function"
? editModalOverride({ app, eventTarget: events })
: editModalOverride) ||
new EditModal({
removeTrackingScripts: removeTrackingScriptsFn,
setGlobalModalState: setGlobalModalStateFn,
showError,
showSuccess,
getMode,
sanitizers,
escapeHtml,
r2Service,
s3Service,
storageService,
getCurrentPubkey,
safeEncodeNpub,
// Shared signer gate (#56): lets the "Replace file" pickers unlock storage
// inline (cached keep-unlocked key or one passphrase prompt).
ensureSigner: (options) =>
typeof app?.ensureEncryptionCapableSigner === "function"
? app.ensureEncryptionCapableSigner(options)
: null,
eventTarget: events,
container,
});
const boundSubmitHandler =
typeof onSubmit === "function" ? (event) => onSubmit(event) : null;
const boundCancelHandler = typeof onCancel === "function" ? () => onCancel() : null;
if (boundSubmitHandler && typeof modal?.addEventListener === "function") {
modal.addEventListener("video:edit-submit", boundSubmitHandler);
}
if (boundCancelHandler && typeof modal?.addEventListener === "function") {
modal.addEventListener("video:edit-cancel", boundCancelHandler);
}
return {
modal,
events,
handlers: {
submit: boundSubmitHandler,
cancel: boundCancelHandler,
},
};
}
export default initEditModal;