Libs добавлены в синхронизацию
This commit is contained in:
@@ -35,6 +35,9 @@ export default @Component({
|
|||||||
currentProfile: function() {
|
currentProfile: function() {
|
||||||
this.currentProfileChanged(true);
|
this.currentProfileChanged(true);
|
||||||
},
|
},
|
||||||
|
libs: function() {
|
||||||
|
this.debouncedSaveLibs();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
class ServerStorage extends Vue {
|
class ServerStorage extends Vue {
|
||||||
@@ -49,12 +52,17 @@ class ServerStorage extends Vue {
|
|||||||
this.saveSettings();
|
this.saveSettings();
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
this.debouncedSaveLibs = _.debounce(() => {
|
||||||
|
this.saveLibs();
|
||||||
|
}, 500);
|
||||||
|
|
||||||
this.debouncedNotifySuccess = _.debounce(() => {
|
this.debouncedNotifySuccess = _.debounce(() => {
|
||||||
this.success('Данные синхронизированы с сервером');
|
this.success('Данные синхронизированы с сервером');
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
this.oldProfiles = {};
|
this.oldProfiles = {};
|
||||||
this.oldSettings = {};
|
this.oldSettings = {};
|
||||||
|
this.oldLibs = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
@@ -124,6 +132,8 @@ class ServerStorage extends Vue {
|
|||||||
await this.loadProfiles(force);
|
await this.loadProfiles(force);
|
||||||
this.checkCurrentProfile();
|
this.checkCurrentProfile();
|
||||||
await this.currentProfileChanged(force);
|
await this.currentProfileChanged(force);
|
||||||
|
await this.loadLibs(force);
|
||||||
|
|
||||||
const loadSuccess = await this.loadRecent();
|
const loadSuccess = await this.loadRecent();
|
||||||
if (loadSuccess && force)
|
if (loadSuccess && force)
|
||||||
await this.saveRecent();
|
await this.saveRecent();
|
||||||
@@ -169,6 +179,14 @@ class ServerStorage extends Vue {
|
|||||||
return this.settings.showServerStorageMessages;
|
return this.settings.showServerStorageMessages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get libs() {
|
||||||
|
return this.$store.state.reader.libs;
|
||||||
|
}
|
||||||
|
|
||||||
|
get libsRev() {
|
||||||
|
return this.$store.state.reader.libsRev;
|
||||||
|
}
|
||||||
|
|
||||||
checkCurrentProfile() {
|
checkCurrentProfile() {
|
||||||
if (!this.profiles[this.currentProfile]) {
|
if (!this.profiles[this.currentProfile]) {
|
||||||
this.commit('reader/setCurrentProfile', '');
|
this.commit('reader/setCurrentProfile', '');
|
||||||
@@ -345,6 +363,78 @@ class ServerStorage extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async loadLibs(force = false, doNotifySuccess = true) {
|
||||||
|
if (!this.keyInited || !this.serverSyncEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const oldRev = this.libsRev;
|
||||||
|
//проверим ревизию на сервере
|
||||||
|
if (!force) {
|
||||||
|
try {
|
||||||
|
const revs = await this.storageCheck({libs: {}});
|
||||||
|
if (revs.state == 'success' && revs.items.libs.rev == oldRev) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
this.error(`Ошибка соединения с сервером: ${e.message}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let libs = null;
|
||||||
|
try {
|
||||||
|
libs = await this.storageGet({libs: {}});
|
||||||
|
} catch(e) {
|
||||||
|
this.error(`Ошибка соединения с сервером: ${e.message}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (libs.state == 'success') {
|
||||||
|
libs = libs.items.libs;
|
||||||
|
|
||||||
|
if (libs.rev == 0)
|
||||||
|
libs.data = {};
|
||||||
|
|
||||||
|
this.oldLibs = _.cloneDeep(libs.data);
|
||||||
|
this.commit('reader/setLibs', libs.data);
|
||||||
|
this.commit('reader/setLibsRev', libs.rev);
|
||||||
|
|
||||||
|
if (doNotifySuccess)
|
||||||
|
this.debouncedNotifySuccess();
|
||||||
|
} else {
|
||||||
|
this.warning(`Неверный ответ сервера: ${libs.state}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async saveLibs() {
|
||||||
|
if (!this.keyInited || !this.serverSyncEnabled || this.savingLibs)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const diff = utils.getObjDiff(this.oldLibs, this.libs);
|
||||||
|
if (utils.isEmptyObjDiff(diff))
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.savingLibs = true;
|
||||||
|
try {
|
||||||
|
let result = {state: ''};
|
||||||
|
try {
|
||||||
|
result = await this.storageSet({libs: {rev: this.libsRev + 1, data: this.libs}});
|
||||||
|
} catch(e) {
|
||||||
|
this.error(`Ошибка соединения с сервером (${e.message}). Данные не сохранены и могут быть перезаписаны.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.state == 'reject') {
|
||||||
|
await this.loadLibs(true, false);
|
||||||
|
this.warning(`Последние изменения отменены. Данные синхронизированы с сервером.`);
|
||||||
|
} else if (result.state == 'success') {
|
||||||
|
this.oldLibs = _.cloneDeep(this.libs);
|
||||||
|
this.commit('reader/setLibsRev', this.libsRev + 1);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.savingLibs = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async loadRecent(skipRevCheck = false, doNotifySuccess = true) {
|
async loadRecent(skipRevCheck = false, doNotifySuccess = true) {
|
||||||
if (!this.keyInited || !this.serverSyncEnabled || this.loadingRecent)
|
if (!this.keyInited || !this.serverSyncEnabled || this.loadingRecent)
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user