mirror of
https://github.com/zadam/trilium.git
synced 2026-02-17 11:14:36 +01:00
feat(pdfjs): replace blob instead of creating a new revision every time
This commit is contained in:
parent
23f7dc63b8
commit
0039f4c155
@ -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
|
||||
|
||||
@ -43,7 +43,8 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
|
||||
if (iframeRef.current?.contentWindow) {
|
||||
iframeRef.current.contentWindow.location.reload();
|
||||
}
|
||||
}
|
||||
},
|
||||
replaceWithoutRevision: true
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@ -28,7 +28,9 @@ function updateFile(req: Request) {
|
||||
};
|
||||
}
|
||||
|
||||
note.saveRevision();
|
||||
if (req.query.replace !== "1") {
|
||||
note.saveRevision();
|
||||
}
|
||||
|
||||
note.mime = file.mimetype.toLowerCase();
|
||||
note.save();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user