You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-29 22:48:10 +02:00
Fixed RN sync issue
This commit is contained in:
@@ -9,14 +9,33 @@ class BaseItem extends BaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
static loadClass(className, classRef) {
|
||||
for (let i = 0; i < BaseItem.syncItemDefinitions_.length; i++) {
|
||||
if (BaseItem.syncItemDefinitions_[i].className == className) {
|
||||
BaseItem.syncItemDefinitions_[i].classRef = classRef;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('Invalid class name: ' + className);
|
||||
}
|
||||
|
||||
// Need to dynamically load the classes like this to avoid circular dependencies
|
||||
static getClass(name) {
|
||||
if (!this.classes_) this.classes_ = {};
|
||||
if (this.classes_[name]) return this.classes_[name];
|
||||
let filename = name.toLowerCase();
|
||||
if (name == 'NoteTag') filename = 'note-tag';
|
||||
this.classes_[name] = require('lib/models/' + filename + '.js')[name];
|
||||
return this.classes_[name];
|
||||
for (let i = 0; i < BaseItem.syncItemDefinitions_.length; i++) {
|
||||
if (BaseItem.syncItemDefinitions_[i].className == name) {
|
||||
return BaseItem.syncItemDefinitions_[i].classRef;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('Invalid class name: ' + name);
|
||||
|
||||
// if (!this.classes_) this.classes_ = {};
|
||||
// if (this.classes_[name]) return this.classes_[name];
|
||||
// let filename = name.toLowerCase();
|
||||
// if (name == 'NoteTag') filename = 'note-tag';
|
||||
// this.classes_[name] = require('lib/models/' + filename + '.js')[name];
|
||||
// return this.classes_[name];
|
||||
}
|
||||
|
||||
static systemPath(itemOrId) {
|
||||
@@ -229,6 +248,12 @@ class BaseItem extends BaseModel {
|
||||
|
||||
}
|
||||
|
||||
// import { Note } from 'lib/models/note.js';
|
||||
// import { Folder } from 'lib/models/folder.js';
|
||||
// import { Resource } from 'lib/models/resource.js';
|
||||
// import { Tag } from 'lib/models/tag.js';
|
||||
// import { NoteTag } from 'lib/models/note-tag.js';
|
||||
|
||||
// Also update:
|
||||
// - itemsThatNeedSync()
|
||||
// - syncedItems()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { shim } from 'lib/shim.js';
|
||||
import { stringify } from 'query-string';
|
||||
import { time } from 'lib/time-utils.js';
|
||||
|
||||
class OneDriveApi {
|
||||
|
||||
@@ -133,15 +134,6 @@ class OneDriveApi {
|
||||
|
||||
if (data) options.body = data;
|
||||
|
||||
// Rare error (one Google hit) - maybe repeat the request when it happens?
|
||||
|
||||
// { error:
|
||||
// { code: 'generalException',
|
||||
// message: 'An error occurred in the data store.',
|
||||
// innerError:
|
||||
// { 'request-id': 'b4310552-c18a-45b1-bde1-68e2c2345eef',
|
||||
// date: '2017-06-29T00:15:50' } } }
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
options.headers['Authorization'] = 'bearer ' + this.token();
|
||||
|
||||
@@ -153,6 +145,26 @@ class OneDriveApi {
|
||||
if (error.code == 'InvalidAuthenticationToken') {
|
||||
await this.refreshAccessToken();
|
||||
continue;
|
||||
} else if (error && ((error.error && error.error.code == 'generalException') || (error.code == 'generalException'))) {
|
||||
// Rare error (one Google hit) - I guess the request can be repeated
|
||||
|
||||
// { error:
|
||||
// { code: 'generalException',
|
||||
// message: 'An error occurred in the data store.',
|
||||
// innerError:
|
||||
// { 'request-id': 'b4310552-c18a-45b1-bde1-68e2c2345eef',
|
||||
// date: '2017-06-29T00:15:50' } } }
|
||||
await time.msleep(1000 * i);
|
||||
continue;
|
||||
} else if (error.code == 'EAGAIN') {
|
||||
// { FetchError: request to https://graph.microsoft.com/v1.0/drive/root:/Apps/Joplin/.sync/7ee5dc04afcb414aa7c684bfc1edba8b.md_1499352102856 failed, reason: connect EAGAIN 65.52.64.250:443 - Local (0.0.0.0:54374)
|
||||
// name: 'FetchError',
|
||||
// message: 'request to https://graph.microsoft.com/v1.0/drive/root:/Apps/Joplin/.sync/7ee5dc04afcb414aa7c684bfc1edba8b.md_1499352102856 failed, reason: connect EAGAIN 65.52.64.250:443 - Local (0.0.0.0:54374)',
|
||||
// type: 'system',
|
||||
// errno: 'EAGAIN',
|
||||
// code: 'EAGAIN' }
|
||||
await time.msleep(1000 * i);
|
||||
continue;
|
||||
} else {
|
||||
error.request = method + ' ' + url + ' ' + JSON.stringify(query) + ' ' + JSON.stringify(data) + ' ' + JSON.stringify(options);
|
||||
throw error;
|
||||
|
||||
@@ -313,12 +313,12 @@ class Synchronizer {
|
||||
};
|
||||
if (action == 'createLocal') options.isNew = true;
|
||||
|
||||
if (newContent.type_ == BaseModel.TYPE_RESOURCE && action == 'createLocal') {
|
||||
let localResourceContentPath = Resource.fullPath(newContent);
|
||||
let remoteResourceContentPath = this.resourceDirName_ + '/' + newContent.id;
|
||||
let remoteResourceContent = await this.api().get(remoteResourceContentPath, { encoding: 'binary' });
|
||||
await Resource.setContent(newContent, remoteResourceContent);
|
||||
}
|
||||
// if (newContent.type_ == BaseModel.TYPE_RESOURCE && action == 'createLocal') {
|
||||
// let localResourceContentPath = Resource.fullPath(newContent);
|
||||
// let remoteResourceContentPath = this.resourceDirName_ + '/' + newContent.id;
|
||||
// let remoteResourceContent = await this.api().get(remoteResourceContentPath, { encoding: 'binary' });
|
||||
// await Resource.setContent(newContent, remoteResourceContent);
|
||||
// }
|
||||
|
||||
await ItemClass.save(newContent, options);
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@ import { addNavigationHelpers } from 'react-navigation';
|
||||
import { Log } from 'lib/log.js'
|
||||
import { Note } from 'lib/models/note.js'
|
||||
import { Folder } from 'lib/models/folder.js'
|
||||
import { Resource } from 'lib/models/resource.js'
|
||||
import { Tag } from 'lib/models/tag.js'
|
||||
import { NoteTag } from 'lib/models/note-tag.js'
|
||||
import { BaseItem } from 'lib/models/base-item.js'
|
||||
import { BaseModel } from 'lib/base-model.js'
|
||||
import { Database } from 'lib/database.js'
|
||||
import { ItemList } from 'lib/components/item-list.js'
|
||||
@@ -199,7 +203,13 @@ class AppComponent extends React.Component {
|
||||
NotesScreenUtils.dispatch = this.props.dispatch;
|
||||
BaseModel.db_ = db;
|
||||
|
||||
db.open({ name: '/storage/emulated/0/Download/joplin-43.sqlite' }).then(() => {
|
||||
BaseItem.loadClass('Note', Note);
|
||||
BaseItem.loadClass('Folder', Folder);
|
||||
BaseItem.loadClass('Resource', Resource);
|
||||
BaseItem.loadClass('Tag', Tag);
|
||||
BaseItem.loadClass('NoteTag', NoteTag);
|
||||
|
||||
db.open({ name: '/storage/emulated/0/Download/joplin-44.sqlite' }).then(() => {
|
||||
Log.info('Database is ready.');
|
||||
}).then(() => {
|
||||
Log.info('Loading settings...');
|
||||
|
||||
Reference in New Issue
Block a user