|
@@ -17,6 +17,9 @@ const maxSetTries = 5;
|
|
|
|
|
|
export default @Component({
|
|
export default @Component({
|
|
watch: {
|
|
watch: {
|
|
|
|
+ serverStorageKey: function() {
|
|
|
|
+ this.serverStorageKeyChanged();
|
|
|
|
+ },
|
|
profiles: function() {
|
|
profiles: function() {
|
|
this.saveProfiles();
|
|
this.saveProfiles();
|
|
},
|
|
},
|
|
@@ -25,17 +28,27 @@ export default @Component({
|
|
class ServerStorage extends Vue {
|
|
class ServerStorage extends Vue {
|
|
created() {
|
|
created() {
|
|
this.commit = this.$store.commit;
|
|
this.commit = this.$store.commit;
|
|
|
|
+ this.prevServerStorageKey = null;
|
|
|
|
+ this.$root.$on('generateNewServerStorageKey', () => {this.generateNewServerStorageKey()});
|
|
}
|
|
}
|
|
|
|
|
|
async init() {
|
|
async init() {
|
|
if (!this.serverStorageKey) {
|
|
if (!this.serverStorageKey) {
|
|
//генерируем новый ключ
|
|
//генерируем новый ключ
|
|
- this.generateNewServerStorageKey();
|
|
|
|
|
|
+ await this.generateNewServerStorageKey();
|
|
|
|
+ } else {
|
|
|
|
+ await this.serverStorageKeyChanged();
|
|
}
|
|
}
|
|
- this.hashedStorageKey = utils.toBase58(cryptoUtils.sha256(this.serverStorageKey));
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- await this.loadProfiles();
|
|
|
|
- this.checkCurrentProfile();
|
|
|
|
|
|
+ async serverStorageKeyChanged() {
|
|
|
|
+ if (this.prevServerStorageKey != this.serverStorageKey) {
|
|
|
|
+ this.prevServerStorageKey = this.serverStorageKey;
|
|
|
|
+ this.hashedStorageKey = utils.toBase58(cryptoUtils.sha256(this.serverStorageKey));
|
|
|
|
+
|
|
|
|
+ await this.loadProfiles();
|
|
|
|
+ this.checkCurrentProfile();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
get serverSyncEnabled() {
|
|
get serverSyncEnabled() {
|
|
@@ -94,11 +107,10 @@ class ServerStorage extends Vue {
|
|
if (prof.rev == 0)
|
|
if (prof.rev == 0)
|
|
prof.data = {};
|
|
prof.data = {};
|
|
|
|
|
|
|
|
+ this.oldProfiles = prof.data;
|
|
this.commit('reader/setProfiles', prof.data);
|
|
this.commit('reader/setProfiles', prof.data);
|
|
this.commit('reader/setProfilesRev', prof.rev);
|
|
this.commit('reader/setProfilesRev', prof.rev);
|
|
|
|
|
|
- this.oldProfiles = this.profiles;
|
|
|
|
-
|
|
|
|
this.notifySuccessIfNeeded(oldRev, prof.rev);
|
|
this.notifySuccessIfNeeded(oldRev, prof.rev);
|
|
} else {
|
|
} else {
|
|
this.warning(`Неверный ответ сервера: ${prof.state}`);
|
|
this.warning(`Неверный ответ сервера: ${prof.state}`);
|
|
@@ -142,9 +154,10 @@ class ServerStorage extends Vue {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- generateNewServerStorageKey() {
|
|
|
|
|
|
+ async generateNewServerStorageKey() {
|
|
const key = utils.toBase58(utils.randomArray(32));
|
|
const key = utils.toBase58(utils.randomArray(32));
|
|
this.commit('reader/setServerStorageKey', key);
|
|
this.commit('reader/setServerStorageKey', key);
|
|
|
|
+ await this.serverStorageKeyChanged();
|
|
}
|
|
}
|
|
|
|
|
|
async storageCheck(items) {
|
|
async storageCheck(items) {
|