mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
etapi ZIP import
This commit is contained in:
parent
74400dad97
commit
3223e76787
@ -33,13 +33,7 @@ paths:
|
|||||||
content:
|
content:
|
||||||
application/json; charset=utf-8:
|
application/json; charset=utf-8:
|
||||||
schema:
|
schema:
|
||||||
properties:
|
$ref: '#/components/schemas/NoteWithBranch'
|
||||||
note:
|
|
||||||
$ref: '#/components/schemas/Note'
|
|
||||||
description: Created note
|
|
||||||
branch:
|
|
||||||
$ref: '#/components/schemas/Branch'
|
|
||||||
description: Created branch
|
|
||||||
default:
|
default:
|
||||||
description: unexpected error
|
description: unexpected error
|
||||||
content:
|
content:
|
||||||
@ -291,6 +285,29 @@ paths:
|
|||||||
application/json; charset=utf-8:
|
application/json; charset=utf-8:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Error'
|
$ref: '#/components/schemas/Error'
|
||||||
|
/notes/{noteId}/import:
|
||||||
|
parameters:
|
||||||
|
- name: noteId
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/EntityId'
|
||||||
|
post:
|
||||||
|
description: Imports ZIP file into a given note.
|
||||||
|
operationId: importZip
|
||||||
|
responses:
|
||||||
|
'201':
|
||||||
|
description: note created
|
||||||
|
content:
|
||||||
|
application/json; charset=utf-8:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/NoteWithBranch'
|
||||||
|
default:
|
||||||
|
description: unexpected error
|
||||||
|
content:
|
||||||
|
application/json; charset=utf-8:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Error'
|
||||||
/notes/{noteId}/note-revision:
|
/notes/{noteId}/note-revision:
|
||||||
parameters:
|
parameters:
|
||||||
- name: noteId
|
- name: noteId
|
||||||
@ -852,6 +869,13 @@ components:
|
|||||||
utcDateModified:
|
utcDateModified:
|
||||||
$ref: '#/components/schemas/UtcDateTime'
|
$ref: '#/components/schemas/UtcDateTime'
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
NoteWithBranch:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
note:
|
||||||
|
$ref: '#/components/schemas/Note'
|
||||||
|
branch:
|
||||||
|
$ref: '#/components/schemas/Branch'
|
||||||
Attribute:
|
Attribute:
|
||||||
type: object
|
type: object
|
||||||
description: Attribute (Label, Relation) is a key-value record attached to a note.
|
description: Attribute (Label, Relation) is a key-value record attached to a note.
|
||||||
|
@ -8,6 +8,7 @@ const v = require("./validators");
|
|||||||
const searchService = require("../services/search/services/search");
|
const searchService = require("../services/search/services/search");
|
||||||
const SearchContext = require("../services/search/search_context");
|
const SearchContext = require("../services/search/search_context");
|
||||||
const zipExportService = require("../services/export/zip");
|
const zipExportService = require("../services/export/zip");
|
||||||
|
const zipImportService = require("../services/import/zip");
|
||||||
|
|
||||||
function register(router) {
|
function register(router) {
|
||||||
eu.route(router, 'get', '/etapi/notes', (req, res, next) => {
|
eu.route(router, 'get', '/etapi/notes', (req, res, next) => {
|
||||||
@ -141,11 +142,21 @@ function register(router) {
|
|||||||
// (e.g. branchIds are not seen in UI), that we export "note export" instead.
|
// (e.g. branchIds are not seen in UI), that we export "note export" instead.
|
||||||
const branch = note.getParentBranches()[0];
|
const branch = note.getParentBranches()[0];
|
||||||
|
|
||||||
console.log(note.getParentBranches());
|
|
||||||
|
|
||||||
zipExportService.exportToZip(taskContext, branch, format, res);
|
zipExportService.exportToZip(taskContext, branch, format, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
eu.route(router, 'post' ,'/etapi/notes/:noteId/import', (req, res, next) => {
|
||||||
|
const note = eu.getAndCheckNote(req.params.noteId);
|
||||||
|
const taskContext = new TaskContext('no-progress-reporting');
|
||||||
|
|
||||||
|
zipImportService.importZip(taskContext, req.body, note).then(importedNote => {
|
||||||
|
res.status(201).json({
|
||||||
|
note: mappers.mapNoteToPojo(importedNote),
|
||||||
|
branch: mappers.mapBranchToPojo(importedNote.getBranches()[0]),
|
||||||
|
});
|
||||||
|
}); // we need better error handling here, async errors won't be properly processed.
|
||||||
|
});
|
||||||
|
|
||||||
eu.route(router, 'post' ,'/etapi/notes/:noteId/note-revision', (req, res, next) => {
|
eu.route(router, 'post' ,'/etapi/notes/:noteId/note-revision', (req, res, next) => {
|
||||||
const note = eu.getAndCheckNote(req.params.noteId);
|
const note = eu.getAndCheckNote(req.params.noteId);
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ const ws = require('./ws');
|
|||||||
const taskContexts = {};
|
const taskContexts = {};
|
||||||
|
|
||||||
class TaskContext {
|
class TaskContext {
|
||||||
constructor(taskId, taskType = null, data = null) {
|
constructor(taskId, taskType = null, data = {}) {
|
||||||
this.taskId = taskId;
|
this.taskId = taskId;
|
||||||
this.taskType = taskType;
|
this.taskType = taskType;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
12
test-etapi/import-zip.http
Normal file
12
test-etapi/import-zip.http
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
POST {{triliumHost}}/etapi/notes/root/import
|
||||||
|
Authorization: {{authToken}}
|
||||||
|
Content-Type: application/octet-stream
|
||||||
|
Content-Transfer-Encoding: binary
|
||||||
|
|
||||||
|
< ../db/demo.zip
|
||||||
|
|
||||||
|
> {%
|
||||||
|
client.assert(response.status === 201);
|
||||||
|
client.assert(response.body.note.title == "Trilium Demo");
|
||||||
|
client.assert(response.body.branch.parentNoteId == "root");
|
||||||
|
%}
|
Loading…
x
Reference in New Issue
Block a user