feat: a password can be set for a document, and one is asked for on opening
The File menu of both chromes protects the document; the password reaches the two write primitives in saveFile.ts, so .odt, .docx and both template kinds are encrypted after every post-processing pass. Opening a protected file asks until it fits or the user gives up, before any importer reads the archive. The password is session state and never persisted; the autosaved copy stays plain.
This commit is contained in:
1 parent
4b163e6d10
commit
5856de6c2d
7 files changed
+293
-18
No files matched your search
+69
-7
@@ -13,6 +13,7 @@
|
||||
import { supportsFsAccess, saveOdt, saveAsOdt, saveDocx, saveAsDocx, saveAsTemplate, openOdt } from './lib/export/saveFile';
|
||||
import { loadRecentFiles, rememberRecentFile, readRecentFile, forgetRecentFile, forgetRecentFiles, pruneRecentFiles, type RecentFile } from './lib/storage/recentFiles';
|
||||
import { importOdt } from './lib/import/odt';
|
||||
import { isProtected, decryptPackage, WRONG_PASSWORD } from './lib/crypto/protect';
|
||||
import { importDocx } from './lib/import/docx';
|
||||
import { convertUnsupportedImages } from './lib/import/imageFormats';
|
||||
import { getPageBreakDebug } from './lib/editor/extensions/pageBreaks';
|
||||
@@ -56,6 +57,7 @@
|
||||
import TemplateGalleryDialog from './lib/components/TemplateGalleryDialog.svelte';
|
||||
import type { TemplateEntry } from './lib/templates/types';
|
||||
import DocPropertiesDialog from './lib/components/DocPropertiesDialog.svelte';
|
||||
import PasswordDialog from './lib/components/PasswordDialog.svelte';
|
||||
import CommentsPane from './lib/components/CommentsPane.svelte';
|
||||
import RevisionsPane from './lib/components/RevisionsPane.svelte';
|
||||
import ConnectorLayer from './lib/components/ConnectorLayer.svelte';
|
||||
@@ -481,6 +483,13 @@
|
||||
// The file the document is saved to (File System Access API). Session-only: a
|
||||
// reload restores the doc from localStorage but the first Save re-prompts.
|
||||
let fileHandle: FileSystemFileHandle | null = $state(null);
|
||||
// The password the document is saved with. Session-only: it is never written to
|
||||
// localStorage, and the autosaved copy there stays unencrypted.
|
||||
let docPassword: string | null = $state(null);
|
||||
let passwordSetOpen = $state(false);
|
||||
let passwordAskOpen = $state(false);
|
||||
let passwordWrong = $state(false);
|
||||
let askResolve: ((password: string | null) => void) | null = null;
|
||||
// Word's and LibreOffice's recent-documents list; a click reopens the file itself.
|
||||
// Only a browser with the File System Access API has handles to reopen from, so
|
||||
// elsewhere the list stays empty; a startup prune drops entries whose handle is gone.
|
||||
@@ -581,6 +590,7 @@
|
||||
saveDocProperties(docProps);
|
||||
fileHandle = null;
|
||||
documentFormat = 'odt';
|
||||
docPassword = null;
|
||||
// Styles and note settings live in the document, so a new one starts from the built-ins
|
||||
setStyleSheet(builtinStyleSheet());
|
||||
setNoteSettings(DEFAULT_NOTE_SETTINGS);
|
||||
@@ -634,9 +644,41 @@
|
||||
if (Array.isArray(n.content)) for (const c of n.content) collectFontFamilies(c, out);
|
||||
}
|
||||
|
||||
function settleAsk(password: string | null): void {
|
||||
const resolve = askResolve;
|
||||
askResolve = null;
|
||||
resolve?.(password);
|
||||
}
|
||||
|
||||
// Ask until the password fits or the user gives up; null means give up.
|
||||
async function unprotect(bytes: Uint8Array): Promise<Uint8Array | null> {
|
||||
for (;;) {
|
||||
const password = await new Promise<string | null>((resolve) => {
|
||||
askResolve = resolve;
|
||||
passwordAskOpen = true;
|
||||
});
|
||||
if (password === null) return null;
|
||||
try {
|
||||
const plain = await decryptPackage(bytes, password);
|
||||
docPassword = password;
|
||||
passwordWrong = false;
|
||||
return plain;
|
||||
} catch (err) {
|
||||
if ((err as Error)?.message !== WRONG_PASSWORD) throw err;
|
||||
passwordWrong = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function applyImport(bytes: Uint8Array, handle: FileSystemFileHandle | null, sourceName?: string) {
|
||||
if (!editor) return;
|
||||
try {
|
||||
// Before anything reads the archive: an encrypted file is not one yet.
|
||||
if (isProtected(bytes)) {
|
||||
const opened = await unprotect(bytes);
|
||||
if (!opened) return;
|
||||
bytes = opened;
|
||||
}
|
||||
const name = sourceName?.toLowerCase() ?? '';
|
||||
let isDocx = name.endsWith('.docx') || name.endsWith('.dotx');
|
||||
// A template is loaded for its content but never bound as the handle, so the
|
||||
@@ -822,17 +864,18 @@
|
||||
if (documentFormat === 'docx') {
|
||||
const { buildDocx } = await import('./lib/export/docx');
|
||||
const bytes = await buildDocx(json, pageMargins, pageOrientation, hfOpts(), odfFromLanguage(documentLanguage), pageFormat, styleSheet(), tabIntervalCm, spacingModel, pageRtl, noteSettings(), docProps, hyphenate, pageNumbering, pageDecor, lineNumbering, recordChanges(), foldMarks);
|
||||
fileHandle = await saveDocx(bytes, suggestedFilenameDocx(json), fileHandle);
|
||||
fileHandle = await saveDocx(bytes, suggestedFilenameDocx(json), fileHandle, docPassword);
|
||||
recentFiles = await rememberRecentFile(fileHandle?.name ?? suggestedFilenameDocx(json), fileHandle);
|
||||
return;
|
||||
}
|
||||
const bytes = await buildOdt(json, pageMargins, pageOrientation, hfOpts(), odfFromLanguage(documentLanguage), pageFormat, styleSheet(), tabIntervalCm, spacingModel, pageRtl, noteSettings(), docProps, hyphenate, pageNumbering, pageDecor, lineNumbering, recordChanges(), foldMarks);
|
||||
fileHandle = await saveOdt(bytes, suggestedFilename(json), fileHandle);
|
||||
fileHandle = await saveOdt(bytes, suggestedFilename(json), fileHandle, docPassword);
|
||||
recentFiles = await rememberRecentFile(fileHandle?.name ?? suggestedFilename(json), fileHandle);
|
||||
} catch (err) {
|
||||
if ((err as DOMException)?.name === 'AbortError') return;
|
||||
// A stored handle may have lost permission; re-prompt via Save As.
|
||||
if (fileHandle) { fileHandle = null; await handleSaveAs(); return; }
|
||||
// A stored handle may have lost permission; re-prompt via Save As. Encryption
|
||||
// failing is not that case — it would silently save the document unprotected.
|
||||
if (fileHandle && (err as Error)?.name !== 'EncryptionError') { fileHandle = null; await handleSaveAs(); return; }
|
||||
console.error('[save] Failed to save file:', err);
|
||||
failed(t().dialogs.couldNotSave, err);
|
||||
}
|
||||
@@ -844,7 +887,7 @@
|
||||
const json = editor.getJSON() as Parameters<typeof buildOdt>[0];
|
||||
try {
|
||||
const bytes = await buildOdt(json, pageMargins, pageOrientation, hfOpts(), odfFromLanguage(documentLanguage), pageFormat, styleSheet(), tabIntervalCm, spacingModel, pageRtl, noteSettings(), docProps, hyphenate, pageNumbering, pageDecor, lineNumbering, recordChanges(), foldMarks);
|
||||
fileHandle = await saveAsOdt(bytes, suggestedFilename(json));
|
||||
fileHandle = await saveAsOdt(bytes, suggestedFilename(json), docPassword);
|
||||
documentFormat = 'odt'; // Save As is odt-only, so a docx-opened document switches format here.
|
||||
recentFiles = await rememberRecentFile(fileHandle?.name ?? suggestedFilename(json), fileHandle);
|
||||
} catch (err) {
|
||||
@@ -870,7 +913,7 @@
|
||||
return docxToDotx(await buildDocx(json, ...args));
|
||||
}
|
||||
return odtToOtt(await buildOdt(json, ...args));
|
||||
}, stripOdtExtension(suggestedFilename(json)));
|
||||
}, stripOdtExtension(suggestedFilename(json)), docPassword);
|
||||
} catch (err) {
|
||||
if ((err as DOMException)?.name === 'AbortError') return;
|
||||
console.error('[save] Failed to save template:', err);
|
||||
@@ -917,7 +960,7 @@
|
||||
const json = editor.getJSON() as Parameters<typeof buildOdt>[0];
|
||||
const { buildDocx } = await import('./lib/export/docx');
|
||||
const bytes = await buildDocx(json, pageMargins, pageOrientation, hfOpts(), odfFromLanguage(documentLanguage), pageFormat, styleSheet(), tabIntervalCm, spacingModel, pageRtl, noteSettings(), docProps, hyphenate, pageNumbering, pageDecor, lineNumbering, recordChanges(), foldMarks);
|
||||
await saveAsDocx(bytes, suggestedFilenameDocx(json));
|
||||
await saveAsDocx(bytes, suggestedFilenameDocx(json), docPassword);
|
||||
} catch (err) {
|
||||
if ((err as DOMException)?.name === 'AbortError') return;
|
||||
console.error('[docx] Export failed:', err);
|
||||
@@ -1182,6 +1225,8 @@
|
||||
onPrint={handlePrint}
|
||||
onAbout={() => (aboutOpen = true)}
|
||||
onDocProperties={() => (docPropsOpen = true)}
|
||||
onProtect={() => (passwordSetOpen = true)}
|
||||
hasPassword={docPassword !== null}
|
||||
onAutoCorrect={() => (autoCorrectOpen = true)}
|
||||
onAutoText={() => (autoTextOpen = true)}
|
||||
onNewComment={addComment}
|
||||
@@ -1307,6 +1352,10 @@
|
||||
<span class="theme-option-hint">{t().app.clearRecentFiles}</span>
|
||||
</button>
|
||||
{/if}
|
||||
<button class="theme-option" onclick={() => { exportMenuOpen = false; passwordSetOpen = true; }} role="menuitem">
|
||||
<span>{t().password.menu}</span>
|
||||
{#if docPassword !== null}<span class="theme-option-hint">{t().password.menuOn}</span>{/if}
|
||||
</button>
|
||||
<div class="theme-heading">{t().docProps.title}</div>
|
||||
<button class="theme-option" onclick={() => { exportMenuOpen = false; docPropsOpen = true; }} role="menuitem">
|
||||
<span>{t().docProps.title}</span>
|
||||
@@ -1591,6 +1640,19 @@
|
||||
<AutoTextDialog bind:open={autoTextOpen} editor={activeEditor} />
|
||||
<ThesaurusDialog bind:open={thesaurusOpen} editor={activeEditor} />
|
||||
<DocPropertiesDialog bind:open={docPropsOpen} props={docProps} onApply={(p) => { docProps = p; saveDocProperties(p); }} />
|
||||
<PasswordDialog
|
||||
bind:open={passwordSetOpen}
|
||||
mode="set"
|
||||
hasPassword={docPassword !== null}
|
||||
onApply={(password) => (docPassword = password)}
|
||||
/>
|
||||
<PasswordDialog
|
||||
bind:open={passwordAskOpen}
|
||||
mode="ask"
|
||||
wrong={passwordWrong}
|
||||
onApply={settleAsk}
|
||||
onCancel={() => settleAsk(null)}
|
||||
/>
|
||||
<!-- One instance for every entry point (styles gallery, insert-table menu): the
|
||||
callers only say which family to land on. -->
|
||||
<StyleManagerDialog bind:open={styleManagerOpen} family={styleManagerFamily} editor={activeEditor} />
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
<script lang="ts">
|
||||
import { t } from '../i18n/i18n.svelte';
|
||||
|
||||
// Two jobs, one dialog: setting the password a document is saved with, and asking
|
||||
// for the one an encrypted document was saved with.
|
||||
let { open = $bindable(false), mode, hasPassword = false, wrong = false, onApply, onCancel }: {
|
||||
open?: boolean;
|
||||
mode: 'set' | 'ask';
|
||||
hasPassword?: boolean;
|
||||
wrong?: boolean;
|
||||
onApply: (password: string | null) => void;
|
||||
onCancel?: () => void;
|
||||
} = $props();
|
||||
|
||||
let dialogEl = $state<HTMLDialogElement | null>(null);
|
||||
let firstInput = $state<HTMLInputElement | null>(null);
|
||||
let password = $state('');
|
||||
let repeat = $state('');
|
||||
|
||||
const mismatch = $derived(mode === 'set' && repeat !== '' && password !== repeat);
|
||||
const canApply = $derived(password !== '' && (mode === 'ask' || password === repeat));
|
||||
|
||||
$effect(() => {
|
||||
const el = dialogEl;
|
||||
if (!el) return;
|
||||
if (open && !el.open) el.showModal();
|
||||
else if (!open && el.open) el.close();
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (!open) return;
|
||||
password = '';
|
||||
repeat = '';
|
||||
queueMicrotask(() => firstInput?.focus());
|
||||
});
|
||||
|
||||
function apply(value: string | null) {
|
||||
onApply(value);
|
||||
open = false;
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
open = false;
|
||||
onCancel?.();
|
||||
}
|
||||
</script>
|
||||
|
||||
<dialog
|
||||
bind:this={dialogEl}
|
||||
onclose={cancel}
|
||||
onclick={(e) => e.target === dialogEl && cancel()}
|
||||
aria-label={mode === 'set' ? t().password.setTitle : t().password.askTitle}
|
||||
>
|
||||
<div class="body">
|
||||
<h2>{mode === 'set' ? t().password.setTitle : t().password.askTitle}</h2>
|
||||
|
||||
{#if wrong}<p class="wrong">{t().password.wrong}</p>{/if}
|
||||
|
||||
<label class="row">
|
||||
<span>{t().password.password}</span>
|
||||
<input
|
||||
bind:this={firstInput}
|
||||
type="password"
|
||||
bind:value={password}
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
onkeydown={(e) => { if (e.key === 'Enter' && canApply) apply(password); }}
|
||||
/>
|
||||
</label>
|
||||
|
||||
{#if mode === 'set'}
|
||||
<label class="row">
|
||||
<span>{t().password.repeat}</span>
|
||||
<input
|
||||
type="password"
|
||||
bind:value={repeat}
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
onkeydown={(e) => { if (e.key === 'Enter' && canApply) apply(password); }}
|
||||
/>
|
||||
</label>
|
||||
{#if mismatch}<p class="wrong">{t().password.mismatch}</p>{/if}
|
||||
<p class="note">{t().password.note}</p>
|
||||
{/if}
|
||||
|
||||
<div class="actions">
|
||||
{#if mode === 'set' && hasPassword}
|
||||
<button onclick={() => apply(null)}>{t().password.remove}</button>
|
||||
{/if}
|
||||
<span class="spacer"></span>
|
||||
<button onclick={cancel}>{t().common.cancel}</button>
|
||||
<button class="primary" disabled={!canApply} onclick={() => apply(password)}>
|
||||
{t().common.ok}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<style>
|
||||
dialog {
|
||||
/* The global reset zeroes every margin, which also takes the auto centring a
|
||||
modal <dialog> gets by default. */
|
||||
margin: auto;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
padding: 0;
|
||||
background: var(--color-surface);
|
||||
color: var(--color-text);
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
|
||||
|
||||
.body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
width: 360px;
|
||||
padding: 18px 20px 16px;
|
||||
font-family: var(--font-sans);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
h2 { font-size: 1rem; margin-bottom: 4px; }
|
||||
|
||||
.row { display: flex; align-items: center; gap: 8px; }
|
||||
.row > span { flex: 1; color: var(--color-text-muted); }
|
||||
|
||||
input {
|
||||
height: 26px;
|
||||
width: 200px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius);
|
||||
background: var(--color-surface);
|
||||
color: var(--color-text);
|
||||
padding: 0 6px;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.note { color: var(--color-text-muted); line-height: 1.35; }
|
||||
.wrong { color: #c62828; }
|
||||
|
||||
.actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
|
||||
.spacer { flex: 1; }
|
||||
|
||||
.actions button {
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius);
|
||||
background: var(--color-surface);
|
||||
color: var(--color-text);
|
||||
padding: 5px 14px;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.actions button:hover { background: var(--color-btn-hover); }
|
||||
.actions button:disabled { opacity: 0.5; cursor: default; }
|
||||
.actions .primary { border-color: var(--color-primary); background: var(--color-primary); color: #fff; }
|
||||
</style>
|
||||
@@ -68,7 +68,8 @@
|
||||
onSelectTheme,
|
||||
docxBusy = false,
|
||||
pdfBusy = false,
|
||||
onNew, onNewFromTemplate, onOpen, onSave, onSaveAs, onSaveDocx, onSaveTemplate, onExportPdf, onPrintPdf, onPrint, onAbout, onDocProperties, onAutoCorrect, onAutoText, onNewComment,
|
||||
hasPassword = false,
|
||||
onNew, onNewFromTemplate, onOpen, onSave, onSaveAs, onSaveDocx, onSaveTemplate, onExportPdf, onPrintPdf, onPrint, onAbout, onDocProperties, onProtect, onAutoCorrect, onAutoText, onNewComment,
|
||||
navigatorOpen = false, onToggleNavigator,
|
||||
recentFiles = [], onOpenRecent, onForgetRecent,
|
||||
}: {
|
||||
@@ -122,6 +123,8 @@
|
||||
onPrint?: () => void;
|
||||
onAbout?: () => void;
|
||||
onDocProperties?: () => void;
|
||||
onProtect?: () => void;
|
||||
hasPassword?: boolean;
|
||||
onAutoCorrect?: () => void;
|
||||
onAutoText?: () => void;
|
||||
onNewComment?: () => void;
|
||||
@@ -247,6 +250,10 @@
|
||||
<Icon name="print" size={16} />{t().app.print}
|
||||
<span class="menu-key">{withShortcut('Ctrl+P')}</span>
|
||||
</button>
|
||||
<button onclick={() => run(onProtect)}>
|
||||
<Icon name="lock" size={16} />{t().password.menu}
|
||||
{#if hasPassword}<span class="menu-key">{t().password.menuOn}</span>{/if}
|
||||
</button>
|
||||
<button onclick={() => run(onDocProperties)}>
|
||||
<Icon name="info" size={16} />{t().docProps.title}
|
||||
</button>
|
||||
|
||||
@@ -30,6 +30,7 @@ export const STROKED = {
|
||||
undo: ['M2.5 6.5h6.75a3.75 3.75 0 0 1 0 7.5H5.5', 'M5.25 3.5 2.5 6.5l2.75 3'],
|
||||
redo: ['M13.5 6.5H6.75a3.75 3.75 0 0 0 0 7.5H10.5', 'M10.75 3.5 13.5 6.5l-2.75 3'],
|
||||
info: ['M8 14.5A6.5 6.5 0 1 0 8 1.5a6.5 6.5 0 0 0 0 13z', 'M8 7.25v4'],
|
||||
lock: ['M3.75 7.25h8.5v6.25h-8.5z', 'M5.75 7.25V5a2.25 2.25 0 0 1 4.5 0v2.25'],
|
||||
ribbon: ['M2 3.25h12v3.5H2z', 'M2 9.5h4v3.25H2z', 'M7.5 9.5h2.5v3.25H7.5z', 'M11.5 9.5H14v3.25h-2.5z'],
|
||||
|
||||
cut: ['M4 2.5 11 12', 'M12 2.5 5 12', 'M3.6 13.9a1.6 1.6 0 1 0 0-3.2 1.6 1.6 0 0 0 0 3.2z', 'M12.4 13.9a1.6 1.6 0 1 0 0-3.2 1.6 1.6 0 0 0 0 3.2z'],
|
||||
|
||||
+31
-10
@@ -69,6 +69,15 @@ async function writeHandle(handle: FileSystemFileHandle, bytes: Uint8Array): Pro
|
||||
await writable.close();
|
||||
}
|
||||
|
||||
// Password protection is the last thing that happens to the bytes, after every
|
||||
// post-processing pass and after the template conversion. The crypto module loads
|
||||
// only when a password is actually set.
|
||||
async function protect(bytes: Uint8Array, password: string | null): Promise<Uint8Array> {
|
||||
if (!password) return bytes;
|
||||
const { encryptPackage } = await import('../crypto/protect');
|
||||
return encryptPackage(bytes, password);
|
||||
}
|
||||
|
||||
// Save to the given handle if we have one; otherwise prompt for a location (i.e.
|
||||
// the first save acts as Save As). Returns the handle written to, or null when
|
||||
// falling back to a plain download. Throws AbortError if the user cancels.
|
||||
@@ -76,13 +85,15 @@ export async function saveOdt(
|
||||
bytes: Uint8Array,
|
||||
suggestedName: string,
|
||||
handle: FileSystemFileHandle | null,
|
||||
password: string | null = null,
|
||||
): Promise<FileSystemFileHandle | null> {
|
||||
const out = await protect(bytes, password);
|
||||
if (!supportsFsAccess()) {
|
||||
download(bytes, suggestedName);
|
||||
download(out, suggestedName);
|
||||
return null;
|
||||
}
|
||||
const target = handle ?? (await (window as WinFs).showSaveFilePicker!({ suggestedName, types: PICKER_TYPES }));
|
||||
await writeHandle(target, bytes);
|
||||
await writeHandle(target, out);
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -90,13 +101,15 @@ export async function saveOdt(
|
||||
export async function saveAsOdt(
|
||||
bytes: Uint8Array,
|
||||
suggestedName: string,
|
||||
password: string | null = null,
|
||||
): Promise<FileSystemFileHandle | null> {
|
||||
const out = await protect(bytes, password);
|
||||
if (!supportsFsAccess()) {
|
||||
download(bytes, suggestedName);
|
||||
download(out, suggestedName);
|
||||
return null;
|
||||
}
|
||||
const handle = await (window as WinFs).showSaveFilePicker!({ suggestedName, types: PICKER_TYPES });
|
||||
await writeHandle(handle, bytes);
|
||||
await writeHandle(handle, out);
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -106,20 +119,26 @@ export async function saveDocx(
|
||||
bytes: Uint8Array,
|
||||
suggestedName: string,
|
||||
handle: FileSystemFileHandle | null,
|
||||
password: string | null = null,
|
||||
): Promise<FileSystemFileHandle | null> {
|
||||
const out = await protect(bytes, password);
|
||||
if (!supportsFsAccess()) {
|
||||
download(bytes, suggestedName, DOCX_MIME);
|
||||
download(out, suggestedName, DOCX_MIME);
|
||||
return null;
|
||||
}
|
||||
const target = handle ?? (await (window as WinFs).showSaveFilePicker!({ suggestedName, types: DOCX_PICKER_TYPES }));
|
||||
await writeHandle(target, bytes);
|
||||
await writeHandle(target, out);
|
||||
return target;
|
||||
}
|
||||
|
||||
// Export a .docx: always prompt for a location (no handle is tracked — this is the
|
||||
// explicit "Export" action, like PDF). Returns null. Throws AbortError if cancelled.
|
||||
export async function saveAsDocx(bytes: Uint8Array, suggestedName: string): Promise<void> {
|
||||
await saveDocx(bytes, suggestedName, null);
|
||||
export async function saveAsDocx(
|
||||
bytes: Uint8Array,
|
||||
suggestedName: string,
|
||||
password: string | null = null,
|
||||
): Promise<void> {
|
||||
await saveDocx(bytes, suggestedName, null, password);
|
||||
}
|
||||
|
||||
// Save a template. The picker offers both formats, so the bytes can only be built
|
||||
@@ -128,15 +147,17 @@ export async function saveAsDocx(bytes: Uint8Array, suggestedName: string): Prom
|
||||
export async function saveAsTemplate(
|
||||
build: (kind: 'ott' | 'dotx') => Promise<Uint8Array>,
|
||||
baseName: string,
|
||||
password: string | null = null,
|
||||
): Promise<void> {
|
||||
if (!supportsFsAccess()) {
|
||||
download(await build('ott'), `${baseName}.ott`, OTT_MIME);
|
||||
download(await protect(await build('ott'), password), `${baseName}.ott`, OTT_MIME);
|
||||
return;
|
||||
}
|
||||
const handle = await (window as WinFs).showSaveFilePicker!({
|
||||
suggestedName: `${baseName}.ott`, types: TEMPLATE_PICKER_TYPES,
|
||||
});
|
||||
await writeHandle(handle, await build(handle.name.toLowerCase().endsWith('.dotx') ? 'dotx' : 'ott'));
|
||||
const kind = handle.name.toLowerCase().endsWith('.dotx') ? 'dotx' : 'ott';
|
||||
await writeHandle(handle, await protect(await build(kind), password));
|
||||
}
|
||||
|
||||
// Prompt for an .odt/.ott/.docx to open, capturing its handle so a later save can
|
||||
|
||||
@@ -1104,6 +1104,18 @@ const de: Messages = {
|
||||
comments: 'Kommentare wurden entfernt',
|
||||
missingFonts: (fonts) => `Diese Schriftarten sind nicht installiert und wurden durch Ersatzschriften dargestellt: ${fonts}`,
|
||||
},
|
||||
password: {
|
||||
menu: 'Mit Passwort schützen…',
|
||||
menuOn: 'Geschützt',
|
||||
setTitle: 'Mit Passwort schützen',
|
||||
askTitle: 'Dieses Dokument ist geschützt',
|
||||
password: 'Passwort',
|
||||
repeat: 'Wiederholen',
|
||||
mismatch: 'Die beiden Eingaben unterscheiden sich.',
|
||||
wrong: 'Falsches Passwort.',
|
||||
note: 'Schützt die gespeicherte Datei. Die Kopie, die der Editor im Browser hält, bleibt unverschlüsselt.',
|
||||
remove: 'Schutz entfernen',
|
||||
},
|
||||
importError: {
|
||||
odtArchive: 'Keine gültige .odt-Datei (Archiv konnte nicht gelesen werden).',
|
||||
odtContentMissing: 'Keine gültige .odt-Datei (content.xml fehlt).',
|
||||
@@ -1113,6 +1125,7 @@ const de: Messages = {
|
||||
docxArchive: 'Keine gültige .docx-Datei (Archiv konnte nicht gelesen werden).',
|
||||
docxMissing: 'Keine gültige .docx-Datei (word/document.xml fehlt).',
|
||||
docxNoBody: 'Kein Word-Dokument (kein w:body).',
|
||||
encryptionUnsupported: 'Dieses Dokument benutzt ein Verschlüsselungsverfahren, das nicht unterstützt wird.',
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1112,6 +1112,18 @@ const en = {
|
||||
comments: 'Comments were removed',
|
||||
missingFonts: (fonts: string) => `These fonts aren't installed and were shown with a substitute: ${fonts}`,
|
||||
},
|
||||
password: {
|
||||
menu: 'Protect with a password…',
|
||||
menuOn: 'Protected',
|
||||
setTitle: 'Protect with a password',
|
||||
askTitle: 'This document is protected',
|
||||
password: 'Password',
|
||||
repeat: 'Repeat',
|
||||
mismatch: 'The two entries differ.',
|
||||
wrong: 'Wrong password.',
|
||||
note: 'Protects the saved file. The copy this editor keeps in the browser stays unencrypted.',
|
||||
remove: 'Remove protection',
|
||||
},
|
||||
importError: {
|
||||
odtArchive: 'Not a valid .odt file (could not read the archive).',
|
||||
odtContentMissing: 'Not a valid .odt file (content.xml is missing).',
|
||||
@@ -1121,6 +1133,7 @@ const en = {
|
||||
docxArchive: 'Not a valid .docx file (could not read the archive).',
|
||||
docxMissing: 'Not a valid .docx file (word/document.xml is missing).',
|
||||
docxNoBody: 'Not a Word document (no w:body).',
|
||||
encryptionUnsupported: 'This document uses an encryption method that is not supported.',
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user