mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
All: Fixed "Invalid lock client type" error when migrating sync target
This commit is contained in:
parent
78c5877c65
commit
e0e93c436b
@ -5,6 +5,7 @@ import MigrationHandler from '@joplin/lib/services/synchronizer/MigrationHandler
|
|||||||
import ResourceFetcher from '@joplin/lib/services/ResourceFetcher';
|
import ResourceFetcher from '@joplin/lib/services/ResourceFetcher';
|
||||||
import Synchronizer from '@joplin/lib/Synchronizer';
|
import Synchronizer from '@joplin/lib/Synchronizer';
|
||||||
import { masterKeysWithoutPassword } from '@joplin/lib/services/e2ee/utils';
|
import { masterKeysWithoutPassword } from '@joplin/lib/services/e2ee/utils';
|
||||||
|
import { appTypeToLockType } from '@joplin/lib/services/synchronizer/LockHandler';
|
||||||
const { BaseCommand } = require('./base-command.js');
|
const { BaseCommand } = require('./base-command.js');
|
||||||
const { app } = require('./app.js');
|
const { app } = require('./app.js');
|
||||||
const { OneDriveApiNodeUtils } = require('@joplin/lib/onedrive-api-node-utils.js');
|
const { OneDriveApiNodeUtils } = require('@joplin/lib/onedrive-api-node-utils.js');
|
||||||
@ -188,7 +189,7 @@ class Command extends BaseCommand {
|
|||||||
sync.api(),
|
sync.api(),
|
||||||
reg.db(),
|
reg.db(),
|
||||||
sync.lockHandler(),
|
sync.lockHandler(),
|
||||||
Setting.value('appType'),
|
appTypeToLockType(Setting.value('appType')),
|
||||||
Setting.value('clientId')
|
Setting.value('clientId')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import Logger from './Logger';
|
import Logger from './Logger';
|
||||||
import LockHandler, { hasActiveLock, LockClientType, LockType } from './services/synchronizer/LockHandler';
|
import LockHandler, { appTypeToLockType, hasActiveLock, LockClientType, LockType } from './services/synchronizer/LockHandler';
|
||||||
import Setting, { AppType } from './models/Setting';
|
import Setting, { AppType } from './models/Setting';
|
||||||
import shim from './shim';
|
import shim from './shim';
|
||||||
import MigrationHandler from './services/synchronizer/MigrationHandler';
|
import MigrationHandler from './services/synchronizer/MigrationHandler';
|
||||||
@ -53,7 +53,7 @@ export default class Synchronizer {
|
|||||||
|
|
||||||
private db_: JoplinDatabase;
|
private db_: JoplinDatabase;
|
||||||
private api_: FileApi;
|
private api_: FileApi;
|
||||||
private appType_: string;
|
private appType_: AppType;
|
||||||
private logger_: Logger = new Logger();
|
private logger_: Logger = new Logger();
|
||||||
private state_: string = 'idle';
|
private state_: string = 'idle';
|
||||||
private cancelling_: boolean = false;
|
private cancelling_: boolean = false;
|
||||||
@ -77,7 +77,7 @@ export default class Synchronizer {
|
|||||||
|
|
||||||
public dispatch: Function;
|
public dispatch: Function;
|
||||||
|
|
||||||
public constructor(db: JoplinDatabase, api: FileApi, appType: string) {
|
public constructor(db: JoplinDatabase, api: FileApi, appType: AppType) {
|
||||||
this.db_ = db;
|
this.db_ = db;
|
||||||
this.api_ = api;
|
this.api_ = api;
|
||||||
this.appType_ = appType;
|
this.appType_ = appType;
|
||||||
@ -123,13 +123,7 @@ export default class Synchronizer {
|
|||||||
|
|
||||||
private lockClientType(): LockClientType {
|
private lockClientType(): LockClientType {
|
||||||
if (this.lockClientType_) return this.lockClientType_;
|
if (this.lockClientType_) return this.lockClientType_;
|
||||||
|
this.lockClientType_ = appTypeToLockType(this.appType_);
|
||||||
if (this.appType_ === AppType.Desktop) this.lockClientType_ = LockClientType.Desktop;
|
|
||||||
if (this.appType_ === AppType.Mobile) this.lockClientType_ = LockClientType.Mobile;
|
|
||||||
if (this.appType_ === AppType.Cli) this.lockClientType_ = LockClientType.Cli;
|
|
||||||
|
|
||||||
if (!this.lockClientType_) throw new Error(`Invalid client type: ${this.appType_}`);
|
|
||||||
|
|
||||||
return this.lockClientType_;
|
return this.lockClientType_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +135,7 @@ export default class Synchronizer {
|
|||||||
|
|
||||||
maxResourceSize() {
|
maxResourceSize() {
|
||||||
if (this.maxResourceSize_ !== null) return this.maxResourceSize_;
|
if (this.maxResourceSize_ !== null) return this.maxResourceSize_;
|
||||||
return this.appType_ === 'mobile' ? 100 * 1000 * 1000 : Infinity;
|
return this.appType_ === AppType.Mobile ? 100 * 1000 * 1000 : Infinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setShareService(v: ShareService) {
|
public setShareService(v: ShareService) {
|
||||||
|
@ -3,6 +3,7 @@ import shim from '../../shim';
|
|||||||
import JoplinError from '../../JoplinError';
|
import JoplinError from '../../JoplinError';
|
||||||
import time from '../../time';
|
import time from '../../time';
|
||||||
import { FileApi } from '../../file-api';
|
import { FileApi } from '../../file-api';
|
||||||
|
import { AppType } from '../../models/Setting';
|
||||||
const { fileExtension, filename } = require('../../path-utils');
|
const { fileExtension, filename } = require('../../path-utils');
|
||||||
|
|
||||||
export enum LockType {
|
export enum LockType {
|
||||||
@ -46,6 +47,13 @@ export function lockNameToObject(name: string, updatedTime: number = null): Lock
|
|||||||
return lock;
|
return lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function appTypeToLockType(appType: AppType): LockClientType {
|
||||||
|
if (appType === AppType.Desktop) return LockClientType.Desktop;
|
||||||
|
if (appType === AppType.Mobile) return LockClientType.Mobile;
|
||||||
|
if (appType === AppType.Cli) return LockClientType.Cli;
|
||||||
|
throw new Error(`Invalid app type: ${appType}`);
|
||||||
|
}
|
||||||
|
|
||||||
export function hasActiveLock(locks: Lock[], currentDate: Date, lockTtl: number, lockType: LockType, clientType: LockClientType = null, clientId: string = null) {
|
export function hasActiveLock(locks: Lock[], currentDate: Date, lockTtl: number, lockType: LockType, clientType: LockClientType = null, clientId: string = null) {
|
||||||
const lock = activeLock(locks, currentDate, lockTtl, lockType, clientType, clientId);
|
const lock = activeLock(locks, currentDate, lockTtl, lockType, clientType, clientId);
|
||||||
return !!lock;
|
return !!lock;
|
||||||
|
@ -2,6 +2,7 @@ import shim from '../../../shim';
|
|||||||
import MigrationHandler from '../MigrationHandler';
|
import MigrationHandler from '../MigrationHandler';
|
||||||
import Setting from '../../../models/Setting';
|
import Setting from '../../../models/Setting';
|
||||||
import { reg } from '../../../registry';
|
import { reg } from '../../../registry';
|
||||||
|
import { appTypeToLockType } from '../LockHandler';
|
||||||
const { useEffect, useState } = shim.react();
|
const { useEffect, useState } = shim.react();
|
||||||
|
|
||||||
export interface SyncTargetUpgradeResult {
|
export interface SyncTargetUpgradeResult {
|
||||||
@ -28,7 +29,7 @@ export default function useSyncTargetUpgrade(): SyncTargetUpgradeResult {
|
|||||||
synchronizer.api(),
|
synchronizer.api(),
|
||||||
reg.db(),
|
reg.db(),
|
||||||
synchronizer.lockHandler(),
|
synchronizer.lockHandler(),
|
||||||
Setting.value('appType'),
|
appTypeToLockType(Setting.value('appType')),
|
||||||
Setting.value('clientId')
|
Setting.value('clientId')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user