Пример #1
0
  async function backup(options) {
    const config = readYamlConfig(options.config);

    if (options.dev) {
      try {
        merge(config, readYamlConfig(fromRoot('config/kibi.dev.yml')));
      }
      catch (e) {
        // ignore
      }
    }

    if (has(config, 'elasticsearch.ssl.ca')) {
      syswidecas.addCAs(get(config, 'elasticsearch.ssl.ca'));
    }

    let exitCode = 0;
    try {
      const backupKibi = new BackupKibi(config, options.backupDir);
      await backupKibi.backup();
    } catch (error) {
      process.stderr.write(`${error}\n`);
      exitCode = 1;
    }

    process.exit(exitCode);
  }
Пример #2
0
	async generalMiddleware(store, next, action) {
		this.logger().debug('Reducer action', this.reducerActionToString(action));

		const result = next(action);
		const newState = store.getState();
		let refreshNotes = false;

		reduxSharedMiddleware(store, next, action);

		if (action.type == 'FOLDER_SELECT' || action.type === 'FOLDER_DELETE' || (action.type === 'SEARCH_UPDATE' && newState.notesParentType === 'Folder')) {
			Setting.setValue('activeFolderId', newState.selectedFolderId);
			this.currentFolder_ = newState.selectedFolderId ? await Folder.load(newState.selectedFolderId) : null;
			refreshNotes = true;
		}

		if (this.hasGui() && ((action.type == 'SETTING_UPDATE_ONE' && action.key == 'uncompletedTodosOnTop') || action.type == 'SETTING_UPDATE_ALL')) {
			refreshNotes = true;
		}

		if (this.hasGui() && ((action.type == 'SETTING_UPDATE_ONE' && action.key == 'showCompletedTodos') || action.type == 'SETTING_UPDATE_ALL')) {
			refreshNotes = true;
		}

		if (this.hasGui() && ((action.type == 'SETTING_UPDATE_ONE' && action.key.indexOf('notes.sortOrder') === 0) || action.type == 'SETTING_UPDATE_ALL')) {
			refreshNotes = true;
		}

		if (action.type == 'TAG_SELECT' || action.type === 'TAG_DELETE') {
			refreshNotes = true;
		}

		if (action.type == 'SEARCH_SELECT' || action.type === 'SEARCH_DELETE') {
			refreshNotes = true;
		}

		if (refreshNotes) {
			await this.refreshNotes(newState);
		}

		if ((action.type == 'SETTING_UPDATE_ONE' && (action.key == 'dateFormat' || action.key == 'timeFormat')) || (action.type == 'SETTING_UPDATE_ALL')) {
			time.setDateFormat(Setting.value('dateFormat'));
			time.setTimeFormat(Setting.value('timeFormat'));
		}

		if ((action.type == 'SETTING_UPDATE_ONE' && action.key == 'net.ignoreTlsErrors') || (action.type == 'SETTING_UPDATE_ALL')) {
			// https://stackoverflow.com/questions/20082893/unable-to-verify-leaf-signature
			process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = Setting.value('net.ignoreTlsErrors') ? '0' : '1';
		}

		if ((action.type == 'SETTING_UPDATE_ONE' && action.key == 'net.customCertificates') || (action.type == 'SETTING_UPDATE_ALL')) {
			const caPaths = Setting.value('net.customCertificates').split(',');
			for (let i = 0; i < caPaths.length; i++) {
				const f = caPaths[i].trim();
				if (!f) continue;
				syswidecas.addCAs(f);
			}
		}

		if ((action.type == 'SETTING_UPDATE_ONE' && (action.key.indexOf('encryption.') === 0)) || (action.type == 'SETTING_UPDATE_ALL')) {
			if (this.hasGui()) {
				await EncryptionService.instance().loadMasterKeysFromSettings();
				DecryptionWorker.instance().scheduleStart();
				const loadedMasterKeyIds = EncryptionService.instance().loadedMasterKeyIds();

				this.dispatch({
					type: 'MASTERKEY_REMOVE_NOT_LOADED',
					ids: loadedMasterKeyIds,
				});

				// Schedule a sync operation so that items that need to be encrypted
				// are sent to sync target.
				reg.scheduleSync();
			}
		}

		if (action.type === 'NOTE_UPDATE_ONE') {
			// If there is a conflict, we refresh the folders so as to display "Conflicts" folder
			if (action.note && action.note.is_conflict) {
				await FoldersScreenUtils.refreshFolders();
			}
		}

		if (this.hasGui() && action.type == 'SETTING_UPDATE_ONE' && action.key == 'sync.interval' || action.type == 'SETTING_UPDATE_ALL') {
			reg.setupRecurrentSync();
		}

		if (this.hasGui() && action.type === 'SYNC_GOT_ENCRYPTED_ITEM') {
			DecryptionWorker.instance().scheduleStart();
		}

	  	return result;
	}