mirror of
https://github.com/zadam/trilium.git
synced 2025-12-29 18:54:29 +01:00
fix(client/pdf): blob reloaded when saving
This commit is contained in:
parent
359f398afa
commit
bb374a5ce2
@ -85,13 +85,15 @@ async function remove<T>(url: string, componentId?: string) {
|
||||
return await call<T>("DELETE", url, componentId);
|
||||
}
|
||||
|
||||
async function upload(url: string, fileToUpload: File) {
|
||||
async function upload(url: string, fileToUpload: File, componentId?: string) {
|
||||
const formData = new FormData();
|
||||
formData.append("upload", fileToUpload);
|
||||
|
||||
return await $.ajax({
|
||||
url: window.glob.baseApiUrl + url,
|
||||
headers: await getHeaders(),
|
||||
headers: await getHeaders(componentId ? {
|
||||
"trilium-component-id": componentId
|
||||
} : undefined),
|
||||
data: formData,
|
||||
type: "PUT",
|
||||
timeout: 60 * 60 * 1000,
|
||||
|
||||
@ -10,13 +10,13 @@ import { TypeWidgetProps } from "./type_widget";
|
||||
|
||||
const TEXT_MAX_NUM_CHARS = 5000;
|
||||
|
||||
export default function FileTypeWidget({ note }: TypeWidgetProps) {
|
||||
const blob = useNoteBlob(note);
|
||||
export default function FileTypeWidget({ note, parentComponent }: TypeWidgetProps) {
|
||||
const blob = useNoteBlob(note, parentComponent?.componentId);
|
||||
|
||||
if (blob?.content) {
|
||||
return <TextPreview content={blob.content} />;
|
||||
} else if (note.mime === "application/pdf") {
|
||||
return <PdfPreview note={note} />;
|
||||
return <PdfPreview note={note} componentId={parentComponent?.componentId} />;
|
||||
} else if (note.mime.startsWith("video/")) {
|
||||
return <VideoPreview note={note} />;
|
||||
} else if (note.mime.startsWith("audio/")) {
|
||||
|
||||
@ -12,7 +12,10 @@ const VARIABLE_WHITELIST = new Set([
|
||||
"main-text-color"
|
||||
]);
|
||||
|
||||
export default function PdfPreview({ note }: { note: FNote }) {
|
||||
export default function PdfPreview({ note, componentId }: {
|
||||
note: FNote,
|
||||
componentId: string | undefined;
|
||||
}) {
|
||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||
const { onLoad } = useStyleInjection(iframeRef);
|
||||
const historyConfig = useViewModeConfig(note, "pdfHistory");
|
||||
@ -21,7 +24,7 @@ export default function PdfPreview({ note }: { note: FNote }) {
|
||||
function handleMessage(event: MessageEvent) {
|
||||
if (event.data?.type === "pdfjs-viewer-document-modified" && event.data?.data) {
|
||||
const blob = new Blob([event.data.data], { type: note.mime });
|
||||
server.upload(`notes/${note.noteId}/file`, new File([blob], note.title, { type: note.mime }));
|
||||
server.upload(`notes/${note.noteId}/file`, new File([blob], note.title, { type: note.mime }), componentId);
|
||||
}
|
||||
|
||||
if (event.data.type === "pdfjs-viewer-save-view-history" && event.data?.data) {
|
||||
|
||||
@ -1,20 +1,21 @@
|
||||
"use strict";
|
||||
|
||||
import protectedSessionService from "../../services/protected_session.js";
|
||||
import utils from "../../services/utils.js";
|
||||
import log from "../../services/log.js";
|
||||
import noteService from "../../services/notes.js";
|
||||
import tmp from "tmp";
|
||||
|
||||
import chokidar from "chokidar";
|
||||
import type { Request, Response } from "express";
|
||||
import fs from "fs";
|
||||
import { Readable } from "stream";
|
||||
import chokidar from "chokidar";
|
||||
import ws from "../../services/ws.js";
|
||||
import tmp from "tmp";
|
||||
|
||||
import becca from "../../becca/becca.js";
|
||||
import ValidationError from "../../errors/validation_error.js";
|
||||
import type { Request, Response } from "express";
|
||||
import type BNote from "../../becca/entities/bnote.js";
|
||||
import type BAttachment from "../../becca/entities/battachment.js";
|
||||
import type BNote from "../../becca/entities/bnote.js";
|
||||
import ValidationError from "../../errors/validation_error.js";
|
||||
import dataDirs from "../../services/data_dir.js";
|
||||
import log from "../../services/log.js";
|
||||
import noteService from "../../services/notes.js";
|
||||
import protectedSessionService from "../../services/protected_session.js";
|
||||
import utils from "../../services/utils.js";
|
||||
import ws from "../../services/ws.js";
|
||||
|
||||
function updateFile(req: Request) {
|
||||
const note = becca.getNoteOrThrow(req.params.noteId);
|
||||
@ -189,8 +190,8 @@ function saveToTmpDir(fileName: string, content: string | Buffer, entityType: st
|
||||
chokidar.watch(tmpObj.name).on("change", (path, stats) => {
|
||||
ws.sendMessageToAllClients({
|
||||
type: "openedFileUpdated",
|
||||
entityType: entityType,
|
||||
entityId: entityId,
|
||||
entityType,
|
||||
entityId,
|
||||
lastModifiedMs: stats?.atimeMs,
|
||||
filePath: tmpObj.name
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user