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
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
|
-
import { requireUser } from "../auth.js";
|
|
4
|
+
import { currentUser, requireUser } from "../auth.js";
|
|
5
5
|
import { maxCollaborativeFileBytes } from "../collaboration.js";
|
|
6
|
+
import { isEngine } from "../config.js";
|
|
6
7
|
import { createProjectFiles, duplicateProjectFiles, outputRoot, removeProjectDirectory, resolveSourcePath, safeRelativePath, sourceRoot } from "../files.js";
|
|
7
8
|
import { apiError, contentDisposition, httpError } from "../http.js";
|
|
8
9
|
import { isMainDocumentCandidate } from "../latexRoot.js";
|
|
@@ -11,6 +12,7 @@ import { accessibleProject, canEdit } from "../projects.js";
|
|
|
11
12
|
import { ProjectPreviewService } from "../projectPreview.js";
|
|
12
13
|
import { writeProjectArchive } from "../archive.js";
|
|
13
14
|
import { extractProjectZip, ZipValidationError } from "../zip.js";
|
|
15
|
+
import { ProjectTemplateCache } from "../projectTemplateCache.js";
|
|
14
16
|
import { HarperLintSupersededError, HarperUnavailableError } from "../harper.js";
|
|
15
17
|
import { ChktexLintSupersededError, ChktexUnavailableError } from "../chktex.js";
|
|
16
18
|
import { supportsChktexChecks, supportsWritingChecks } from "../../shared/writingChecks.js";
|
|
@@ -22,6 +24,29 @@ const clientIdPattern = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
|
22
24
|
export function registerProjectCatalogRoutes(app, context) {
|
|
23
25
|
const { config, db, collaboration, projectMutations, latexCompletions, projectOutlines, harper, chktex, recordHistory } = context;
|
|
24
26
|
const projectPreviews = new ProjectPreviewService(config);
|
|
27
|
+
const templateCache = new ProjectTemplateCache(path.join(config.dataDir, "tmp", "template-cache"), config.maxUploadBytes);
|
|
28
|
+
/** Both uploaded archives and template URLs use the same project import. */
|
|
29
|
+
const importArchive = async (user, name, archive) => {
|
|
30
|
+
const project = {
|
|
31
|
+
id: randomUUID(), owner_id: user.id, last_modified_by: user.id, name: text(name, 120),
|
|
32
|
+
main_file: "", latexmkrc: null, engine: config.defaultEngine, icon: null, chktex_enabled: 0, created_at: now(), updated_at: now()
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
fs.mkdirSync(sourceRoot(config, project.id), { recursive: true, mode: 0o700 });
|
|
36
|
+
fs.mkdirSync(outputRoot(config, project.id), { recursive: true, mode: 0o700 });
|
|
37
|
+
const extracted = await extractProjectZip(archive, sourceRoot(config, project.id), config.maxUploadBytes);
|
|
38
|
+
project.main_file = extracted.mainFile;
|
|
39
|
+
db.prepare(`INSERT INTO projects (id, owner_id, last_modified_by, name, main_file, latexmkrc, engine, chktex_enabled, created_at, updated_at)
|
|
40
|
+
VALUES (?, ?, ?, ?, ?, NULL, ?, ?, ?, ?)`)
|
|
41
|
+
.run(project.id, project.owner_id, project.last_modified_by, project.name, project.main_file, project.engine, project.chktex_enabled, project.created_at, project.updated_at);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
removeProjectDirectory(config, project.id);
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
recordHistory(project.id, user.id, "initial");
|
|
48
|
+
return project;
|
|
49
|
+
};
|
|
25
50
|
// Advanced project icons are served as cacheable SVG masks. The browser
|
|
26
51
|
// therefore does not have to bundle Lucide's entire icon catalogue merely
|
|
27
52
|
// because an owner selected an icon outside the curated picker.
|
|
@@ -137,13 +162,17 @@ export function registerProjectCatalogRoutes(app, context) {
|
|
|
137
162
|
const search = typeof query.search === "string" ? query.search.trim() : "";
|
|
138
163
|
const tagId = typeof query.tag === "string" ? query.tag.trim() : "";
|
|
139
164
|
const sortColumn = query.sort === "created" ? "p.created_at" : "p.updated_at";
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
: "NOT EXISTS (SELECT 1 FROM user_project_archives archive WHERE archive.project_id = p.id AND archive.user_id = :userId)";
|
|
165
|
+
const isArchived = "EXISTS (SELECT 1 FROM user_project_archives archive WHERE archive.project_id = p.id AND archive.user_id = :userId)";
|
|
166
|
+
const archiveCondition = archivedOnly ? isArchived : `NOT ${isArchived}`;
|
|
143
167
|
const from = `FROM projects p JOIN users owner ON owner.id = p.owner_id
|
|
144
168
|
LEFT JOIN users modifier ON modifier.id = p.last_modified_by
|
|
145
169
|
LEFT JOIN project_members pm ON pm.project_id = p.id AND pm.user_id = :userId`;
|
|
146
170
|
const conditions = ["(p.owner_id = :userId OR pm.user_id = :userId)"];
|
|
171
|
+
// Archive badges describe the whole category, not the filtered result set.
|
|
172
|
+
const archivedCounts = db.prepare(`SELECT COUNT(DISTINCT p.id) AS "all",
|
|
173
|
+
COUNT(DISTINCT CASE WHEN p.owner_id = :userId THEN p.id END) AS owned,
|
|
174
|
+
COUNT(DISTINCT CASE WHEN p.owner_id <> :userId THEN p.id END) AS shared
|
|
175
|
+
${from} WHERE ${conditions[0]} AND ${isArchived}`).get({ userId: user.id });
|
|
147
176
|
const params = { userId: user.id };
|
|
148
177
|
if (search) {
|
|
149
178
|
conditions.push("(p.name LIKE :search ESCAPE '\\' OR owner.username LIKE :search ESCAPE '\\' OR owner.display_name LIKE :search ESCAPE '\\')");
|
|
@@ -190,7 +219,8 @@ export function registerProjectCatalogRoutes(app, context) {
|
|
|
190
219
|
return {
|
|
191
220
|
projects: projects.map((project) => ({ ...projectJson({ ...project, archived: archivedOnly }, projectTags.get(project.id) ?? [], commentsSummaries.get(project.id), unreadMentionCounts.get(project.id) ?? 0), ...(previews.has(project.id) ? { preview: previews.get(project.id) } : {}) })),
|
|
192
221
|
pagination: { page: currentPage, pageSize, total, totalPages },
|
|
193
|
-
counts
|
|
222
|
+
counts,
|
|
223
|
+
archivedCounts
|
|
194
224
|
};
|
|
195
225
|
});
|
|
196
226
|
app.post("/api/projects", async (request, reply) => {
|
|
@@ -201,6 +231,41 @@ export function registerProjectCatalogRoutes(app, context) {
|
|
|
201
231
|
return apiError(reply, 403, "PROJECT_CREATE_FORBIDDEN");
|
|
202
232
|
}
|
|
203
233
|
const body = request.body;
|
|
234
|
+
if (body?.templateUrl !== undefined) {
|
|
235
|
+
// Validate the name before starting a potentially slow download.
|
|
236
|
+
const name = text(body.name, 120);
|
|
237
|
+
const controller = new AbortController();
|
|
238
|
+
const disconnect = () => { if (!reply.raw.writableEnded)
|
|
239
|
+
controller.abort(); };
|
|
240
|
+
reply.raw.on("close", disconnect);
|
|
241
|
+
const template = await templateCache.download(body.templateUrl, controller.signal)
|
|
242
|
+
.finally(() => reply.raw.off("close", disconnect));
|
|
243
|
+
if (controller.signal.aborted)
|
|
244
|
+
return;
|
|
245
|
+
// Downloading may take time; do not create after access was revoked.
|
|
246
|
+
const creator = currentUser(request, db, true);
|
|
247
|
+
if (!creator)
|
|
248
|
+
return apiError(reply, 401, "AUTH_REQUIRED");
|
|
249
|
+
if (creator.must_change_password)
|
|
250
|
+
return apiError(reply, 403, "PASSWORD_CHANGE_REQUIRED");
|
|
251
|
+
if (creator.role !== "admin" && !creator.can_create_projects)
|
|
252
|
+
return apiError(reply, 403, "PROJECT_CREATE_FORBIDDEN");
|
|
253
|
+
let project;
|
|
254
|
+
try {
|
|
255
|
+
project = await importArchive(creator, name, template.archive);
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
if (error instanceof ZipValidationError)
|
|
259
|
+
return apiError(reply, 400, error.code, error.details);
|
|
260
|
+
return apiError(reply, 400, "ZIP_INVALID");
|
|
261
|
+
}
|
|
262
|
+
if (!template.cached)
|
|
263
|
+
await templateCache.store(body.templateUrl, template.archive);
|
|
264
|
+
return reply.code(201).send({ project: projectJson({
|
|
265
|
+
...project, permission: "owner", owner_username: creator.username, owner_display_name: creator.display_name,
|
|
266
|
+
last_modified_username: creator.username, last_modified_display_name: creator.display_name
|
|
267
|
+
}) });
|
|
268
|
+
}
|
|
204
269
|
const project = {
|
|
205
270
|
id: randomUUID(), owner_id: user.id, last_modified_by: user.id, name: text(body?.name, 120),
|
|
206
271
|
main_file: "main.tex", latexmkrc: null, engine: config.defaultEngine, icon: null, chktex_enabled: 0, created_at: now(), updated_at: now()
|
|
@@ -233,26 +298,16 @@ export function registerProjectCatalogRoutes(app, context) {
|
|
|
233
298
|
}
|
|
234
299
|
const query = request.query;
|
|
235
300
|
const fallbackName = path.basename(part.filename, path.extname(part.filename));
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
main_file: "", latexmkrc: null, engine: config.defaultEngine, icon: null, chktex_enabled: 0, created_at: now(), updated_at: now()
|
|
239
|
-
};
|
|
240
|
-
fs.mkdirSync(sourceRoot(config, project.id), { recursive: true, mode: 0o700 });
|
|
241
|
-
fs.mkdirSync(outputRoot(config, project.id), { recursive: true, mode: 0o700 });
|
|
301
|
+
const name = text(query.name || fallbackName, 120);
|
|
302
|
+
let project;
|
|
242
303
|
try {
|
|
243
|
-
|
|
244
|
-
project.main_file = extracted.mainFile;
|
|
245
|
-
db.prepare(`INSERT INTO projects (id, owner_id, last_modified_by, name, main_file, latexmkrc, engine, chktex_enabled, created_at, updated_at)
|
|
246
|
-
VALUES (?, ?, ?, ?, ?, NULL, ?, ?, ?, ?)`)
|
|
247
|
-
.run(project.id, project.owner_id, project.last_modified_by, project.name, project.main_file, project.engine, project.chktex_enabled, project.created_at, project.updated_at);
|
|
304
|
+
project = await importArchive(user, name, await part.toBuffer());
|
|
248
305
|
}
|
|
249
306
|
catch (error) {
|
|
250
|
-
removeProjectDirectory(config, project.id);
|
|
251
307
|
if (error instanceof ZipValidationError)
|
|
252
308
|
return apiError(reply, 400, error.code, error.details);
|
|
253
309
|
return apiError(reply, 400, "ZIP_INVALID");
|
|
254
310
|
}
|
|
255
|
-
recordHistory(project.id, user.id, "initial");
|
|
256
311
|
return reply.code(201).send({ project: projectJson({
|
|
257
312
|
...project, permission: "owner", owner_username: user.username, owner_display_name: user.display_name,
|
|
258
313
|
last_modified_username: user.username, last_modified_display_name: user.display_name
|
|
@@ -558,8 +613,14 @@ export function registerProjectCatalogRoutes(app, context) {
|
|
|
558
613
|
}
|
|
559
614
|
mainFile = safeRelativePath(body.mainFile);
|
|
560
615
|
}
|
|
561
|
-
|
|
562
|
-
|
|
616
|
+
let engine = currentProject.engine;
|
|
617
|
+
if (body.engine !== undefined && body.engine !== engine) {
|
|
618
|
+
if (!isEngine(body.engine))
|
|
619
|
+
return apiError(reply, 400, "REQUEST_INVALID");
|
|
620
|
+
if (!config.allowedEngines.includes(body.engine))
|
|
621
|
+
return apiError(reply, 422, "LATEX_ENGINE_UNAVAILABLE", { engine: body.engine });
|
|
622
|
+
engine = body.engine;
|
|
623
|
+
}
|
|
563
624
|
const chktexEnabled = typeof body.chktexEnabled === "boolean" ? body.chktexEnabled : Boolean(currentProject.chktex_enabled);
|
|
564
625
|
const latexmkrc = body.latexmkrc === null || body.latexmkrc === ""
|
|
565
626
|
? null
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { publicUser, requireAdmin, requireUser } from "../auth.js";
|
|
3
3
|
import { activeAdminCount } from "../db.js";
|
|
4
|
-
import { removeProjectDirectory } from "../files.js";
|
|
5
4
|
import { apiError, httpError, ValidationError } from "../http.js";
|
|
6
5
|
import { hashPassword } from "../security.js";
|
|
7
6
|
const now = () => new Date().toISOString();
|
|
@@ -13,7 +12,7 @@ function text(value, max = 200) {
|
|
|
13
12
|
}
|
|
14
13
|
/** Register administrator-facing user management and the active-user directory. */
|
|
15
14
|
export function registerUserManagementRoutes(app, context) {
|
|
16
|
-
const {
|
|
15
|
+
const { db, collaboration, projectMutations, projectDeletionCleanup } = context;
|
|
17
16
|
app.get("/api/admin/users", async (request, reply) => {
|
|
18
17
|
if (!requireAdmin(request, reply, db))
|
|
19
18
|
return;
|
|
@@ -133,7 +132,7 @@ export function registerUserManagementRoutes(app, context) {
|
|
|
133
132
|
if (currentTarget.role === "admin" && activeAdminCount(db) <= 1) {
|
|
134
133
|
throw httpError(400, "LAST_ADMIN");
|
|
135
134
|
}
|
|
136
|
-
owned = db.prepare("SELECT id FROM projects WHERE owner_id = ?").all(id);
|
|
135
|
+
owned = db.prepare("SELECT id FROM projects WHERE owner_id = ? ORDER BY created_at, rowid").all(id);
|
|
137
136
|
if (!body.deleteProjects) {
|
|
138
137
|
// Persist any active drafts while the old owner row still exists. This
|
|
139
138
|
// is synchronous, so no edit can arrive between this flush and the
|
|
@@ -142,6 +141,8 @@ export function registerUserManagementRoutes(app, context) {
|
|
|
142
141
|
projectMutations.flushProject(project.id);
|
|
143
142
|
}
|
|
144
143
|
if (body.deleteProjects) {
|
|
144
|
+
for (const project of owned)
|
|
145
|
+
projectDeletionCleanup.enqueue(project.id);
|
|
145
146
|
db.prepare("DELETE FROM projects WHERE owner_id = ?").run(id);
|
|
146
147
|
}
|
|
147
148
|
else {
|
|
@@ -160,20 +161,15 @@ export function registerUserManagementRoutes(app, context) {
|
|
|
160
161
|
// Requests already queued for the removed user fail their lock-time
|
|
161
162
|
// preflight. Cleanup is then serialized after them and invalidates any
|
|
162
163
|
// room initialization that started before the transaction committed.
|
|
164
|
+
collaboration.disconnectUser(id, "user-deleted");
|
|
163
165
|
for (const project of owned) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
+
if (body.deleteProjects)
|
|
167
|
+
await projectDeletionCleanup.clean(project.id);
|
|
168
|
+
else
|
|
169
|
+
await projectMutations.runExclusive(project.id, "admin ownership transfer", () => {
|
|
166
170
|
collaboration.resetProject(project.id);
|
|
167
|
-
|
|
168
|
-
latexCompletions.invalidate(project.id);
|
|
169
|
-
projectOutlines.invalidate(project.id);
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
collaboration.resetProject(project.id);
|
|
173
|
-
}
|
|
174
|
-
}, { flush: false });
|
|
171
|
+
}, { flush: false });
|
|
175
172
|
}
|
|
176
|
-
collaboration.disconnectUser(id, "user-deleted");
|
|
177
173
|
return { ok: true, deletedProjects: body.deleteProjects ? owned.length : 0 };
|
|
178
174
|
});
|
|
179
175
|
app.get("/api/users", async (request, reply) => {
|
package/dist/server/synctex.js
CHANGED
|
@@ -11,6 +11,19 @@ export class SyncTeXError extends Error {
|
|
|
11
11
|
this.name = "SyncTeXError";
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
+
/** Rebase only absolute project inputs; relative inputs already use the snapshot cwd. */
|
|
15
|
+
export function relocateSyncTeXInputs(content, cacheSource, snapshotSource, platform = process.platform) {
|
|
16
|
+
const paths = platform === "win32" ? path.win32 : path.posix;
|
|
17
|
+
const cacheRoot = paths.resolve(cacheSource);
|
|
18
|
+
return content.replace(/^(Input:\d+:)([^\r\n]+)$/gm, (record, prefix, input) => {
|
|
19
|
+
if (!paths.isAbsolute(input))
|
|
20
|
+
return record;
|
|
21
|
+
const relative = paths.relative(cacheRoot, input);
|
|
22
|
+
if (!relative || relative === ".." || relative.startsWith(`..${paths.sep}`) || paths.isAbsolute(relative))
|
|
23
|
+
return record;
|
|
24
|
+
return prefix + paths.join(snapshotSource, relative);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
14
27
|
async function runSynctex(args, cwd) {
|
|
15
28
|
try {
|
|
16
29
|
const { stdout } = await runFile("synctex", args, {
|
|
@@ -28,9 +41,13 @@ async function runSynctex(args, cwd) {
|
|
|
28
41
|
}
|
|
29
42
|
}
|
|
30
43
|
export async function sourceToPdf(sourceDirectory, pdfPath, sourcePath, line, column) {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
const view = (input) => runSynctex(["view", "-i", `${line}:${column}:${input}`, "-o", pdfPath], sourceDirectory);
|
|
45
|
+
// TeX Live can record absolute names even for relative \input paths. The
|
|
46
|
+
// SyncTeX CLI may not match a relative query against those records.
|
|
47
|
+
const absoluteInput = path.resolve(sourceDirectory, sourcePath);
|
|
48
|
+
let output = await view(absoluteInput);
|
|
49
|
+
if (absoluteInput !== sourcePath && numericField(output, "Page") === null)
|
|
50
|
+
output = await view(sourcePath);
|
|
34
51
|
const page = numericField(output, "Page");
|
|
35
52
|
const x = numericField(output, "x");
|
|
36
53
|
const y = numericField(output, "y");
|
package/dist/server/texcount.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import { detachedProcessGroup,
|
|
2
|
+
import { afterProcessStop, detachedProcessGroup, stopProcessTree } from "./processTree.js";
|
|
3
3
|
/** TeXcount is an optional host command supplied by TeX Live. */
|
|
4
4
|
export const TEXCOUNT_COMMAND = "texcount";
|
|
5
5
|
const TEXLITE_WORD_REPORT_PREFIX = "__TEXLITE_TEXCOUNT_WORDS__";
|
|
@@ -53,8 +53,12 @@ export class TexcountService {
|
|
|
53
53
|
}
|
|
54
54
|
async dispose() {
|
|
55
55
|
this.disposed = true;
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
const children = [...this.activeChildren];
|
|
57
|
+
if (process.platform === "win32")
|
|
58
|
+
await Promise.allSettled(children.map((child) => stopProcessTree(child)));
|
|
59
|
+
else
|
|
60
|
+
for (const child of children)
|
|
61
|
+
void stopProcessTree(child, "SIGTERM");
|
|
58
62
|
this.activeChildren.clear();
|
|
59
63
|
await this.probePromise?.catch(() => undefined);
|
|
60
64
|
this.probePromise = null;
|
|
@@ -147,10 +151,10 @@ export class TexcountService {
|
|
|
147
151
|
let outputBytes = 0;
|
|
148
152
|
let settled = false;
|
|
149
153
|
let timedOut = false;
|
|
150
|
-
let
|
|
154
|
+
let terminationError;
|
|
151
155
|
const timer = setTimeout(() => {
|
|
152
156
|
timedOut = true;
|
|
153
|
-
|
|
157
|
+
void stopProcessTree(child).catch((error) => finish(() => reject(error)));
|
|
154
158
|
}, timeoutMs);
|
|
155
159
|
const finish = (callback) => {
|
|
156
160
|
if (settled)
|
|
@@ -161,13 +165,14 @@ export class TexcountService {
|
|
|
161
165
|
callback();
|
|
162
166
|
};
|
|
163
167
|
const terminateWithError = (error) => {
|
|
164
|
-
|
|
165
|
-
|
|
168
|
+
if (terminationError || settled)
|
|
169
|
+
return;
|
|
170
|
+
terminationError = error;
|
|
171
|
+
void stopProcessTree(child).then(() => finish(() => reject(error)), (failure) => finish(() => reject(failure)));
|
|
166
172
|
};
|
|
167
173
|
const collect = (target) => (chunk) => {
|
|
168
174
|
outputBytes += chunk.length;
|
|
169
175
|
if (outputBytes > outputLimit) {
|
|
170
|
-
outputTooLarge = true;
|
|
171
176
|
terminateWithError(new TexcountExecutionError(`${this.command} produced too much output.`));
|
|
172
177
|
return;
|
|
173
178
|
}
|
|
@@ -187,21 +192,20 @@ export class TexcountService {
|
|
|
187
192
|
}
|
|
188
193
|
reject(error);
|
|
189
194
|
}));
|
|
190
|
-
child.once("close", (code) =>
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}));
|
|
195
|
+
child.once("close", (code) => {
|
|
196
|
+
clearTimeout(timer);
|
|
197
|
+
afterProcessStop(child, () => finish(() => {
|
|
198
|
+
if (terminationError)
|
|
199
|
+
return reject(terminationError);
|
|
200
|
+
if (timedOut)
|
|
201
|
+
return reject(new TexcountExecutionError(`${this.command} timed out after ${Math.ceil(timeoutMs / 1000)} seconds.`));
|
|
202
|
+
resolve({
|
|
203
|
+
code,
|
|
204
|
+
stdout: Buffer.concat(stdout).toString("utf8"),
|
|
205
|
+
stderr: Buffer.concat(stderr).toString("utf8")
|
|
206
|
+
});
|
|
207
|
+
}), (error) => finish(() => reject(error)));
|
|
208
|
+
});
|
|
205
209
|
if (input !== undefined)
|
|
206
210
|
child.stdin?.end(input, "utf8");
|
|
207
211
|
});
|
package/dist/server/zip.js
CHANGED
|
@@ -18,7 +18,7 @@ export class ZipValidationError extends Error {
|
|
|
18
18
|
this.name = "ZipValidationError";
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
export async function extractProjectZip(buffer, destination, maxFileBytes) {
|
|
21
|
+
export async function extractProjectZip(buffer, destination, maxFileBytes, platform = process.platform) {
|
|
22
22
|
const maxTotalBytes = Math.max(MAX_TOTAL_BYTES, maxFileBytes);
|
|
23
23
|
// Node >= 24 provides native deflate-raw streams. The custom entry point
|
|
24
24
|
// avoids loading browser workers or WASM codecs in the server process.
|
|
@@ -28,12 +28,12 @@ export async function extractProjectZip(buffer, destination, maxFileBytes) {
|
|
|
28
28
|
filenameValidation: "tolerant"
|
|
29
29
|
});
|
|
30
30
|
try {
|
|
31
|
-
const entries = await inspectZip(zip, maxFileBytes, maxTotalBytes);
|
|
31
|
+
const entries = await inspectZip(zip, maxFileBytes, maxTotalBytes, platform);
|
|
32
32
|
const prefix = commonRootPrefix(entries.filter((entry) => !entry.directory).map((entry) => entry.fileName));
|
|
33
33
|
const root = path.resolve(destination);
|
|
34
34
|
assertNoSymbolicLinks(root);
|
|
35
35
|
await fs.promises.mkdir(root, { recursive: true, mode: 0o700 });
|
|
36
|
-
const files = await extractZip(entries, root, prefix, maxFileBytes, maxTotalBytes);
|
|
36
|
+
const files = await extractZip(entries, root, prefix, maxFileBytes, maxTotalBytes, platform);
|
|
37
37
|
const mainFile = await discoverMainFile(root, files);
|
|
38
38
|
if (!mainFile)
|
|
39
39
|
throw new ZipValidationError("ZIP_MAIN_DOCUMENT_NOT_FOUND");
|
|
@@ -43,13 +43,14 @@ export async function extractProjectZip(buffer, destination, maxFileBytes) {
|
|
|
43
43
|
await zip.close();
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
async function inspectZip(zip, maxFileBytes, maxTotalBytes) {
|
|
46
|
+
async function inspectZip(zip, maxFileBytes, maxTotalBytes, platform) {
|
|
47
47
|
const entries = [];
|
|
48
48
|
const seenPaths = new Set();
|
|
49
|
+
const windowsRoot = platform === "win32" ? new Map() : null;
|
|
49
50
|
let totalBytes = 0;
|
|
50
51
|
try {
|
|
51
52
|
for await (const entry of zip.getEntriesGenerator()) {
|
|
52
|
-
validateEntry(entry);
|
|
53
|
+
const normalized = validateEntry(entry, platform);
|
|
53
54
|
if (entries.length >= MAX_ENTRIES)
|
|
54
55
|
throw new ZipValidationError("ZIP_TOO_MANY_ENTRIES", { limit: MAX_ENTRIES });
|
|
55
56
|
totalBytes += entry.uncompressedSize;
|
|
@@ -58,10 +59,11 @@ async function inspectZip(zip, maxFileBytes, maxTotalBytes) {
|
|
|
58
59
|
if (totalBytes > maxTotalBytes)
|
|
59
60
|
throw new ZipValidationError("ZIP_TOTAL_TOO_LARGE", { size: formatMB(maxTotalBytes) });
|
|
60
61
|
// Canonical paths also detect aliases such as `./main.tex` and `main.tex`.
|
|
61
|
-
const normalized = safeRelativePath(entry.filename.replace(/\/+$/, ""));
|
|
62
62
|
if (seenPaths.has(normalized))
|
|
63
63
|
throw new ZipValidationError("ZIP_DUPLICATE_ENTRY", { path: normalized });
|
|
64
64
|
seenPaths.add(normalized);
|
|
65
|
+
if (windowsRoot)
|
|
66
|
+
registerWindowsZipPath(windowsRoot, normalized, entry.directory);
|
|
65
67
|
entries.push({ entry, fileName: normalized, directory: entry.directory });
|
|
66
68
|
}
|
|
67
69
|
}
|
|
@@ -72,7 +74,25 @@ async function inspectZip(zip, maxFileBytes, maxTotalBytes) {
|
|
|
72
74
|
}
|
|
73
75
|
return entries;
|
|
74
76
|
}
|
|
75
|
-
|
|
77
|
+
/** Each implicit directory has one spelling and cannot also be a file. */
|
|
78
|
+
function registerWindowsZipPath(root, relative, directory) {
|
|
79
|
+
const segments = relative.split("/");
|
|
80
|
+
let siblings = root;
|
|
81
|
+
for (const [index, name] of segments.entries()) {
|
|
82
|
+
const isDirectory = directory || index < segments.length - 1;
|
|
83
|
+
const key = name.toUpperCase();
|
|
84
|
+
const existing = siblings.get(key);
|
|
85
|
+
if (existing && (existing.name !== name || !isDirectory || !existing.children)) {
|
|
86
|
+
throw new ZipValidationError("ZIP_PATH_CONFLICT", { path: relative });
|
|
87
|
+
}
|
|
88
|
+
const node = existing ?? { name, children: isDirectory ? new Map() : null };
|
|
89
|
+
if (!existing)
|
|
90
|
+
siblings.set(key, node);
|
|
91
|
+
if (node.children)
|
|
92
|
+
siblings = node.children;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function extractZip(entries, destination, prefix, maxFileBytes, maxTotalBytes, platform) {
|
|
76
96
|
const files = [];
|
|
77
97
|
// Only this extraction owns the cache. Recursive mkdir also establishes
|
|
78
98
|
// ancestors, including directories whose explicit ZIP entry arrives later.
|
|
@@ -93,7 +113,7 @@ async function extractZip(entries, destination, prefix, maxFileBytes, maxTotalBy
|
|
|
93
113
|
const stripped = prefix && fileName.startsWith(prefix) ? fileName.slice(prefix.length) : fileName;
|
|
94
114
|
if (!stripped || stripped.startsWith("__MACOSX/") || stripped.endsWith("/.DS_Store") || stripped === ".DS_Store")
|
|
95
115
|
continue;
|
|
96
|
-
const relative = safeRelativePath(stripped);
|
|
116
|
+
const relative = safeRelativePath(stripped, platform);
|
|
97
117
|
const absolute = path.join(destination, relative);
|
|
98
118
|
if (entry.directory) {
|
|
99
119
|
await ensureDirectory(absolute);
|
|
@@ -113,7 +133,8 @@ async function extractZip(entries, destination, prefix, maxFileBytes, maxTotalBy
|
|
|
113
133
|
callback(null, chunk);
|
|
114
134
|
}
|
|
115
135
|
});
|
|
116
|
-
|
|
136
|
+
// Let the filesystem reject aliases not captured by lexical comparison.
|
|
137
|
+
const writing = pipeline(limiter, fs.createWriteStream(absolute, { mode: 0o600, flags: platform === "win32" ? "wx" : "w" }));
|
|
117
138
|
const extracting = entry.getData(Writable.toWeb(limiter));
|
|
118
139
|
try {
|
|
119
140
|
await Promise.all([extracting, writing]);
|
|
@@ -125,19 +146,23 @@ async function extractZip(entries, destination, prefix, maxFileBytes, maxTotalBy
|
|
|
125
146
|
await Promise.allSettled([extracting, writing]);
|
|
126
147
|
if (error instanceof ZipValidationError)
|
|
127
148
|
throw error;
|
|
149
|
+
if (platform === "win32" && error?.code === "EEXIST") {
|
|
150
|
+
throw new ZipValidationError("ZIP_PATH_CONFLICT", { path: relative });
|
|
151
|
+
}
|
|
128
152
|
throw new ZipValidationError("ZIP_ENTRY_READ_FAILED");
|
|
129
153
|
}
|
|
130
154
|
files.push(relative);
|
|
131
155
|
}
|
|
132
156
|
return files;
|
|
133
157
|
}
|
|
134
|
-
function validateEntry(entry) {
|
|
158
|
+
function validateEntry(entry, platform) {
|
|
135
159
|
const name = entry.filename;
|
|
136
160
|
if (!name || name.includes("\0") || name.startsWith("/") || name.includes("\\") || /^[a-z]:/i.test(name) || name.split("/").includes("..")) {
|
|
137
161
|
throw new ZipValidationError("ZIP_INVALID_PATH");
|
|
138
162
|
}
|
|
163
|
+
let normalized;
|
|
139
164
|
try {
|
|
140
|
-
safeRelativePath(name.replace(
|
|
165
|
+
normalized = safeRelativePath(name.replace(/\/+$/, ""), platform);
|
|
141
166
|
}
|
|
142
167
|
catch {
|
|
143
168
|
throw new ZipValidationError("ZIP_INVALID_PATH");
|
|
@@ -145,6 +170,7 @@ function validateEntry(entry) {
|
|
|
145
170
|
const unixType = (entry.externalFileAttributes >>> 16) & 0o170000;
|
|
146
171
|
if (unixType === 0o120000)
|
|
147
172
|
throw new ZipValidationError("ZIP_SYMLINK_FORBIDDEN");
|
|
173
|
+
return normalized;
|
|
148
174
|
}
|
|
149
175
|
function commonRootPrefix(files) {
|
|
150
176
|
if (files.length === 0)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export const EMPTY_DRAWIO = '<mxfile><diagram id="page-1" name="Page-1"><mxGraphModel math="1"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';
|
|
2
|
+
export const isDrawioFile = (path) => /\.drawio$/i.test(path);
|
|
3
|
+
export const drawioPdfPath = (path) => path.replace(/\.drawio$/i, ".pdf");
|
|
4
|
+
export const DRAWIO_ORIGIN = "https://embed.diagrams.net";
|
|
5
|
+
export const DRAWIO_LOCK_HEADER = "x-texlite-drawio-lock";
|
|
6
|
+
export const drawioMessages = {
|
|
7
|
+
en: {
|
|
8
|
+
errors: {
|
|
9
|
+
DRAWIO_LOCKED: "{{name}} is editing this diagram. Close the editor before moving, replacing or deleting its files.",
|
|
10
|
+
DRAWIO_LOCK_LOST: "The diagram editing lock is no longer valid. Reconnect before saving or exporting.",
|
|
11
|
+
DRAWIO_INVALID: "The diagram or exported SVG is invalid or too large.",
|
|
12
|
+
DRAWIO_CONFLICT: "This file changed elsewhere. Reopen the diagram before saving or exporting again.",
|
|
13
|
+
DRAWIO_BROWSER_UNAVAILABLE: "PDF export requires Chromium, Chrome or Edge on the server. Ask your administrator to install one or configure drawio.browserPath.",
|
|
14
|
+
DRAWIO_EXPORT_FAILED: "Could not export the diagram. Check the server browser and fonts, then retry.",
|
|
15
|
+
DRAWIO_EXPORT_BUSY: "Other diagrams are being exported. Try again shortly."
|
|
16
|
+
},
|
|
17
|
+
ui: {
|
|
18
|
+
connecting: "Connecting…", lockedBy: "{{name}} is editing this diagram", lockLost: "Editing connection lost. Your unsaved changes are kept here.", retryEdit: "Try editing",
|
|
19
|
+
new: "draw.io diagram", title: "draw.io", export: "Export PDF", exported: "PDF saved", saved: "Saved",
|
|
20
|
+
saving: "Saving…", saveFailed: "Save failed", saveTimeout: "The diagram editor did not respond. Try saving again.",
|
|
21
|
+
exportOptions: "PDF export options", exportScope: "Export range", currentPage: "Current page", selection: "Selected content", margin: "Content margin",
|
|
22
|
+
selectionCheckFailed: "Could not check selection. Reopen this menu to retry.",
|
|
23
|
+
invalidMargin: "Enter a whole number from 0 to 100.", emptySelection: "Select shapes or connectors in the diagram first.",
|
|
24
|
+
loading: "Loading diagram editor…", unavailable: "The editor did not load. Check your connection to embed.diagrams.net and retry.",
|
|
25
|
+
help: "Loaded from diagrams.net. PDFs are generated using a server browser.",
|
|
26
|
+
discard: "Discard unsaved diagram changes?", discardDescription: "Your changes have not been saved.", discardAction: "Discard",
|
|
27
|
+
overwrite: "Replace PDF?", overwriteDescription: "Exporting will replace {{path}}.", overwriteAction: "Replace and export",
|
|
28
|
+
readOnly: "Read-only"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
zh: {
|
|
32
|
+
errors: {
|
|
33
|
+
DRAWIO_LOCKED: "{{name}} 正在编辑此图表。请先关闭编辑器,再移动、替换或删除相关文件。",
|
|
34
|
+
DRAWIO_LOCK_LOST: "图表编辑锁已失效。请重新连接后再保存或导出。",
|
|
35
|
+
DRAWIO_INVALID: "图表或导出的 SVG 无效,或文件过大。",
|
|
36
|
+
DRAWIO_CONFLICT: "文件已在其他位置修改。请重新打开图表后再保存或导出。",
|
|
37
|
+
DRAWIO_BROWSER_UNAVAILABLE: "导出 PDF 需要服务器安装 Chromium、Chrome 或 Edge。请联系管理员安装,或配置 drawio.browserPath。",
|
|
38
|
+
DRAWIO_EXPORT_FAILED: "无法导出图表。请检查服务器浏览器及字体后重试。",
|
|
39
|
+
DRAWIO_EXPORT_BUSY: "正在导出其他图表,请稍后重试。"
|
|
40
|
+
},
|
|
41
|
+
ui: {
|
|
42
|
+
connecting: "连接中…", lockedBy: "{{name}} 正在编辑此图表", lockLost: "编辑连接已断开,未保存的修改仍保留在此处。", retryEdit: "尝试编辑",
|
|
43
|
+
new: "draw.io 图表", title: "draw.io", export: "导出 PDF", exported: "PDF 已保存", saved: "已保存",
|
|
44
|
+
saving: "保存中…", saveFailed: "保存失败", saveTimeout: "图表编辑器未响应,请重试保存。",
|
|
45
|
+
exportOptions: "PDF 导出选项", exportScope: "导出范围", currentPage: "当前页面", selection: "所选内容", margin: "内容外边距",
|
|
46
|
+
selectionCheckFailed: "无法检查选区,请重新打开菜单重试。",
|
|
47
|
+
invalidMargin: "请输入 0–100 的整数。", emptySelection: "请先在图表中选中图形或连线。",
|
|
48
|
+
loading: "正在加载图表编辑器…", unavailable: "编辑器未能加载。请检查与 embed.diagrams.net 的连接后重试。",
|
|
49
|
+
help: "从 diagrams.net 加载。PDF 使用服务器浏览器生成。",
|
|
50
|
+
discard: "放弃未保存的图表修改?", discardDescription: "当前修改尚未保存。", discardAction: "放弃修改",
|
|
51
|
+
overwrite: "替换 PDF?", overwriteDescription: "导出将替换 {{path}}。", overwriteAction: "替换并导出",
|
|
52
|
+
readOnly: "只读"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"zh-Hant": {
|
|
56
|
+
errors: {
|
|
57
|
+
DRAWIO_LOCKED: "{{name}} 正在編輯此圖表。請先關閉編輯器,再移動、取代或刪除相關檔案。",
|
|
58
|
+
DRAWIO_LOCK_LOST: "圖表編輯鎖已失效。請重新連線後再儲存或匯出。",
|
|
59
|
+
DRAWIO_INVALID: "圖表或匯出的 SVG 無效,或檔案過大。",
|
|
60
|
+
DRAWIO_CONFLICT: "檔案已在其他位置修改。請重新開啟圖表後再儲存或匯出。",
|
|
61
|
+
DRAWIO_BROWSER_UNAVAILABLE: "匯出 PDF 需要伺服器安裝 Chromium、Chrome 或 Edge。請聯絡管理員安裝,或設定 drawio.browserPath。",
|
|
62
|
+
DRAWIO_EXPORT_FAILED: "無法匯出圖表。請檢查伺服器瀏覽器及字型後重試。",
|
|
63
|
+
DRAWIO_EXPORT_BUSY: "正在匯出其他圖表,請稍後重試。"
|
|
64
|
+
},
|
|
65
|
+
ui: {
|
|
66
|
+
connecting: "連線中…", lockedBy: "{{name}} 正在編輯此圖表", lockLost: "編輯連線已中斷,未儲存的修改仍保留在此處。", retryEdit: "嘗試編輯",
|
|
67
|
+
new: "draw.io 圖表", title: "draw.io", export: "匯出 PDF", exported: "PDF 已儲存", saved: "已儲存",
|
|
68
|
+
saving: "儲存中…", saveFailed: "儲存失敗", saveTimeout: "圖表編輯器未回應,請重試儲存。",
|
|
69
|
+
exportOptions: "PDF 匯出選項", exportScope: "匯出範圍", currentPage: "目前頁面", selection: "所選內容", margin: "內容外邊距",
|
|
70
|
+
selectionCheckFailed: "無法檢查選取範圍,請重新開啟選單重試。",
|
|
71
|
+
invalidMargin: "請輸入 0–100 的整數。", emptySelection: "請先在圖表中選取圖形或連接線。",
|
|
72
|
+
loading: "正在載入圖表編輯器…", unavailable: "編輯器未能載入。請檢查與 embed.diagrams.net 的連線後重試。",
|
|
73
|
+
help: "從 diagrams.net 載入。PDF 使用伺服器瀏覽器產生。",
|
|
74
|
+
discard: "捨棄未儲存的圖表修改?", discardDescription: "目前修改尚未儲存。", discardAction: "捨棄修改",
|
|
75
|
+
overwrite: "取代 PDF?", overwriteDescription: "匯出將取代 {{path}}。", overwriteAction: "取代並匯出",
|
|
76
|
+
readOnly: "唯讀"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
package/dist/shared/fileTypes.js
CHANGED
|
@@ -7,7 +7,7 @@ const textExtensions = new Set([
|
|
|
7
7
|
"c", "cc", "cpp", "cxx", "h", "hh", "hpp", "hxx", "m", "mm", "cs", "java", "js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx",
|
|
8
8
|
"py", "pyw", "pyi", "r", "rmd", "qmd", "jl", "pl", "pm", "rb", "go", "rs", "lua", "php", "sh", "bash", "zsh", "ksh", "fish",
|
|
9
9
|
"bashrc", "zshrc", "profile", "awk", "sed", "ps1", "psm1", "bat", "cmd", "sql", "html", "htm", "xhtml", "css", "scss", "sass", "less",
|
|
10
|
-
"xml", "xsd", "xsl", "xslt", "graphql", "gql", "proto", "cmake", "mk", "diff", "patch", "srt", "vtt", "asc", "pem"
|
|
10
|
+
"xml", "drawio", "xsd", "xsl", "xslt", "graphql", "gql", "proto", "cmake", "mk", "diff", "patch", "srt", "vtt", "asc", "pem"
|
|
11
11
|
]);
|
|
12
12
|
const textNames = new Set([
|
|
13
13
|
"latexmkrc", ".latexmkrc", "readme", "license", "licence", "copying", "authors", "changelog",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const pdfFontMessages = {
|
|
2
|
+
en: {
|
|
3
|
+
PDF_FONTS_UNAVAILABLE: "Font inspection requires pdffonts (Poppler) on the server. Ask an administrator to install it.",
|
|
4
|
+
PDF_FONTS_FAILED: "Could not inspect PDF fonts. The PDF may be damaged or the inspection exceeded its limits."
|
|
5
|
+
},
|
|
6
|
+
zh: {
|
|
7
|
+
PDF_FONTS_UNAVAILABLE: "字体检查需要服务器安装 pdffonts(Poppler),请联系管理员。",
|
|
8
|
+
PDF_FONTS_FAILED: "无法检查 PDF 字体,文件可能损坏或检查超出限制。"
|
|
9
|
+
},
|
|
10
|
+
"zh-Hant": {
|
|
11
|
+
PDF_FONTS_UNAVAILABLE: "字型檢查需要伺服器安裝 pdffonts(Poppler),請聯絡管理員。",
|
|
12
|
+
PDF_FONTS_FAILED: "無法檢查 PDF 字型,檔案可能損毀或檢查超出限制。"
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Errors shared by URL imports and the browser interface. */
|
|
2
|
+
export const projectImportMessages = {
|
|
3
|
+
en: {
|
|
4
|
+
TEMPLATE_URL_INVALID: "Enter an HTTP or HTTPS link to a ZIP file, without sign-in credentials.",
|
|
5
|
+
TEMPLATE_DOWNLOAD_FAILED: "Could not download the template. Check that the link downloads a ZIP without signing in.",
|
|
6
|
+
TEMPLATE_DOWNLOAD_TIMEOUT: "Template download timed out. Try again or upload the ZIP manually.",
|
|
7
|
+
TEMPLATE_DOWNLOAD_TOO_LARGE: "The template exceeds the {{size}} MB download limit."
|
|
8
|
+
},
|
|
9
|
+
zh: {
|
|
10
|
+
TEMPLATE_URL_INVALID: "请输入 HTTP 或 HTTPS ZIP 链接,不含登录凭据。",
|
|
11
|
+
TEMPLATE_DOWNLOAD_FAILED: "无法下载模板,请确认链接无需登录即可下载 ZIP。",
|
|
12
|
+
TEMPLATE_DOWNLOAD_TIMEOUT: "模板下载超时,请重试或手动上传 ZIP。",
|
|
13
|
+
TEMPLATE_DOWNLOAD_TOO_LARGE: "模板超过 {{size}} MB 的下载限制。"
|
|
14
|
+
},
|
|
15
|
+
"zh-Hant": {
|
|
16
|
+
TEMPLATE_URL_INVALID: "請輸入 HTTP 或 HTTPS ZIP 連結,不含登入憑證。",
|
|
17
|
+
TEMPLATE_DOWNLOAD_FAILED: "無法下載範本,請確認連結無需登入即可下載 ZIP。",
|
|
18
|
+
TEMPLATE_DOWNLOAD_TIMEOUT: "範本下載逾時,請重試或手動上傳 ZIP。",
|
|
19
|
+
TEMPLATE_DOWNLOAD_TOO_LARGE: "範本超過 {{size}} MB 的下載限制。"
|
|
20
|
+
}
|
|
21
|
+
};
|