Skip to content

Build your personal knowledge base with Trilium Notes

refactor(etapi): drop restoreAsRoot from the note import endpoint

Elian Doran2dd76c4383de
diff --git a/apps/server/spec/etapi/import-zip.spec.ts b/apps/server/spec/etapi/import-zip.spec.ts
index f0f5d7b0ae..a1aba2ca01 100644
--- a/apps/server/spec/etapi/import-zip.spec.ts
+++ b/apps/server/spec/etapi/import-zip.spec.ts
@@ -32,9 +32,9 @@ describe("etapi/import", () => {
// A Trilium root-export (its top note is "root") imported into root is nested under a "root"
// wrapper note rather than being remapped onto / merged into the system root - that would
- // create a self-referential root->root branch that breaks loading. Whole-database *restore*
- // (the demo content on first run) instead passes the restoreAsRoot import option, which maps
- // the archive's root onto the destination root - see trilium-core import/zip.spec.ts.
+ // create a self-referential root->root branch that breaks loading. (Whole-database *restore*,
+ // which maps the archive's root onto the destination root, is an internal-only option used by
+ // the demo-content seed - it is deliberately not exposed over ETAPI. See import/zip.spec.ts.)
expect(response.body.note.title).toStrictEqual("root");
expect(response.body.branch.parentNoteId).toStrictEqual("root");
@@ -43,21 +43,4 @@ describe("etapi/import", () => {
expect(wrapper?.getChildNotes().map((n) => n.title)).toEqual(expect.arrayContaining(["Journal", "Trilium Demo", "Miscellaneous"]));
expect(becca.getBranchFromChildAndParent("root", "root")).toBeFalsy();
});
-
- it("demo zip imports flat under root with ?restoreAsRoot=true (whole-database restore)", async () => {
- const buffer = readFileSync(join(__dirname, "../../src/assets/db/demo.zip"));
- const response = await supertest(app)
- .post("/etapi/notes/root/import?restoreAsRoot=true")
- .auth(USER, token, { "type": "basic"})
- .set("Content-Type", "application/octet-stream")
- .set("Content-Transfer-Encoding", "binary")
- .send(buffer)
- .expect(201);
-
- // restoreAsRoot maps the archive's "root" onto the destination root, so its children land directly
- // under root (no wrapper note) and no self-referential root->root branch is created.
- expect(response.body.note.title).toStrictEqual("Journal");
- expect(response.body.branch.parentNoteId).toStrictEqual("root");
- expect(becca.getBranchFromChildAndParent("root", "root")).toBeFalsy();
- });
});
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Import & Export.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Import & Export.html
index 19a4595ec4..38dab51550 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Import & Export.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Import & Export.html
@@ -11,7 +11,7 @@
>Note that HTML is not a standardized format so some more specific features
such as admonitions or&nbsp;<a class="reference-link" href="#root/_help_hrZ1D00cLbal">Internal (reference) links</a>&nbsp;might
not be supported by other applications.</li>
- <li>The notes can also be exported as <a href="#root/pOsGYCXsbNQG/tC7s2alapj8V/R9pX4DGra2Vt/_help_ycBFjKrrwE9p">static HTML that can be used for web publishing</a>.</li>
+ <li>The notes can also be exported as <a href="#root/_help_ycBFjKrrwE9p">static HTML that can be used for web publishing</a>.</li>
</ul>
</li>
<li><a class="reference-link" href="#root/_help_Oau6X9rCuegd">Markdown</a>
@@ -57,19 +57,19 @@
</aside>
<h2>Exporting the root note</h2>
<p>The root note is the top-most note. Exporting it behaves just like any
- other note: right click on it in the&nbsp;<a class="reference-link" href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/Vc8PjrjAGuOp/_help_oPVyFC7WL2Lp">Note Tree</a>&nbsp;and
+ other note: right click on it in the&nbsp;<a class="reference-link" href="#root/_help_oPVyFC7WL2Lp">Note Tree</a>&nbsp;and
select <em>Export</em>.</p>
<p>Starting with v0.104.0, when a root note is imported, it will be imported
as a child of your existing root note. This behavior makes sure that the
import cannot change or overwrite your existing notes.</p>
<p>You can easily move the notes onto the root using the tree's&nbsp;<a class="reference-link"
- href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/Vc8PjrjAGuOp/oPVyFC7WL2Lp/_help_yTjUdsOi4CIE">Multiple selection</a>&nbsp;and
- delete the redundant root note.</p>
+ href="#root/_help_yTjUdsOi4CIE">Multiple selection</a>&nbsp;and delete the redundant
+ root note.</p>
<figure class="table">
<table>
<thead>
<tr>
- <th style="width:50%;" scope="col">Before</th>
+ <th scope="col">Before</th>
<th scope="col">After</th>
</tr>
</thead>
@@ -104,10 +104,9 @@
</table>
</figure>
<aside class="admonition tip">
- <ul>
- <li>Consider using <a href="#root/pOsGYCXsbNQG/Otzi9La2YAUX/_help_ODY7qQn5m2FT">backups</a> instead
- of full root note.</li>
- <li><a class="reference-link" href="#root/pOsGYCXsbNQG/tC7s2alapj8V/_help_pgxEVkzLl1OP">ETAPI (REST API)</a>&nbsp;can
- bypass this import behavior using the <code spellcheck="false">restoreAsRoot</code> option.</li>
- </ul>
+ <p>Instead of exporting full ZIPs (including the root note), consider using
+ <a
+ href="#root/_help_ODY7qQn5m2FT">backups</a>instead. Backups always contain the entire structure, as well
+ as additional information a ZIP export does not have: maintains note IDs,
+ contains the options/tokens and handle&nbsp;<a class="reference-link" href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/BFs8mudNFgCS/_help_bwg0e8ewQMak">Protected Notes</a>&nbsp;better.</p>
</aside>
\ No newline at end of file
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Import & Export/Importing data from other applications.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Import & Export/Importing data from other applications.html
index 9ae42a9f67..334d09147c 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Import & Export/Importing data from other applications.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Import & Export/Importing data from other applications.html
@@ -10,13 +10,12 @@
ZIP export.</li>
<li><a class="reference-link" href="#root/_help_nhQVuO4zvIxi">Google Keep</a>, via
a ZIP export from <em>Google Takeout</em> (Keep has no dedicated export mechanism).</li>
- <li
- ><a class="reference-link" href="#root/_help_syuSEKf2rUGr">Evernote</a>, via
+ <li><a class="reference-link" href="#root/_help_syuSEKf2rUGr">Evernote</a>, via
an ENEX export.</li>
- <li><a class="reference-link" href="#root/_help_83zmPBJRgfnW">Anytype</a>, via a
- JSON export.</li>
- <li><a class="reference-link" href="#root/_help_iWD7wiIuMtgV">Obsidian</a>, via
- a ZIP of the vault.</li>
+ <li><a class="reference-link" href="#root/_help_83zmPBJRgfnW">Anytype</a>, via a
+ JSON export.</li>
+ <li><a class="reference-link" href="#root/_help_iWD7wiIuMtgV">Obsidian</a>, via
+ a ZIP of the vault.</li>
</ul>
<h2>Importing data from another application</h2>
<p>To import from an application, there are two ways to access the import
@@ -39,9 +38,8 @@
<li><a href="https://pictogrammers.com/library/mdi/">Material Design Icons</a> for
OneNote, Google Keep, Evernote.</li>
<li><a href="https://fontawesome.com/">Font Awesome</a> for Notion, Obsidian.</li>
- <li
- ><a href="https://svgicons.com/icon/187676/anytype">SVGicons.com</a> for
+ <li><a href="https://svgicons.com/icon/187676/anytype">SVGicons.com</a> for
Anytype.</li>
- </ul>
+ </ul>
</li>
</ul>
\ No newline at end of file
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Tree Concepts.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Tree Concepts.html
index 5a7d31773b..aafd4a8dbc 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Tree Concepts.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Tree Concepts.html
@@ -3,7 +3,7 @@
<h2>Note</h2>
<p>A note is the central entity in TriliumNext. For more details, see&nbsp;
<a
- class="reference-link" href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/_help_BFs8mudNFgCS">Notes</a>.</p>
+ class="reference-link" href="#root/_help_BFs8mudNFgCS">Notes</a>.</p>
<h2>Branch</h2>
<p>A branch describes the placement of a note within the note tree. Essentially,
it is a tuple of <code spellcheck="false">parentNoteId</code> and <code spellcheck="false">noteId</code>,
@@ -12,7 +12,7 @@
<p>Each note can have multiple branches, meaning any note can be placed in
multiple locations within the tree. This concept is referred to as&nbsp;
<a
- class="reference-link" href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/BFs8mudNFgCS/_help_IakOLONlIfGI">Cloning Notes</a>.</p>
+ class="reference-link" href="#root/_help_IakOLONlIfGI">Cloning Notes</a>.</p>
<h2>Prefix</h2>
<p>A prefix is a branch-specific title modifier for a note. If you place
your note in two different locations within the tree and want to alter
diff --git a/apps/server/src/assets/etapi.openapi.yaml b/apps/server/src/assets/etapi.openapi.yaml
index 5685e8f4c6..99e5a98c70 100644
--- a/apps/server/src/assets/etapi.openapi.yaml
+++ b/apps/server/src/assets/etapi.openapi.yaml
@@ -294,16 +294,6 @@ paths:
required: true
schema:
$ref: "#/components/schemas/EntityId"
- - name: restoreAsRoot
- in: query
- required: false
- description: >-
- When importing a whole-database ZIP export (one whose top note is the database root), map
- the archive's "root" note onto {noteId} instead of nesting it under a redundant "root"
- wrapper note. Typically used with noteId "root" to restore an entire database.
- schema:
- type: boolean
- default: false
post:
description: Imports ZIP file into a given note.
operationId: importZip
diff --git a/apps/server/src/etapi/notes.ts b/apps/server/src/etapi/notes.ts
index 731e4de40b..1dec2c0895 100644
--- a/apps/server/src/etapi/notes.ts
+++ b/apps/server/src/etapi/notes.ts
@@ -173,11 +173,7 @@ function register(router: Router) {
const note = eu.getAndCheckNote(req.params.noteId);
const taskContext = new TaskContext("no-progress-reporting", "importNotes", null);
- // Whole-database restore: map the archive's "root" note onto the target note instead of nesting it
- // in a redundant "root" wrapper. Use when importing a Trilium root export into "root".
- const restoreAsRoot = req.query.restoreAsRoot === "true";
-
- zipImportService.importZip(taskContext, req.body, note, { restoreAsRoot }).then((importedNote) => {
+ zipImportService.importZip(taskContext, req.body, note).then((importedNote) => {
res.status(201).json({
note: mappers.mapNoteToPojo(importedNote),
branch: mappers.mapBranchToPojo(importedNote.getParentBranches()[0])
diff --git a/docs/User Guide/!!!meta.json b/docs/User Guide/!!!meta.json
index b49d44c805..db4a0ab9b7 100644
--- a/docs/User Guide/!!!meta.json
+++ b/docs/User Guide/!!!meta.json
@@ -5757,6 +5757,20 @@
"type": "text",
"mime": "text/markdown",
"attributes": [
+ {
+ "type": "relation",
+ "name": "internalLink",
+ "value": "BFs8mudNFgCS",
+ "isInheritable": false,
+ "position": 10
+ },
+ {
+ "type": "relation",
+ "name": "internalLink",
+ "value": "IakOLONlIfGI",
+ "isInheritable": false,
+ "position": 20
+ },
{
"type": "label",
"name": "shareAlias",
@@ -5770,20 +5784,6 @@
"value": "bx bx-pyramid",
"isInheritable": false,
"position": 30
- },
- {
- "type": "relation",
- "name": "internalLink",
- "value": "BFs8mudNFgCS",
- "isInheritable": false,
- "position": 40
- },
- {
- "type": "relation",
- "name": "internalLink",
- "value": "IakOLONlIfGI",
- "isInheritable": false,
- "position": 50
}
],
"format": "markdown",
@@ -6909,112 +6909,112 @@
{
"type": "relation",
"name": "internalLink",
- "value": "Oau6X9rCuegd",
+ "value": "ycBFjKrrwE9p",
"isInheritable": false,
"position": 20
},
{
"type": "relation",
"name": "internalLink",
- "value": "rJ9grSgoExl9",
+ "value": "Oau6X9rCuegd",
"isInheritable": false,
"position": 30
},
{
"type": "relation",
"name": "internalLink",
- "value": "ckZ2uNWQmVeX",
+ "value": "rJ9grSgoExl9",
"isInheritable": false,
"position": 40
},
{
"type": "relation",
"name": "internalLink",
- "value": "W8vYD3Q1zjCR",
+ "value": "ckZ2uNWQmVeX",
"isInheritable": false,
"position": 50
},
{
"type": "relation",
"name": "internalLink",
- "value": "0vhv7lsOLy82",
+ "value": "W8vYD3Q1zjCR",
"isInheritable": false,
"position": 60
},
{
"type": "relation",
"name": "internalLink",
- "value": "iPIMuisry3hd",
+ "value": "0vhv7lsOLy82",
"isInheritable": false,
"position": 70
},
{
"type": "relation",
"name": "internalLink",
- "value": "cbkrhQjrkKrh",
+ "value": "iPIMuisry3hd",
"isInheritable": false,
"position": 80
},
{
"type": "relation",
"name": "internalLink",
- "value": "poXkQfguuA0U",
+ "value": "cbkrhQjrkKrh",
"isInheritable": false,
"position": 90
},
{
"type": "relation",
"name": "internalLink",
- "value": "oPVyFC7WL2Lp",
+ "value": "poXkQfguuA0U",
"isInheritable": false,
"position": 100
},
{
"type": "relation",
"name": "internalLink",
- "value": "8YBEPzcpUgxw",
+ "value": "oPVyFC7WL2Lp",
"isInheritable": false,
"position": 110
},
- {
- "type": "label",
- "name": "iconClass",
- "value": "bx bx-import",
- "isInheritable": false,
- "position": 10
- },
- {
- "type": "label",
- "name": "shareAlias",
- "value": "import-export",
- "isInheritable": false,
- "position": 20
- },
{
"type": "relation",
"name": "internalLink",
- "value": "ycBFjKrrwE9p",
+ "value": "8YBEPzcpUgxw",
"isInheritable": false,
"position": 120
},
{
"type": "relation",
"name": "internalLink",
- "value": "ODY7qQn5m2FT",
+ "value": "yTjUdsOi4CIE",
"isInheritable": false,
"position": 130
},
{
"type": "relation",
"name": "internalLink",
- "value": "pgxEVkzLl1OP",
+ "value": "ODY7qQn5m2FT",
"isInheritable": false,
"position": 140
},
+ {
+ "type": "label",
+ "name": "iconClass",
+ "value": "bx bx-import",
+ "isInheritable": false,
+ "position": 10
+ },
+ {
+ "type": "label",
+ "name": "shareAlias",
+ "value": "import-export",
+ "isInheritable": false,
+ "position": 20
+ },
{
"type": "relation",
"name": "internalLink",
- "value": "yTjUdsOi4CIE",
+ "value": "bwg0e8ewQMak",
"isInheritable": false,
"position": 150
}
diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/Import & Export.md b/docs/User Guide/User Guide/Basic Concepts and Features/Import & Export.md
index 4a50b90a47..e9fe8449e2 100644
--- a/docs/User Guide/User Guide/Basic Concepts and Features/Import & Export.md
+++ b/docs/User Guide/User Guide/Basic Concepts and Features/Import & Export.md
@@ -38,8 +38,7 @@ Starting with v0.104.0, when a root note is imported, it will be imported as a c
You can easily move the notes onto the root using the tree's <a class="reference-link" href="UI%20Elements/Note%20Tree/Multiple%20selection.md">Multiple selection</a> and delete the redundant root note.
-<table><thead><tr><th style="width:50%;" scope="col">Before</th><th scope="col">After</th></tr></thead><tbody><tr><td><ul><li data-list-item-id="e8c5b61fca3b22a75ee4f651a12b0cd2b">root<ul><li data-list-item-id="e1e4f62c9fe4499cabfefcba28bf64c7e">one</li><li data-list-item-id="e8088b4ea90e8371d88182db886b8fd1f">two</li></ul></li></ul></td><td><ul><li data-list-item-id="e74bf0ef3d3f2aff13bb3918d1e23e06f">root (existing)<ul><li data-list-item-id="efcba337fd0db50e4d83740d986d04b00">root (from import)<ul><li data-list-item-id="e50b95f63c2069dbf902c281256c32155">one</li><li data-list-item-id="e406337a40071ddfc3c5b1432ba235a2e">two</li></ul></li></ul></li></ul></td></tr></tbody></table>
+<table><thead><tr><th scope="col">Before</th><th scope="col">After</th></tr></thead><tbody><tr><td><ul><li data-list-item-id="e8c5b61fca3b22a75ee4f651a12b0cd2b">root<ul><li data-list-item-id="e1e4f62c9fe4499cabfefcba28bf64c7e">one</li><li data-list-item-id="e8088b4ea90e8371d88182db886b8fd1f">two</li></ul></li></ul></td><td><ul><li data-list-item-id="e74bf0ef3d3f2aff13bb3918d1e23e06f">root (existing)<ul><li data-list-item-id="efcba337fd0db50e4d83740d986d04b00">root (from import)<ul><li data-list-item-id="e50b95f63c2069dbf902c281256c32155">one</li><li data-list-item-id="e406337a40071ddfc3c5b1432ba235a2e">two</li></ul></li></ul></li></ul></td></tr></tbody></table>
> [!TIP]
-> * Consider using [backups](../Installation%20%26%20Setup/Backup.md) instead of full root note.
-> * <a class="reference-link" href="../Advanced%20Usage/ETAPI%20(REST%20API).md">ETAPI (REST API)</a> can bypass this import behavior using the `restoreAsRoot` option.
\ No newline at end of file
+> Instead of exporting full ZIPs (including the root note), consider using [backups](../Installation%20%26%20Setup/Backup.md) instead. Backups always contain the entire structure, as well as additional information a ZIP export does not have: maintains note IDs, contains the options/tokens and handle <a class="reference-link" href="Notes/Protected%20Notes.md">Protected Notes</a> better.
\ No newline at end of file