texlite 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DESIGN.md +85 -2
- package/NPM_TESTING.md +46 -2
- package/OPERATIONS.md +136 -6
- package/README.md +1 -2
- package/README.zh-CN.md +2 -2
- package/THIRD_PARTY_NOTICES.md +12 -0
- package/dist/client/assets/AdminUsers-D4ljqr_D.js +1 -0
- package/dist/client/assets/AdminUsers-D4ljqr_D.js.br +0 -0
- package/dist/client/assets/AdminUsers-D4ljqr_D.js.gz +0 -0
- package/dist/client/assets/AgentManagement-DwRMP_nD.js +1 -0
- package/dist/client/assets/AgentManagement-DwRMP_nD.js.br +0 -0
- package/dist/client/assets/AgentManagement-DwRMP_nD.js.gz +0 -0
- package/dist/client/assets/AgentTerminal-CSsr21PC.js +2 -0
- package/dist/client/assets/AgentTerminal-CSsr21PC.js.br +0 -0
- package/dist/client/assets/AgentTerminal-CSsr21PC.js.gz +0 -0
- package/dist/client/assets/{AgentTerminalSurface-DliOcop5.js → AgentTerminalSurface-BLroKMGe.js} +1 -1
- package/dist/client/assets/{AgentTerminalSurface-DliOcop5.js.br → AgentTerminalSurface-BLroKMGe.js.br} +0 -0
- package/dist/client/assets/AgentTerminalSurface-BLroKMGe.js.gz +0 -0
- package/dist/client/assets/{AvatarSettingsDialog-iuEbMO4a.js → AvatarSettingsDialog-BgVGfSzn.js} +1 -1
- package/dist/client/assets/AvatarSettingsDialog-BgVGfSzn.js.br +0 -0
- package/dist/client/assets/AvatarSettingsDialog-BgVGfSzn.js.gz +0 -0
- package/dist/client/assets/CitationBibtexEditor-DLPom-qx.js +1 -0
- package/dist/client/assets/CitationLibraryDialog-Cn-kFi8E.js +3 -0
- package/dist/client/assets/CitationLibraryDialog-Cn-kFi8E.js.br +0 -0
- package/dist/client/assets/CitationLibraryDialog-Cn-kFi8E.js.gz +0 -0
- package/dist/client/assets/Dashboard-7JrR0t6C.js +5 -0
- package/dist/client/assets/Dashboard-7JrR0t6C.js.br +0 -0
- package/dist/client/assets/Dashboard-7JrR0t6C.js.gz +0 -0
- package/dist/client/assets/DrawioEditor-CYQnzKDd.js +1 -0
- package/dist/client/assets/DrawioEditor-CYQnzKDd.js.br +0 -0
- package/dist/client/assets/DrawioEditor-CYQnzKDd.js.gz +0 -0
- package/dist/client/assets/GitDialog-DMCVR8QK.js +4 -0
- package/dist/client/assets/GitDialog-DMCVR8QK.js.br +0 -0
- package/dist/client/assets/GitDialog-DMCVR8QK.js.gz +0 -0
- package/dist/client/assets/GitHubAccountDialog-BbJpR9Vq.js +1 -0
- package/dist/client/assets/GitHubAccountDialog-BbJpR9Vq.js.br +0 -0
- package/dist/client/assets/GitHubAccountDialog-BbJpR9Vq.js.gz +0 -0
- package/dist/client/assets/{HistoryDialog-upkR8E0L.js → HistoryDialog-CcPWpTLn.js} +3 -3
- package/dist/client/assets/HistoryDialog-CcPWpTLn.js.br +0 -0
- package/dist/client/assets/HistoryDialog-CcPWpTLn.js.gz +0 -0
- package/dist/client/assets/LatexEditor-D7C9jpJO.js +25 -0
- package/dist/client/assets/LatexEditor-D7C9jpJO.js.br +0 -0
- package/dist/client/assets/LatexEditor-D7C9jpJO.js.gz +0 -0
- package/dist/client/assets/{MarkdownPreview-_AXp5G7f.js → MarkdownPreview-Txs5upCY.js} +1 -1
- package/dist/client/assets/MarkdownPreview-Txs5upCY.js.br +0 -0
- package/dist/client/assets/MarkdownPreview-Txs5upCY.js.gz +0 -0
- package/dist/client/assets/{ProjectIconPickerDialog-BxjEYsau.js → ProjectIconPickerDialog-CUlPlfmL.js} +1 -1
- package/dist/client/assets/ProjectIconPickerDialog-CUlPlfmL.js.br +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-CUlPlfmL.js.gz +0 -0
- package/dist/client/assets/ProjectSearchDialog-Bt6NyHIJ.js +1 -0
- package/dist/client/assets/ProjectSearchDialog-Bt6NyHIJ.js.br +0 -0
- package/dist/client/assets/ProjectSearchDialog-Bt6NyHIJ.js.gz +0 -0
- package/dist/client/assets/ProjectSettings-B6e7EAxq.js +4 -0
- package/dist/client/assets/ProjectSettings-B6e7EAxq.js.br +0 -0
- package/dist/client/assets/ProjectSettings-B6e7EAxq.js.gz +0 -0
- package/dist/client/assets/ProjectWorkspace-D0EMITec.js +25 -0
- package/dist/client/assets/ProjectWorkspace-D0EMITec.js.br +0 -0
- package/dist/client/assets/ProjectWorkspace-D0EMITec.js.gz +0 -0
- package/dist/client/assets/{QuickOpenDialog-HlkWqVR9.js → QuickOpenDialog-D6yjnquG.js} +1 -1
- package/dist/client/assets/QuickOpenDialog-D6yjnquG.js.br +0 -0
- package/dist/client/assets/QuickOpenDialog-D6yjnquG.js.gz +0 -0
- package/dist/client/assets/{ReadOnlySource-BIdN1YP_.js → ReadOnlySource-BOAnB5L0.js} +1 -1
- package/dist/client/assets/{SelectionHistoryDialog-Cb8I-G6m.js → SelectionHistoryDialog-D6ql9E0j.js} +2 -2
- package/dist/client/assets/SelectionHistoryDialog-D6ql9E0j.js.br +0 -0
- package/dist/client/assets/SelectionHistoryDialog-D6ql9E0j.js.gz +0 -0
- package/dist/client/assets/SharedProjectPage-DuscqDx5.js +2 -0
- package/dist/client/assets/SharedProjectPage-DuscqDx5.js.br +0 -0
- package/dist/client/assets/SharedProjectPage-DuscqDx5.js.gz +0 -0
- package/dist/client/assets/SystemMetricsDialog-KiKZOF2N.js +1 -0
- package/dist/client/assets/SystemMetricsDialog-KiKZOF2N.js.br +0 -0
- package/dist/client/assets/SystemMetricsDialog-KiKZOF2N.js.gz +0 -0
- package/dist/client/assets/TagManagementDialog-BHbqvu3K.js +1 -0
- package/dist/client/assets/TagManagementDialog-BHbqvu3K.js.br +0 -0
- package/dist/client/assets/TagManagementDialog-BHbqvu3K.js.gz +0 -0
- package/dist/client/assets/ThemeSwitcher-5cgNbWiG.js +1 -0
- package/dist/client/assets/{TikzGalleryDialog-cPUDQ5Wj.js → TikzGalleryDialog-CFbLjNTt.js} +1 -1
- package/dist/client/assets/TikzGalleryDialog-CFbLjNTt.js.br +0 -0
- package/dist/client/assets/TikzGalleryDialog-CFbLjNTt.js.gz +0 -0
- package/dist/client/assets/{WordCountDialog-AiuR3rra.js → WordCountDialog-hXC-cpPs.js} +1 -1
- package/dist/client/assets/WordCountDialog-hXC-cpPs.js.br +0 -0
- package/dist/client/assets/WordCountDialog-hXC-cpPs.js.gz +0 -0
- package/dist/client/assets/{chktex--32C-Pkl.js → chktex-CLzMD_9a.js} +1 -1
- package/dist/client/assets/file-down-DA4jGFrF.js +1 -0
- package/dist/client/assets/i18n-B8sR-BXw.js +13 -0
- package/dist/client/assets/i18n-B8sR-BXw.js.br +0 -0
- package/dist/client/assets/i18n-B8sR-BXw.js.gz +0 -0
- package/dist/client/assets/index-D6faTuJe.css +1 -0
- package/dist/client/assets/index-D6faTuJe.css.br +0 -0
- package/dist/client/assets/index-D6faTuJe.css.gz +0 -0
- package/dist/client/assets/index-dScQ5LCu.js +2 -0
- package/dist/client/assets/index-dScQ5LCu.js.br +0 -0
- package/dist/client/assets/index-dScQ5LCu.js.gz +0 -0
- package/dist/client/assets/relativeTime-zIVNCN0k.js +1 -0
- package/dist/client/assets/relativeTime-zIVNCN0k.js.br +0 -0
- package/dist/client/assets/relativeTime-zIVNCN0k.js.gz +0 -0
- package/dist/client/assets/sourceCursorStore-DWCXVKvp.js +2 -0
- package/dist/client/assets/sourceCursorStore-DWCXVKvp.js.br +0 -0
- package/dist/client/assets/sourceCursorStore-DWCXVKvp.js.gz +0 -0
- package/dist/client/assets/{spellCheck-DpWPgtM7.js → spellCheck-DpyzDbmq.js} +1 -1
- package/dist/client/assets/spellCheck-DpyzDbmq.js.br +0 -0
- package/dist/client/assets/spellCheck-DpyzDbmq.js.gz +0 -0
- package/dist/client/assets/useDeletionTransitions-Bm4I5qej.js +1 -0
- package/dist/client/assets/useDeletionTransitions-Bm4I5qej.js.br +0 -0
- package/dist/client/assets/useDeletionTransitions-Bm4I5qej.js.gz +0 -0
- package/dist/client/index.html +3 -4
- package/dist/server/agents/adapters/claude.js +5 -2
- package/dist/server/agents/adapters/common.js +18 -5
- package/dist/server/agents/execution.js +25 -4
- package/dist/server/agents/launcher.js +5 -2
- package/dist/server/agents/processIdentity.js +1 -1
- package/dist/server/agents/terminal.js +5 -2
- package/dist/server/agents/windowsJob.js +141 -0
- package/dist/server/app.js +24 -6
- package/dist/server/auth.js +3 -2
- package/dist/server/browserOrigin.js +15 -0
- package/dist/server/chktex.js +23 -11
- package/dist/server/collaboration.js +2 -1
- package/dist/server/compileDiagnostics.js +13 -9
- package/dist/server/compiler.js +70 -25
- package/dist/server/config.js +5 -1
- package/dist/server/db.js +4 -0
- package/dist/server/drawioLocks.js +114 -0
- package/dist/server/drawioOwnedBrowser.js +122 -0
- package/dist/server/drawioPdf.js +182 -0
- package/dist/server/environment.js +17 -8
- package/dist/server/files.js +86 -20
- package/dist/server/git.js +20 -16
- package/dist/server/harper.js +29 -10
- package/dist/server/history.js +62 -15
- package/dist/server/i18n.js +15 -0
- package/dist/server/index.js +15 -8
- package/dist/server/locales/zh-Hant.js +9 -0
- package/dist/server/pdfFonts.js +78 -0
- package/dist/server/pm2.js +2 -1
- package/dist/server/processTree.js +128 -7
- package/dist/server/projectDeletionCleanup.js +62 -0
- package/dist/server/projectMutations.js +3 -0
- package/dist/server/projectReplace.js +2 -2
- package/dist/server/projectSearch.js +2 -1
- package/dist/server/projectTemplateCache.js +94 -0
- package/dist/server/projectTemplateDownload.js +75 -0
- package/dist/server/projectTextSave.js +56 -0
- package/dist/server/routes/agents.js +2 -15
- package/dist/server/routes/compile.js +67 -9
- package/dist/server/routes/drawio.js +192 -0
- package/dist/server/routes/projectFiles.js +106 -20
- package/dist/server/routes/projects.js +81 -20
- package/dist/server/routes/users.js +10 -14
- package/dist/server/synctex.js +20 -3
- package/dist/server/texcount.js +27 -23
- package/dist/server/zip.js +37 -11
- package/dist/shared/drawio.js +79 -0
- package/dist/shared/fileTypes.js +1 -1
- package/dist/shared/pdfFonts.js +14 -0
- package/dist/shared/projectImport.js +21 -0
- package/package.json +3 -1
- package/dist/client/assets/AdminUsers-C-8tXzvj.js +0 -1
- package/dist/client/assets/AdminUsers-C-8tXzvj.js.br +0 -0
- package/dist/client/assets/AdminUsers-C-8tXzvj.js.gz +0 -0
- package/dist/client/assets/AgentManagement-DXgfP7l_.js +0 -1
- package/dist/client/assets/AgentManagement-DXgfP7l_.js.br +0 -0
- package/dist/client/assets/AgentManagement-DXgfP7l_.js.gz +0 -0
- package/dist/client/assets/AgentTerminal-DD4sskCS.js +0 -2
- package/dist/client/assets/AgentTerminal-DD4sskCS.js.br +0 -0
- package/dist/client/assets/AgentTerminal-DD4sskCS.js.gz +0 -0
- package/dist/client/assets/AgentTerminalSurface-DliOcop5.js.gz +0 -0
- package/dist/client/assets/AvatarSettingsDialog-iuEbMO4a.js.br +0 -0
- package/dist/client/assets/AvatarSettingsDialog-iuEbMO4a.js.gz +0 -0
- package/dist/client/assets/CitationBibtexEditor-CDiYDj3M.js +0 -1
- package/dist/client/assets/CitationLibraryDialog-CJlL-Ytx.js +0 -3
- package/dist/client/assets/CitationLibraryDialog-CJlL-Ytx.js.br +0 -0
- package/dist/client/assets/CitationLibraryDialog-CJlL-Ytx.js.gz +0 -0
- package/dist/client/assets/Dashboard-DqwGd9wd.js +0 -5
- package/dist/client/assets/Dashboard-DqwGd9wd.js.br +0 -0
- package/dist/client/assets/Dashboard-DqwGd9wd.js.gz +0 -0
- package/dist/client/assets/GitDialog-DUGAigLx.js +0 -4
- package/dist/client/assets/GitDialog-DUGAigLx.js.br +0 -0
- package/dist/client/assets/GitDialog-DUGAigLx.js.gz +0 -0
- package/dist/client/assets/GitHubAccountDialog-B4eD622i.js +0 -1
- package/dist/client/assets/GitHubAccountDialog-B4eD622i.js.br +0 -0
- package/dist/client/assets/GitHubAccountDialog-B4eD622i.js.gz +0 -0
- package/dist/client/assets/HistoryDialog-upkR8E0L.js.br +0 -0
- package/dist/client/assets/HistoryDialog-upkR8E0L.js.gz +0 -0
- package/dist/client/assets/InfoPopover-CQ3Q10tN.js +0 -1
- package/dist/client/assets/LatexEditor-DvDYTc0r.js +0 -25
- package/dist/client/assets/LatexEditor-DvDYTc0r.js.br +0 -0
- package/dist/client/assets/LatexEditor-DvDYTc0r.js.gz +0 -0
- package/dist/client/assets/MarkdownPreview-_AXp5G7f.js.br +0 -0
- package/dist/client/assets/MarkdownPreview-_AXp5G7f.js.gz +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-BxjEYsau.js.br +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-BxjEYsau.js.gz +0 -0
- package/dist/client/assets/ProjectSearchDialog-BB8thfK9.js +0 -1
- package/dist/client/assets/ProjectSearchDialog-BB8thfK9.js.br +0 -0
- package/dist/client/assets/ProjectSearchDialog-BB8thfK9.js.gz +0 -0
- package/dist/client/assets/ProjectSettings-Dx-b26uN.js +0 -4
- package/dist/client/assets/ProjectSettings-Dx-b26uN.js.br +0 -0
- package/dist/client/assets/ProjectSettings-Dx-b26uN.js.gz +0 -0
- package/dist/client/assets/ProjectWorkspace-DiurYeU1.js +0 -25
- package/dist/client/assets/ProjectWorkspace-DiurYeU1.js.br +0 -0
- package/dist/client/assets/ProjectWorkspace-DiurYeU1.js.gz +0 -0
- package/dist/client/assets/QuickOpenDialog-HlkWqVR9.js.br +0 -0
- package/dist/client/assets/QuickOpenDialog-HlkWqVR9.js.gz +0 -0
- package/dist/client/assets/SelectionHistoryDialog-Cb8I-G6m.js.br +0 -0
- package/dist/client/assets/SelectionHistoryDialog-Cb8I-G6m.js.gz +0 -0
- package/dist/client/assets/SharedProjectPage-BBLOLjnD.js +0 -2
- package/dist/client/assets/SharedProjectPage-BBLOLjnD.js.br +0 -0
- package/dist/client/assets/SharedProjectPage-BBLOLjnD.js.gz +0 -0
- package/dist/client/assets/SystemMetricsDialog-Dr4pYWG6.js +0 -1
- package/dist/client/assets/SystemMetricsDialog-Dr4pYWG6.js.br +0 -0
- package/dist/client/assets/SystemMetricsDialog-Dr4pYWG6.js.gz +0 -0
- package/dist/client/assets/TagManagementDialog-D4fYVboy.js +0 -1
- package/dist/client/assets/TagManagementDialog-D4fYVboy.js.br +0 -0
- package/dist/client/assets/TagManagementDialog-D4fYVboy.js.gz +0 -0
- package/dist/client/assets/ThemeSwitcher-BgzkYTeA.js +0 -1
- package/dist/client/assets/TikzGalleryDialog-cPUDQ5Wj.js.br +0 -0
- package/dist/client/assets/TikzGalleryDialog-cPUDQ5Wj.js.gz +0 -0
- package/dist/client/assets/WordCountDialog-AiuR3rra.js.br +0 -0
- package/dist/client/assets/WordCountDialog-AiuR3rra.js.gz +0 -0
- package/dist/client/assets/dist-DdUqlCPw.js +0 -1
- package/dist/client/assets/dist-DdUqlCPw.js.br +0 -0
- package/dist/client/assets/dist-DdUqlCPw.js.gz +0 -0
- package/dist/client/assets/i18n-Dpk6KCs6.js +0 -13
- package/dist/client/assets/i18n-Dpk6KCs6.js.br +0 -0
- package/dist/client/assets/i18n-Dpk6KCs6.js.gz +0 -0
- package/dist/client/assets/index-B1vejuOw.js +0 -2
- package/dist/client/assets/index-B1vejuOw.js.br +0 -0
- package/dist/client/assets/index-B1vejuOw.js.gz +0 -0
- package/dist/client/assets/index-Blr4J_Pq.css +0 -1
- package/dist/client/assets/index-Blr4J_Pq.css.br +0 -0
- package/dist/client/assets/index-Blr4J_Pq.css.gz +0 -0
- package/dist/client/assets/relativeTime-CcP1IEvr.js +0 -1
- package/dist/client/assets/relativeTime-CcP1IEvr.js.br +0 -0
- package/dist/client/assets/relativeTime-CcP1IEvr.js.gz +0 -0
- package/dist/client/assets/sourceCursorStore-EycYBVxj.js +0 -1
- package/dist/client/assets/sourceCursorStore-EycYBVxj.js.br +0 -0
- package/dist/client/assets/sourceCursorStore-EycYBVxj.js.gz +0 -0
- package/dist/client/assets/spellCheck-DpWPgtM7.js.br +0 -0
- package/dist/client/assets/spellCheck-DpWPgtM7.js.gz +0 -0
- package/dist/client/assets/useDeletionTransitions-DvxVkRuo.js +0 -1
- package/dist/client/assets/useDeletionTransitions-DvxVkRuo.js.br +0 -0
- package/dist/client/assets/useDeletionTransitions-DvxVkRuo.js.gz +0 -0
|
@@ -3,17 +3,19 @@ import { parseByteRange } from "../byteRange.js";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { performance } from "node:perf_hooks";
|
|
6
|
+
import { isEngine } from "../config.js";
|
|
6
7
|
import { requireUser } from "../auth.js";
|
|
7
8
|
import { accessibleProject, canEdit } from "../projects.js";
|
|
8
|
-
import { outputRoot, resolveSourcePath, safeRelativePath, texFileStem } from "../files.js";
|
|
9
|
+
import { outputRoot, renameProjectPath, resolveSourcePath, safeRelativePath, texFileStem } from "../files.js";
|
|
9
10
|
import { isStandaloneTikz } from "../../shared/tikzStandalone.js";
|
|
10
11
|
import { touchProject } from "./projectShared.js";
|
|
11
12
|
import { captureCompileSnapshot, cleanCompileArtifacts, cleanCompileCache, CompileCancelledError, compileProject, discardCompileSnapshot, hasCompileCache, publishCompileArtifacts, publishedCompileArtifacts } from "../compiler.js";
|
|
12
13
|
import { parseCompileDiagnostics } from "../compileDiagnostics.js";
|
|
13
14
|
import { pdfToSource, sourceToPdf } from "../synctex.js";
|
|
15
|
+
import { inspectPdfFonts } from "../pdfFonts.js";
|
|
14
16
|
import { availablePdf, compileRunPdf, compileMainFile, compilePdfUrl, isTextCompileArtifact, listCompileArtifacts, pdfLoadingMode, syncArtifacts } from "../compileArtifacts.js";
|
|
15
17
|
import { MAX_TEXT_PREVIEW_BYTES } from "../limits.js";
|
|
16
|
-
import { apiError, contentDisposition, httpError } from "../http.js";
|
|
18
|
+
import { apiError, contentDisposition, httpError, HttpError } from "../http.js";
|
|
17
19
|
const now = () => new Date().toISOString();
|
|
18
20
|
const timingDuration = (milliseconds) => Math.round(milliseconds * 10) / 10;
|
|
19
21
|
const MAX_SNAPSHOT_ATTEMPTS = 3;
|
|
@@ -89,6 +91,55 @@ export function registerCompileRoutes(app, context) {
|
|
|
89
91
|
...pdfMetadata
|
|
90
92
|
};
|
|
91
93
|
});
|
|
94
|
+
app.get("/api/projects/:id/compile/fonts", async (request, reply) => {
|
|
95
|
+
const user = requireUser(request, reply, db);
|
|
96
|
+
if (!user)
|
|
97
|
+
return;
|
|
98
|
+
const { id } = request.params;
|
|
99
|
+
const project = accessibleProject(db, id, user);
|
|
100
|
+
if (!project)
|
|
101
|
+
return apiError(reply, 404, "PROJECT_NOT_FOUND");
|
|
102
|
+
const query = request.query;
|
|
103
|
+
const mainFile = compileMainFile(config, id, project.main_file, query.mainFile);
|
|
104
|
+
if (!mainFile)
|
|
105
|
+
return apiError(reply, 400, "MAIN_DOCUMENT_INVALID");
|
|
106
|
+
// Require the displayed PDF's immutable run identity, never the latest log's run.
|
|
107
|
+
if (!query.run || !/^[a-f0-9-]{36}$/i.test(query.run))
|
|
108
|
+
return apiError(reply, 404, "PDF_NOT_FOUND");
|
|
109
|
+
const run = db.prepare(`SELECT id FROM compile_runs
|
|
110
|
+
WHERE id = ? AND project_id = ? AND main_file = ? AND status = 'succeeded'`).get(query.run, id, mainFile);
|
|
111
|
+
const pdf = run ? compileRunPdf(config, id, mainFile, query.run) : null;
|
|
112
|
+
if (!pdf)
|
|
113
|
+
return apiError(reply, 404, "PDF_NOT_FOUND");
|
|
114
|
+
const controller = new AbortController();
|
|
115
|
+
const cancel = () => { if (!reply.raw.writableEnded)
|
|
116
|
+
controller.abort(); };
|
|
117
|
+
reply.raw.once("close", cancel);
|
|
118
|
+
reply.header("Cache-Control", "private, no-store");
|
|
119
|
+
try {
|
|
120
|
+
const result = await inspectPdfFonts(pdf.path, controller.signal);
|
|
121
|
+
if (controller.signal.aborted)
|
|
122
|
+
return;
|
|
123
|
+
// Project membership can change while a host tool is running.
|
|
124
|
+
if (!accessibleProject(db, id, user))
|
|
125
|
+
return apiError(reply, 404, "PROJECT_NOT_FOUND");
|
|
126
|
+
return { mainFile, runId: query.run, ...result };
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (controller.signal.aborted)
|
|
130
|
+
return;
|
|
131
|
+
if (!accessibleProject(db, id, user))
|
|
132
|
+
return apiError(reply, 404, "PROJECT_NOT_FOUND");
|
|
133
|
+
if (!regularFileStat(pdf.path))
|
|
134
|
+
return apiError(reply, 404, "PDF_NOT_FOUND");
|
|
135
|
+
if (error instanceof HttpError)
|
|
136
|
+
return apiError(reply, error.statusCode, error.code);
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
reply.raw.removeListener("close", cancel);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
92
143
|
app.get("/api/projects/:id/compile/artifacts", async (request, reply) => {
|
|
93
144
|
const user = requireUser(request, reply, db);
|
|
94
145
|
if (!user)
|
|
@@ -329,7 +380,7 @@ export function registerCompileRoutes(app, context) {
|
|
|
329
380
|
const staged = path.join(outputRoot(config, id), `.export-${randomUUID()}.pdf`);
|
|
330
381
|
try {
|
|
331
382
|
fs.copyFileSync(pdf.path, staged);
|
|
332
|
-
|
|
383
|
+
renameProjectPath(staged, destination);
|
|
333
384
|
}
|
|
334
385
|
finally {
|
|
335
386
|
fs.rmSync(staged, { force: true });
|
|
@@ -364,12 +415,18 @@ export function registerCompileRoutes(app, context) {
|
|
|
364
415
|
if (!initialProject || !canEdit(initialProject))
|
|
365
416
|
return apiError(reply, 403, "COMPILE_FORBIDDEN");
|
|
366
417
|
const body = (request.body ?? {});
|
|
367
|
-
const requestedEngine =
|
|
368
|
-
if (
|
|
418
|
+
const requestedEngine = body.engine;
|
|
419
|
+
if (requestedEngine !== undefined && !isEngine(requestedEngine))
|
|
369
420
|
return apiError(reply, 400, "REQUEST_INVALID");
|
|
370
421
|
// For this run only; part of the compile generation and cache key, so a
|
|
371
422
|
// request for another engine is neither coalesced nor treated as up to date.
|
|
372
|
-
const withRequestedEngine = (row) =>
|
|
423
|
+
const withRequestedEngine = (row) => {
|
|
424
|
+
const engine = requestedEngine ?? row.engine;
|
|
425
|
+
if (!config.allowedEngines.includes(engine))
|
|
426
|
+
throw httpError(422, "LATEX_ENGINE_UNAVAILABLE", { engine });
|
|
427
|
+
return engine === row.engine ? row : { ...row, engine };
|
|
428
|
+
};
|
|
429
|
+
withRequestedEngine(initialProject);
|
|
373
430
|
const requestedMainFile = typeof body.mainFile === "string" && body.mainFile ? body.mainFile : null;
|
|
374
431
|
const initialMainFile = compileMainFile(config, id, initialProject.main_file, body.mainFile);
|
|
375
432
|
if (!initialMainFile)
|
|
@@ -399,10 +456,11 @@ export function registerCompileRoutes(app, context) {
|
|
|
399
456
|
throw new Error("Project access changed while preparing a compile request");
|
|
400
457
|
}
|
|
401
458
|
const generationRevision = receipt?.revision ?? revisionBeforeFlush;
|
|
459
|
+
const project = withRequestedEngine(refreshedProject);
|
|
402
460
|
const admissionResult = {
|
|
403
|
-
project
|
|
461
|
+
project,
|
|
404
462
|
mainFile: currentMainFile,
|
|
405
|
-
generation: compileRequestGeneration(
|
|
463
|
+
generation: compileRequestGeneration(project, generationRevision, collaboration.currentGeneration(id), config.extraArgs)
|
|
406
464
|
};
|
|
407
465
|
// Insert the queued probe while the project lock is still held. A
|
|
408
466
|
// concurrent clean request must observe this row before the compile
|
|
@@ -598,7 +656,7 @@ export function registerCompileRoutes(app, context) {
|
|
|
598
656
|
if (!db.prepare("SELECT 1 FROM projects WHERE id = ?").get(id)) {
|
|
599
657
|
throw new Error("Project was deleted before compile artifacts could be published.");
|
|
600
658
|
}
|
|
601
|
-
publishCompileArtifacts(config, id, snapshot, compiled);
|
|
659
|
+
publishCompileArtifacts(config, id, snapshot, compiled, (err, directory) => app.log.warn({ err, directory }, "Could not remove a retired compile run"));
|
|
602
660
|
}, { flush: false });
|
|
603
661
|
refreshSnapshotStale();
|
|
604
662
|
if (compiled.timings) {
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
|
+
import { currentUser, requireUser } from "../auth.js";
|
|
5
|
+
import { browserOriginAllowed } from "../browserOrigin.js";
|
|
6
|
+
import { outputRoot, renameProjectPath, resolveSourcePath, safeRelativePath } from "../files.js";
|
|
7
|
+
import { accessibleProject, canEdit } from "../projects.js";
|
|
8
|
+
import { apiError, HttpError, httpError } from "../http.js";
|
|
9
|
+
import { requireEditableProject, touchProject } from "./projectShared.js";
|
|
10
|
+
import { reanchorFileComments } from "../anchors.js";
|
|
11
|
+
import { DrawioPdfRenderer } from "../drawioPdf.js";
|
|
12
|
+
import { saveProjectText } from "../projectTextSave.js";
|
|
13
|
+
import { drawioPdfPath, isDrawioFile } from "../../shared/drawio.js";
|
|
14
|
+
import { isTextContent } from "../../shared/fileTypes.js";
|
|
15
|
+
const maxDiagramBytes = 5 * 1024 * 1024;
|
|
16
|
+
const hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
17
|
+
function diagramPath(value) {
|
|
18
|
+
const relative = safeRelativePath(typeof value === "string" ? value : "");
|
|
19
|
+
if (!isDrawioFile(relative))
|
|
20
|
+
throw httpError(400, "DRAWIO_INVALID");
|
|
21
|
+
return relative;
|
|
22
|
+
}
|
|
23
|
+
function readDiagram(absolute) {
|
|
24
|
+
if (!fs.existsSync(absolute) || !fs.statSync(absolute).isFile())
|
|
25
|
+
throw httpError(404, "FILE_NOT_FOUND");
|
|
26
|
+
if (fs.statSync(absolute).size > maxDiagramBytes)
|
|
27
|
+
throw httpError(413, "DRAWIO_INVALID");
|
|
28
|
+
const bytes = fs.readFileSync(absolute);
|
|
29
|
+
if (!isTextContent(bytes))
|
|
30
|
+
throw httpError(400, "DRAWIO_INVALID");
|
|
31
|
+
return bytes.toString("utf8");
|
|
32
|
+
}
|
|
33
|
+
function validateXml(content, limit) {
|
|
34
|
+
if (typeof content !== "string" || Buffer.byteLength(content) > limit || !isTextContent(Buffer.from(content))
|
|
35
|
+
|| !/^\s*(?:<\?xml[^>]*>\s*)?<(?:mxfile|mxGraphModel)(?:\s|>)/.test(content)
|
|
36
|
+
|| /<!DOCTYPE/i.test(content))
|
|
37
|
+
throw httpError(400, "DRAWIO_INVALID");
|
|
38
|
+
}
|
|
39
|
+
function pdfRevision(absolute) {
|
|
40
|
+
if (!fs.existsSync(absolute))
|
|
41
|
+
return null;
|
|
42
|
+
if (!fs.statSync(absolute).isFile())
|
|
43
|
+
throw httpError(409, "PATH_EXISTS");
|
|
44
|
+
// Only detect replacement conflicts; do not read an existing large PDF.
|
|
45
|
+
const stat = fs.statSync(absolute, { bigint: true });
|
|
46
|
+
return hash(`${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`);
|
|
47
|
+
}
|
|
48
|
+
function writeAtomic(absolute, bytes) {
|
|
49
|
+
const temporary = path.join(path.dirname(absolute), `.texlite-drawio-${randomUUID()}.tmp`);
|
|
50
|
+
try {
|
|
51
|
+
fs.writeFileSync(temporary, bytes, { mode: 0o600, flag: "wx" });
|
|
52
|
+
renameProjectPath(temporary, absolute);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
fs.rmSync(temporary, { force: true });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function registerDrawioRoutes(app, { config, db, collaboration, projectMutations, recordHistory }) {
|
|
59
|
+
const renderer = new DrawioPdfRenderer((err) => app.log.warn({ err }, "draw.io browser export failed"));
|
|
60
|
+
const locks = projectMutations.drawioLocks;
|
|
61
|
+
// Cancel Windows browser jobs before Fastify waits for in-flight exports.
|
|
62
|
+
app.addHook(process.platform === "win32" ? "preClose" : "onClose", async () => { await renderer.close(); });
|
|
63
|
+
app.get("/api/projects/:id/drawio/lock", { websocket: true }, (socket, request) => {
|
|
64
|
+
const user = currentUser(request, db);
|
|
65
|
+
if (!user || user.must_change_password || !browserOriginAllowed(request)) {
|
|
66
|
+
socket.close(1008, "Access denied");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const { id } = request.params;
|
|
70
|
+
const valid = () => {
|
|
71
|
+
const current = currentUser(request, db, true);
|
|
72
|
+
const project = current && !current.must_change_password ? accessibleProject(db, id, current) : null;
|
|
73
|
+
return Boolean(project && canEdit(project));
|
|
74
|
+
};
|
|
75
|
+
socket.on("error", () => { });
|
|
76
|
+
let relative;
|
|
77
|
+
try {
|
|
78
|
+
relative = diagramPath(request.query.path);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
socket.close(1008, "Invalid diagram");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
void projectMutations.runFilesystemRead(id, () => {
|
|
85
|
+
if (socket.readyState !== 1)
|
|
86
|
+
return;
|
|
87
|
+
const content = readDiagram(resolveSourcePath(config, id, relative));
|
|
88
|
+
validateXml(content, maxDiagramBytes);
|
|
89
|
+
locks.acquire(id, relative, user.id, user.display_name, socket, valid, hash(content));
|
|
90
|
+
}, { preflight: () => { if (!valid())
|
|
91
|
+
throw httpError(403, "PROJECT_EDIT_FORBIDDEN"); } })
|
|
92
|
+
.catch(() => { socket.close(1008, "Diagram unavailable"); });
|
|
93
|
+
});
|
|
94
|
+
app.get("/api/projects/:id/drawio", async (request, reply) => {
|
|
95
|
+
const user = requireUser(request, reply, db);
|
|
96
|
+
if (!user)
|
|
97
|
+
return;
|
|
98
|
+
const { id } = request.params;
|
|
99
|
+
if (!accessibleProject(db, id, user))
|
|
100
|
+
return apiError(reply, 404, "PROJECT_NOT_FOUND");
|
|
101
|
+
const relative = diagramPath(request.query.path);
|
|
102
|
+
reply.header("Cache-Control", "private, no-store");
|
|
103
|
+
// Diagrams are not Yjs documents. Keep the filesystem mutation barrier,
|
|
104
|
+
// without making the editor wait for unrelated room hydration.
|
|
105
|
+
return projectMutations.runFilesystemRead(id, () => {
|
|
106
|
+
const content = readDiagram(resolveSourcePath(config, id, relative));
|
|
107
|
+
validateXml(content, maxDiagramBytes);
|
|
108
|
+
return { content, revision: hash(content), pdfRevision: pdfRevision(resolveSourcePath(config, id, drawioPdfPath(relative))) };
|
|
109
|
+
}, { preflight: () => { if (!accessibleProject(db, id, user))
|
|
110
|
+
throw httpError(404, "PROJECT_NOT_FOUND"); } });
|
|
111
|
+
});
|
|
112
|
+
app.put("/api/projects/:id/drawio", { bodyLimit: 6 * 1024 * 1024 }, async (request, reply) => {
|
|
113
|
+
const user = requireUser(request, reply, db);
|
|
114
|
+
if (!user)
|
|
115
|
+
return;
|
|
116
|
+
const { id } = request.params;
|
|
117
|
+
requireEditableProject(db, id, user);
|
|
118
|
+
const body = request.body;
|
|
119
|
+
const relative = diagramPath(body.path);
|
|
120
|
+
validateXml(body.content, Math.min(maxDiagramBytes, config.maxUploadBytes));
|
|
121
|
+
const content = body.content;
|
|
122
|
+
return projectMutations.runWrite(id, () => {
|
|
123
|
+
locks.assertOwned(id, relative, body.lockToken, user.id);
|
|
124
|
+
const absolute = resolveSourcePath(config, id, relative);
|
|
125
|
+
const previous = readDiagram(absolute);
|
|
126
|
+
// A lost response can leave the browser retrying the same save with its
|
|
127
|
+
// old revision. Acknowledge identical bytes without another write.
|
|
128
|
+
if (previous === content)
|
|
129
|
+
return { revision: hash(previous) };
|
|
130
|
+
if (hash(previous) !== body.revision)
|
|
131
|
+
throw httpError(409, "DRAWIO_CONFLICT");
|
|
132
|
+
saveProjectText(db, outputRoot(config, id), absolute, Buffer.from(content, "utf8"), fs.statSync(absolute), () => {
|
|
133
|
+
reanchorFileComments(db, id, relative, previous, content);
|
|
134
|
+
touchProject(db, id, user.id);
|
|
135
|
+
}, (err, directory) => app.log.warn({ err, directory }, "Could not clean up diagram save staging"));
|
|
136
|
+
collaboration.invalidateSourceTree(id, relative);
|
|
137
|
+
recordHistory(id, user.id, "autosave", [relative]);
|
|
138
|
+
return { revision: hash(content) };
|
|
139
|
+
}, { preflight: () => { requireEditableProject(db, id, user); locks.assertOwned(id, relative, body.lockToken, user.id); } });
|
|
140
|
+
});
|
|
141
|
+
app.post("/api/projects/:id/drawio/pdf", { bodyLimit: 12 * 1024 * 1024 }, async (request, reply) => {
|
|
142
|
+
const user = requireUser(request, reply, db);
|
|
143
|
+
if (!user)
|
|
144
|
+
return;
|
|
145
|
+
const { id } = request.params;
|
|
146
|
+
requireEditableProject(db, id, user);
|
|
147
|
+
const body = request.body;
|
|
148
|
+
const relative = diagramPath(body.path), output = drawioPdfPath(relative);
|
|
149
|
+
if (typeof body.svg !== "string" || Buffer.byteLength(body.svg) > 10 * 1024 * 1024
|
|
150
|
+
|| !/^\s*(?:<\?xml[^>]*>\s*)?(?:<!DOCTYPE[^>]*>\s*)?<svg[\s>]/i.test(body.svg))
|
|
151
|
+
return apiError(reply, 400, "DRAWIO_INVALID");
|
|
152
|
+
const validate = () => {
|
|
153
|
+
requireEditableProject(db, id, user);
|
|
154
|
+
locks.assertOwned(id, relative, body.lockToken, user.id);
|
|
155
|
+
if (hash(readDiagram(resolveSourcePath(config, id, relative))) !== body.revision
|
|
156
|
+
|| pdfRevision(resolveSourcePath(config, id, output)) !== body.pdfRevision)
|
|
157
|
+
throw httpError(409, "DRAWIO_CONFLICT");
|
|
158
|
+
};
|
|
159
|
+
// Validate before spawning, but never hold the project write queue while
|
|
160
|
+
// rendering. Recheck source, output, and permissions at the actual write.
|
|
161
|
+
await projectMutations.runConsistentRead(id, validate, { preflight: () => { requireEditableProject(db, id, user); } });
|
|
162
|
+
const controller = new AbortController();
|
|
163
|
+
const cancel = () => { if (!reply.raw.writableEnded)
|
|
164
|
+
controller.abort(); };
|
|
165
|
+
reply.raw.on("close", cancel);
|
|
166
|
+
try {
|
|
167
|
+
const pdf = await renderer.render(body.svg, config.drawioBrowserPath, controller.signal);
|
|
168
|
+
controller.signal.throwIfAborted();
|
|
169
|
+
return await projectMutations.runWrite(id, () => {
|
|
170
|
+
controller.signal.throwIfAborted();
|
|
171
|
+
validate();
|
|
172
|
+
const absolute = resolveSourcePath(config, id, output);
|
|
173
|
+
writeAtomic(absolute, pdf);
|
|
174
|
+
touchProject(db, id, user.id);
|
|
175
|
+
collaboration.invalidateSourceTree(id, output);
|
|
176
|
+
recordHistory(id, user.id, "file", [output]);
|
|
177
|
+
return { path: output, pdfRevision: pdfRevision(absolute) };
|
|
178
|
+
}, { preflight: validate });
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
if (controller.signal.aborted)
|
|
182
|
+
return;
|
|
183
|
+
requireEditableProject(db, id, user);
|
|
184
|
+
if (error instanceof HttpError)
|
|
185
|
+
return apiError(reply, error.statusCode, error.code, error.details);
|
|
186
|
+
return apiError(reply, 422, "DRAWIO_EXPORT_FAILED");
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
reply.raw.off("close", cancel);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
@@ -8,11 +8,14 @@ import { requireUser } from "../auth.js";
|
|
|
8
8
|
import { reanchorFileComments } from "../anchors.js";
|
|
9
9
|
import { isCollaborativeTextFile, maxCollaborativeFileBytes } from "../collaboration.js";
|
|
10
10
|
import { compileMainFile } from "../compileArtifacts.js";
|
|
11
|
-
import { assertNoSourceSymlinks, listProjectFilesAsync, resolveSourcePath, safePathSegment, safeRelativePath, sourceRoot } from "../files.js";
|
|
12
|
-
import { apiError, contentDisposition, httpError } from "../http.js";
|
|
11
|
+
import { assertNoSourceSymlinks, listProjectFilesAsync, outputRoot, removeProjectSourcePath, renameProjectPath, resolveProjectMoveDestination, resolveSourcePath, safePathSegment, safeRelativePath, sourceRoot } from "../files.js";
|
|
12
|
+
import { apiError, contentDisposition, HttpError, httpError } from "../http.js";
|
|
13
|
+
import { saveProjectText } from "../projectTextSave.js";
|
|
13
14
|
import { moveEditHistoryPaths } from "../editHistory.js";
|
|
14
15
|
import { accessibleProject, canEdit } from "../projects.js";
|
|
15
16
|
import { mainDocumentCandidates } from "../latexRoot.js";
|
|
17
|
+
import { inspectPdfFonts } from "../pdfFonts.js";
|
|
18
|
+
import { DRAWIO_LOCK_HEADER } from "../../shared/drawio.js";
|
|
16
19
|
import { isTextContent } from "../../shared/fileTypes.js";
|
|
17
20
|
import { commentsForFile, escapeGlobPattern, movedProjectPath, now, requireEditableProject, touchProject } from "./projectShared.js";
|
|
18
21
|
/** Register project file-tree, editor content, and upload routes. */
|
|
@@ -133,6 +136,7 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
133
136
|
const absolute = resolveSourcePath(config, id, folderPath);
|
|
134
137
|
if (fs.existsSync(absolute))
|
|
135
138
|
return apiError(reply, 409, "PATH_EXISTS", { path: folderPath });
|
|
139
|
+
projectMutations.drawioLocks.assertUnlocked(id, [folderPath]);
|
|
136
140
|
fs.mkdirSync(absolute, { recursive: true, mode: 0o700 });
|
|
137
141
|
touchProject(db, id, user.id);
|
|
138
142
|
// Empty folders have no file entry to trigger a refresh on their own.
|
|
@@ -183,12 +187,11 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
183
187
|
if (!fs.existsSync(destinationRoot) || !fs.statSync(destinationRoot).isDirectory()) {
|
|
184
188
|
return apiError(reply, 404, "DIRECTORY_NOT_FOUND", { path: destinationDirectory });
|
|
185
189
|
}
|
|
186
|
-
const destinationAbsolute =
|
|
187
|
-
if (fs.existsSync(destinationAbsolute))
|
|
188
|
-
return apiError(reply, 409, "PATH_EXISTS", { path: destination });
|
|
190
|
+
const destinationAbsolute = resolveProjectMoveDestination(config, id, source, destination);
|
|
189
191
|
let currentProject = project;
|
|
190
192
|
const validateMove = () => {
|
|
191
193
|
currentProject = requireEditableProject(db, id, user);
|
|
194
|
+
projectMutations.drawioLocks.assertUnlocked(id, [source, destination]);
|
|
192
195
|
assertNoSourceSymlinks(config, id);
|
|
193
196
|
if (source === currentProject.main_file && !/\.tex$/i.test(destination)) {
|
|
194
197
|
throw httpError(400, "MAIN_DOCUMENT_INVALID");
|
|
@@ -203,9 +206,7 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
203
206
|
if (!fs.existsSync(destinationRoot) || !fs.statSync(destinationRoot).isDirectory()) {
|
|
204
207
|
throw httpError(404, "DIRECTORY_NOT_FOUND", { path: destinationDirectory });
|
|
205
208
|
}
|
|
206
|
-
|
|
207
|
-
throw httpError(409, "PATH_EXISTS", { path: destination });
|
|
208
|
-
}
|
|
209
|
+
resolveProjectMoveDestination(config, id, source, destination);
|
|
209
210
|
};
|
|
210
211
|
// Moving/renaming is collaboration-aware: movePath() remaps the live Yjs
|
|
211
212
|
// texts and publishes a files event. It therefore needs the ordinary
|
|
@@ -213,7 +214,7 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
213
214
|
// epoch and makes every connected browser reload after an otherwise safe
|
|
214
215
|
// drag-and-drop move.
|
|
215
216
|
return await projectMutations.runWrite(id, () => {
|
|
216
|
-
|
|
217
|
+
renameProjectPath(sourceAbsolute, destinationAbsolute);
|
|
217
218
|
let hasCommentUpdates = false;
|
|
218
219
|
db.exec("BEGIN IMMEDIATE");
|
|
219
220
|
try {
|
|
@@ -246,6 +247,68 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
246
247
|
return { ok: true, path: destination };
|
|
247
248
|
}, { preflight: validateMove });
|
|
248
249
|
});
|
|
250
|
+
app.get("/api/projects/:id/file/fonts", async (request, reply) => {
|
|
251
|
+
const user = requireUser(request, reply, db);
|
|
252
|
+
if (!user)
|
|
253
|
+
return;
|
|
254
|
+
const { id } = request.params;
|
|
255
|
+
if (!accessibleProject(db, id, user))
|
|
256
|
+
return apiError(reply, 404, "PROJECT_NOT_FOUND");
|
|
257
|
+
const query = request.query;
|
|
258
|
+
const filePath = safeRelativePath(typeof query.path === "string" ? query.path : "");
|
|
259
|
+
if (!/\.pdf$/i.test(filePath))
|
|
260
|
+
return apiError(reply, 400, "REQUEST_INVALID");
|
|
261
|
+
const controller = new AbortController();
|
|
262
|
+
const cancel = () => { if (!reply.raw.writableEnded)
|
|
263
|
+
controller.abort(); };
|
|
264
|
+
reply.raw.once("close", cancel);
|
|
265
|
+
reply.header("Cache-Control", "private, no-store");
|
|
266
|
+
let temporaryDirectory;
|
|
267
|
+
try {
|
|
268
|
+
const temporaryRoot = path.join(config.dataDir, "tmp");
|
|
269
|
+
await fs.promises.mkdir(temporaryRoot, { recursive: true, mode: 0o700 });
|
|
270
|
+
temporaryDirectory = await fs.promises.mkdtemp(path.join(temporaryRoot, "pdf-fonts-"));
|
|
271
|
+
const snapshot = path.join(temporaryDirectory, "document.pdf");
|
|
272
|
+
// Inspect stable bytes without holding the source-tree queue while a
|
|
273
|
+
// host process runs. Moving/replacing the original cannot change this copy.
|
|
274
|
+
await projectMutations.runFilesystemRead(id, async () => {
|
|
275
|
+
const absolute = resolveSourcePath(config, id, filePath);
|
|
276
|
+
const stat = await fs.promises.stat(absolute).catch((error) => {
|
|
277
|
+
if (error.code === "ENOENT" || error.code === "ENOTDIR")
|
|
278
|
+
return null;
|
|
279
|
+
throw error;
|
|
280
|
+
});
|
|
281
|
+
if (!stat?.isFile())
|
|
282
|
+
throw httpError(404, "FILE_NOT_FOUND", { path: filePath });
|
|
283
|
+
await fs.promises.copyFile(absolute, snapshot);
|
|
284
|
+
}, { preflight: () => {
|
|
285
|
+
if (controller.signal.aborted)
|
|
286
|
+
throw new DOMException("Aborted", "AbortError");
|
|
287
|
+
if (!accessibleProject(db, id, user))
|
|
288
|
+
throw httpError(404, "PROJECT_NOT_FOUND");
|
|
289
|
+
} });
|
|
290
|
+
const result = await inspectPdfFonts(snapshot, controller.signal);
|
|
291
|
+
if (controller.signal.aborted)
|
|
292
|
+
return;
|
|
293
|
+
if (!accessibleProject(db, id, user))
|
|
294
|
+
return apiError(reply, 404, "PROJECT_NOT_FOUND");
|
|
295
|
+
return { path: filePath, ...result };
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
if (controller.signal.aborted)
|
|
299
|
+
return;
|
|
300
|
+
if (!accessibleProject(db, id, user))
|
|
301
|
+
return apiError(reply, 404, "PROJECT_NOT_FOUND");
|
|
302
|
+
if (error instanceof HttpError)
|
|
303
|
+
return apiError(reply, error.statusCode, error.code, error.details);
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
306
|
+
finally {
|
|
307
|
+
reply.raw.removeListener("close", cancel);
|
|
308
|
+
if (temporaryDirectory)
|
|
309
|
+
await fs.promises.rm(temporaryDirectory, { recursive: true, force: true }).catch(() => undefined);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
249
312
|
app.get("/api/projects/:id/file/raw", async (request, reply) => {
|
|
250
313
|
const user = requireUser(request, reply, db);
|
|
251
314
|
if (!user)
|
|
@@ -348,6 +411,7 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
348
411
|
}
|
|
349
412
|
return await projectMutations.runWrite(id, () => {
|
|
350
413
|
const absolute = resolveSourcePath(config, id, filePath);
|
|
414
|
+
projectMutations.drawioLocks.assertUnlocked(id, [filePath]);
|
|
351
415
|
try {
|
|
352
416
|
fs.mkdirSync(path.dirname(absolute), { recursive: true, mode: 0o700 });
|
|
353
417
|
}
|
|
@@ -367,7 +431,10 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
367
431
|
throw error;
|
|
368
432
|
}
|
|
369
433
|
touchProject(db, id, user.id);
|
|
370
|
-
|
|
434
|
+
if (isCollaborativeTextFile(filePath))
|
|
435
|
+
collaboration.updateFile(id, filePath, content, user.id);
|
|
436
|
+
else
|
|
437
|
+
collaboration.invalidateSourceTree(id, filePath);
|
|
371
438
|
recordHistory(id, user.id, "file", [filePath]);
|
|
372
439
|
return reply.code(201).send({ ok: true, path: filePath, comments: commentsForFile(db, config, id, filePath) });
|
|
373
440
|
}, { preflight: () => { requireEditableProject(db, id, user); } });
|
|
@@ -434,18 +501,24 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
434
501
|
const absolute = resolveSourcePath(config, id, filePath);
|
|
435
502
|
if (!isCollaborativeTextFile(filePath))
|
|
436
503
|
return apiError(reply, 400, "FILE_CONTENT_INVALID");
|
|
437
|
-
|
|
504
|
+
const previous = fs.statSync(absolute, { throwIfNoEntry: false });
|
|
505
|
+
if (previous && !previous.isFile())
|
|
506
|
+
return apiError(reply, 409, "PATH_EXISTS", { path: filePath });
|
|
507
|
+
if (previous && previous.size > maxCollaborativeFileBytes(config)) {
|
|
438
508
|
return apiError(reply, 413, "FILE_TOO_LARGE", { path: filePath });
|
|
439
509
|
}
|
|
440
510
|
fs.mkdirSync(path.dirname(absolute), { recursive: true, mode: 0o700 });
|
|
441
|
-
const previousBytes =
|
|
511
|
+
const previousBytes = previous ? fs.readFileSync(absolute) : Buffer.alloc(0);
|
|
442
512
|
if (!isTextContent(previousBytes))
|
|
443
513
|
return apiError(reply, 400, "FILE_CONTENT_INVALID");
|
|
444
514
|
const previousContent = previousBytes.toString("utf8");
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
515
|
+
saveProjectText(db, outputRoot(config, id), absolute, Buffer.from(content, "utf8"), previous, () => {
|
|
516
|
+
reanchorFileComments(db, id, filePath, previousContent, content);
|
|
517
|
+
touchProject(db, id, user.id);
|
|
518
|
+
}, (err, directory) => app.log.warn({ err, directory }, "Could not clean up source save staging"));
|
|
448
519
|
collaboration.updateFile(id, filePath, content, user.id);
|
|
520
|
+
if (previousContent !== content)
|
|
521
|
+
collaboration.signalComments(id);
|
|
449
522
|
recordHistory(id, user.id, "file", [filePath]);
|
|
450
523
|
return { ok: true, comments: commentsForFile(db, config, id, filePath) };
|
|
451
524
|
}, { preflight: () => { requireEditableProject(db, id, user); } });
|
|
@@ -464,6 +537,7 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
464
537
|
return apiError(reply, 403, "PROJECT_EDIT_FORBIDDEN");
|
|
465
538
|
return await projectMutations.runWrite(id, () => {
|
|
466
539
|
const currentProject = requireEditableProject(db, id, user);
|
|
540
|
+
const releaseDrawio = projectMutations.drawioLocks.prepareDelete(id, relative, user.id, request.headers[DRAWIO_LOCK_HEADER]);
|
|
467
541
|
if (relative === currentProject.main_file || currentProject.main_file.startsWith(`${relative}/`)) {
|
|
468
542
|
return apiError(reply, 400, "MAIN_FILE_DELETE_FORBIDDEN", { path: relative });
|
|
469
543
|
}
|
|
@@ -476,7 +550,8 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
476
550
|
return apiError(reply, 404, "PATH_NOT_FOUND", { path: relative });
|
|
477
551
|
throw error;
|
|
478
552
|
}
|
|
479
|
-
|
|
553
|
+
removeProjectSourcePath(config, absolute);
|
|
554
|
+
releaseDrawio();
|
|
480
555
|
if (currentProject.latexmkrc === relative || currentProject.latexmkrc?.startsWith(`${relative}/`)) {
|
|
481
556
|
db.prepare("UPDATE projects SET latexmkrc = NULL WHERE id = ?").run(id);
|
|
482
557
|
}
|
|
@@ -539,6 +614,7 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
539
614
|
}
|
|
540
615
|
try {
|
|
541
616
|
return await projectMutations.runWrite(id, () => {
|
|
617
|
+
projectMutations.drawioLocks.assertUnlocked(id, [relative]);
|
|
542
618
|
const absolute = resolveSourcePath(config, id, relative);
|
|
543
619
|
try {
|
|
544
620
|
fs.mkdirSync(path.dirname(absolute), { recursive: true, mode: 0o700 });
|
|
@@ -573,11 +649,21 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
573
649
|
}
|
|
574
650
|
}
|
|
575
651
|
try {
|
|
576
|
-
|
|
652
|
+
renameProjectPath(tmpPath, absolute);
|
|
577
653
|
}
|
|
578
|
-
catch {
|
|
579
|
-
|
|
580
|
-
|
|
654
|
+
catch (error) {
|
|
655
|
+
if (error.code !== "EXDEV")
|
|
656
|
+
throw error;
|
|
657
|
+
// A separately mounted project needs a same-directory staged copy.
|
|
658
|
+
// Never copy directly over the live file, especially on a sharing violation.
|
|
659
|
+
const staged = path.join(path.dirname(absolute), `.texlite-upload-${randomUUID()}.tmp`);
|
|
660
|
+
try {
|
|
661
|
+
fs.copyFileSync(tmpPath, staged, fs.constants.COPYFILE_EXCL);
|
|
662
|
+
renameProjectPath(staged, absolute);
|
|
663
|
+
}
|
|
664
|
+
finally {
|
|
665
|
+
fs.rmSync(staged, { force: true });
|
|
666
|
+
}
|
|
581
667
|
}
|
|
582
668
|
touchProject(db, id, user.id);
|
|
583
669
|
if (collaborativeText) {
|