Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fa88722
fix: scan child table rows for attachment cleanup on delete
alaa-alsalehi May 4, 2026
bc90af2
fix: cleanup filesystem attachments on doc delete
alaa-alsalehi May 4, 2026
c993622
chore: bump version to 0.47.1
alaa-alsalehi May 4, 2026
bc9c0bd
refactor: delegate filesystem attachments to AttachmentManager
alaa-alsalehi May 4, 2026
8ab7f2c
feat: stage attachment files in temp until document sync
alaa-alsalehi May 4, 2026
4c9cb00
refactor: deduplicate attachment save paths in main and AttachmentMan…
alaa-alsalehi May 4, 2026
2f24fb1
feat: stage filesystem attachments on duplicate; add Doc.duplicateFor…
alaa-alsalehi May 5, 2026
37f0bda
fix: delete orphan attachment files when DB write fails after stageCo…
alaa-alsalehi May 5, 2026
80620be
refactor: return mime type from attachment read; centralize filename …
alaa-alsalehi May 5, 2026
1157b1b
refactor: rename AttachmentManager to DocAttachmentManager
alaa-alsalehi May 5, 2026
fde89a0
fix: make books-staged refs always base64 or fail loudly
alaa-alsalehi May 5, 2026
c0aa4b8
refactor: replace escape/unescape in books-staged encoding with TextE…
alaa-alsalehi May 5, 2026
19dc8d8
refactor: unify AttachImage src resolver IPC read to data URL
alaa-alsalehi May 5, 2026
dfcc966
fix: avoid silent attachment data URL encoding failures
alaa-alsalehi May 5, 2026
eb44584
chore: log attachment cleanup failures on doc delete
alaa-alsalehi May 5, 2026
5027ff8
chore: dedupe isDocLike guard and log stageCommit failures
alaa-alsalehi May 5, 2026
b096767
chore: bump version to 0.48.0
alaa-alsalehi May 5, 2026
6e8a52a
fix: commit staged attachments only immediately before DB write
alaa-alsalehi May 5, 2026
b264519
fix: delete DB row before best-effort attachment filesystem cleanup
alaa-alsalehi May 5, 2026
7de025e
fix: abort and rollback stageCommit on partial failure
alaa-alsalehi May 5, 2026
cdd04cb
fix: abort duplicateForEdit when attachment remap fails
alaa-alsalehi May 5, 2026
a1f167d
fix: reject stage root path in stageCommit/stageDelete validation
alaa-alsalehi May 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
986 changes: 986 additions & 0 deletions fyo/model/DocAttachmentManager.ts

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions fyo/model/attachmentEncoding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function uint8ArrayToBase64(bytes: Uint8Array): string | null {
try {
// Browser/Electron renderer
// eslint-disable-next-line no-undef
if (typeof btoa === 'function') {
let binary = '';
const chunkSize = 0x8000;
for (let i = 0; i < bytes.length; i += chunkSize) {
binary += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
}
// eslint-disable-next-line no-undef
return btoa(binary);
}
} catch (err) {
// best-effort; fallback to Buffer path below
console.warn(
'[books] attachment encoding failed using btoa/String.fromCharCode',
err
);
}

// Fallback (Node-like)
const B = (globalThis as { Buffer?: typeof Buffer | undefined })?.Buffer;
if (B) {
try {
return B.from(bytes).toString('base64');
} catch (err) {
console.warn('[books] attachment encoding failed using Buffer', err);
return null;
}
}
return null;
}

export function dataUrlFromBytes(type: string, bytes: Uint8Array): string | null {
const base64 = uint8ArrayToBase64(bytes);
if (!base64) {
return null;
}
return `data:${type || 'application/octet-stream'};base64,${base64}`;
}

Loading
Loading