diff options
author | 2020-01-31 13:40:00 +0100 | |
---|---|---|
committer | 2020-01-31 13:40:00 +0100 | |
commit | 0a89e919b3caf4d4935d135d687ad5b31bdc4441 (patch) | |
tree | aed2ede067e7294c7e945f334d5d4e8e77907b03 | |
parent | #285 Fix DarkReader for FastMail (diff) | |
download | ferdium-app-0a89e919b3caf4d4935d135d687ad5b31bdc4441.tar.gz ferdium-app-0a89e919b3caf4d4935d135d687ad5b31bdc4441.tar.zst ferdium-app-0a89e919b3caf4d4935d135d687ad5b31bdc4441.zip |
#328 Implement local updates
-rw-r--r-- | package-lock.json | 2 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/stores/RecipesStore.js | 29 |
3 files changed, 30 insertions, 3 deletions
diff --git a/package-lock.json b/package-lock.json index 9c9b1aeb7..fd54e00b0 100644 --- a/package-lock.json +++ b/package-lock.json | |||
@@ -1,6 +1,6 @@ | |||
1 | { | 1 | { |
2 | "name": "ferdi", | 2 | "name": "ferdi", |
3 | "version": "5.4.1-beta.4", | 3 | "version": "5.4.3", |
4 | "lockfileVersion": 1, | 4 | "lockfileVersion": 1, |
5 | "requires": true, | 5 | "requires": true, |
6 | "dependencies": { | 6 | "dependencies": { |
diff --git a/package.json b/package.json index eef920a16..d51f02997 100644 --- a/package.json +++ b/package.json | |||
@@ -112,7 +112,7 @@ | |||
112 | "react-sortable-hoc": "1.10.1", | 112 | "react-sortable-hoc": "1.10.1", |
113 | "react-tooltip": "3.11.1", | 113 | "react-tooltip": "3.11.1", |
114 | "route-parser": "^0.0.5", | 114 | "route-parser": "^0.0.5", |
115 | "semver": "^5.4.1", | 115 | "semver": "5.7.1", |
116 | "smoothscroll-polyfill": "0.4.4", | 116 | "smoothscroll-polyfill": "0.4.4", |
117 | "sqlite3": "4.1.0", | 117 | "sqlite3": "4.1.0", |
118 | "tar": "^4.0.2", | 118 | "tar": "^4.0.2", |
diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js index 8b2bde5df..fc7a07dd8 100644 --- a/src/stores/RecipesStore.js +++ b/src/stores/RecipesStore.js | |||
@@ -1,9 +1,13 @@ | |||
1 | import { action, computed, observable } from 'mobx'; | 1 | import { action, computed, observable } from 'mobx'; |
2 | import fs from 'fs-extra'; | ||
3 | import path from 'path'; | ||
4 | import semver from 'semver'; | ||
2 | 5 | ||
3 | import Store from './lib/Store'; | 6 | import Store from './lib/Store'; |
4 | import CachedRequest from './lib/CachedRequest'; | 7 | import CachedRequest from './lib/CachedRequest'; |
5 | import Request from './lib/Request'; | 8 | import Request from './lib/Request'; |
6 | import { matchRoute } from '../helpers/routing-helpers'; | 9 | import { matchRoute } from '../helpers/routing-helpers'; |
10 | import { RECIPES_PATH } from '../config'; | ||
7 | 11 | ||
8 | const debug = require('debug')('Ferdi:RecipeStore'); | 12 | const debug = require('debug')('Ferdi:RecipeStore'); |
9 | 13 | ||
@@ -83,7 +87,30 @@ export default class RecipesStore extends Store { | |||
83 | 87 | ||
84 | if (Object.keys(recipes).length === 0) return; | 88 | if (Object.keys(recipes).length === 0) return; |
85 | 89 | ||
86 | const updates = await this.getRecipeUpdatesRequest.execute(recipes)._promise; | 90 | const remoteUpdates = await this.getRecipeUpdatesRequest.execute(recipes)._promise; |
91 | |||
92 | // Check for local updates | ||
93 | const allJsonFile = path.join(RECIPES_PATH, 'all.json'); | ||
94 | const allJson = await fs.readJSON(allJsonFile); | ||
95 | const localUpdates = []; | ||
96 | |||
97 | Object.keys(recipes).forEach((recipe) => { | ||
98 | const version = recipes[recipe]; | ||
99 | |||
100 | // Find recipe in local recipe repository | ||
101 | const localRecipe = allJson.find((r) => r.id === recipe); | ||
102 | |||
103 | if (localRecipe && semver.lt(version, localRecipe.version)) { | ||
104 | localUpdates.push(recipe); | ||
105 | } | ||
106 | }); | ||
107 | |||
108 | const updates = [ | ||
109 | ...remoteUpdates, | ||
110 | ...localUpdates, | ||
111 | ]; | ||
112 | debug('Got update information (local, remote):', localUpdates, remoteUpdates); | ||
113 | |||
87 | const length = updates.length - 1; | 114 | const length = updates.length - 1; |
88 | const syncUpdate = async (i) => { | 115 | const syncUpdate = async (i) => { |
89 | const update = updates[i]; | 116 | const update = updates[i]; |