mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 19:36:12 +01:00
#98, new option "initialized" which indicates if setup has been finished
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
const sqlInit = require('../../services/sql_init');
|
||||
const sql = require('../../services/sql');
|
||||
const rp = require('request-promise');
|
||||
const Option = require('../../entities/option');
|
||||
const syncService = require('../../services/sync');
|
||||
const log = require('../../services/log');
|
||||
const setupService = require('../../services/setup');
|
||||
|
||||
async function setupNewDocument(req) {
|
||||
const { username, password } = req.body;
|
||||
@@ -16,44 +12,7 @@ async function setupNewDocument(req) {
|
||||
async function setupSyncFromServer(req) {
|
||||
const { serverAddress, username, password } = req.body;
|
||||
|
||||
try {
|
||||
log.info("Getting document options from sync server.");
|
||||
|
||||
// response is expected to contain documentId and documentSecret options
|
||||
const options = await rp.get({
|
||||
uri: serverAddress + '/api/sync/document',
|
||||
auth: {
|
||||
'user': username,
|
||||
'pass': password
|
||||
},
|
||||
json: true
|
||||
});
|
||||
|
||||
log.info("Creating database for sync");
|
||||
|
||||
await sql.transactional(async () => {
|
||||
await sqlInit.createDatabaseForSync(serverAddress);
|
||||
|
||||
for (const opt of options) {
|
||||
await new Option(opt).save();
|
||||
}
|
||||
});
|
||||
|
||||
log.info("Triggering sync.");
|
||||
|
||||
// it's ok to not wait for it here
|
||||
syncService.sync();
|
||||
|
||||
return { result: 'success' };
|
||||
}
|
||||
catch (e) {
|
||||
log.error("Sync failed: " + e.message);
|
||||
|
||||
return {
|
||||
result: 'failure',
|
||||
error: e.message
|
||||
};
|
||||
}
|
||||
return await setupService.setupSyncFromSyncServer(serverAddress, username, password);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user