feat(pdfjs): replace blob instead of creating a new revision every time

This commit is contained in:
Elian Doran 2026-01-04 17:25:56 +02:00
parent 23f7dc63b8
commit 0039f4c155
No known key found for this signature in database
3 changed files with 10 additions and 5 deletions

View File

@ -170,7 +170,7 @@ export function useEditorSpacedUpdate({ note, noteType, noteContext, getData, on
return spacedUpdate;
}
export function useBlobEditorSpacedUpdate({ note, noteType, noteContext, getData, onContentChange, dataSaved, updateInterval }: {
export function useBlobEditorSpacedUpdate({ note, noteType, noteContext, getData, onContentChange, dataSaved, updateInterval, replaceWithoutRevision }: {
noteType: NoteType;
note: FNote,
noteContext: NoteContext | null | undefined,
@ -178,6 +178,8 @@ export function useBlobEditorSpacedUpdate({ note, noteType, noteContext, getData
onContentChange: (newBlob: FBlob) => void,
dataSaved?: (savedData: Blob) => void,
updateInterval?: number;
/** If set to true, then the blob is replaced directly without saving a revision before. */
replaceWithoutRevision?: boolean;
}) {
const parentComponent = useContext(ParentComponent);
const blob = useNoteBlob(note, parentComponent?.componentId);
@ -190,10 +192,10 @@ export function useBlobEditorSpacedUpdate({ note, noteType, noteContext, getData
if (data === undefined || note.type !== noteType) return;
protected_session_holder.touchProtectedSessionIfNecessary(note);
await server.upload(`notes/${note.noteId}/file`, new File([ data ], note.title, { type: note.mime }), parentComponent?.componentId);
await server.upload(`notes/${note.noteId}/file?replace=${replaceWithoutRevision ? "1" : "0"}`, new File([ data ], note.title, { type: note.mime }), parentComponent?.componentId);
dataSaved?.(data);
};
}, [ note, getData, dataSaved, noteType, parentComponent ]);
}, [ note, getData, dataSaved, noteType, parentComponent, replaceWithoutRevision ]);
const stateCallback = useCallback<StateCallback>((state) => {
noteContext?.setContextData("saveState", {
state

View File

@ -43,7 +43,8 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
if (iframeRef.current?.contentWindow) {
iframeRef.current.contentWindow.location.reload();
}
}
},
replaceWithoutRevision: true
});
useEffect(() => {

View File

@ -28,7 +28,9 @@ function updateFile(req: Request) {
};
}
note.saveRevision();
if (req.query.replace !== "1") {
note.saveRevision();
}
note.mime = file.mimetype.toLowerCase();
note.save();