diff options
-rw-r--r-- | .gitmodules | 3 | ||||
-rw-r--r-- | gulpfile.babel.js | 11 | ||||
m--------- | recipes | 0 | ||||
-rw-r--r-- | src/api/server/ServerApi.js | 29 |
4 files changed, 36 insertions, 7 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..5a8d15f8f --- /dev/null +++ b/.gitmodules | |||
@@ -0,0 +1,3 @@ | |||
1 | [submodule "recipes"] | ||
2 | path = recipes | ||
3 | url = https://github.com/getferdi/recipes | ||
diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 142eb7b02..fcdefd3d3 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js | |||
@@ -34,6 +34,10 @@ const paths = { | |||
34 | tmp: '.tmp', | 34 | tmp: '.tmp', |
35 | dictionaries: 'dictionaries', | 35 | dictionaries: 'dictionaries', |
36 | package: `out/${config.version}`, | 36 | package: `out/${config.version}`, |
37 | recipes: { | ||
38 | src: 'recipes/*.tar.gz', | ||
39 | dest: 'build/recipes/', | ||
40 | }, | ||
37 | html: { | 41 | html: { |
38 | src: 'src/**/*.html', | 42 | src: 'src/**/*.html', |
39 | dest: 'build/', | 43 | dest: 'build/', |
@@ -194,10 +198,15 @@ export function dictionaries(done) { | |||
194 | ); | 198 | ); |
195 | } | 199 | } |
196 | 200 | ||
201 | export function recipes() { | ||
202 | return gulp.src(paths.recipes.src, { since: gulp.lastRun(recipes) }) | ||
203 | .pipe(gulp.dest(paths.recipes.dest)); | ||
204 | } | ||
205 | |||
197 | const build = gulp.series( | 206 | const build = gulp.series( |
198 | clean, | 207 | clean, |
199 | gulp.parallel(mvSrc, mvPackageJson, mvLernaPackages), | 208 | gulp.parallel(mvSrc, mvPackageJson, mvLernaPackages), |
200 | gulp.parallel(html, scripts, styles), | 209 | gulp.parallel(html, scripts, styles, recipes), |
201 | dictionaries, | 210 | dictionaries, |
202 | ); | 211 | ); |
203 | export { build }; | 212 | export { build }; |
diff --git a/recipes b/recipes new file mode 160000 | |||
Subproject bd8c25be7961d167d315e76276627306b2379dc | |||
diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 3d973e586..663c2716f 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js | |||
@@ -13,6 +13,7 @@ import UserModel from '../../models/User'; | |||
13 | import OrderModel from '../../models/Order'; | 13 | import OrderModel from '../../models/Order'; |
14 | 14 | ||
15 | import { sleep } from '../../helpers/async-helpers'; | 15 | import { sleep } from '../../helpers/async-helpers'; |
16 | import { asarPath } from '../../helpers/asar-helpers'; | ||
16 | 17 | ||
17 | import { API } from '../../environment'; | 18 | import { API } from '../../environment'; |
18 | import apiBase from '../apiBase'; | 19 | import apiBase from '../apiBase'; |
@@ -369,14 +370,30 @@ export default class ServerApi { | |||
369 | try { | 370 | try { |
370 | const recipesDirectory = path.join(app.getPath('userData'), 'recipes'); | 371 | const recipesDirectory = path.join(app.getPath('userData'), 'recipes'); |
371 | const recipeTempDirectory = path.join(recipesDirectory, 'temp', recipeId); | 372 | const recipeTempDirectory = path.join(recipesDirectory, 'temp', recipeId); |
372 | const archivePath = path.join(recipeTempDirectory, 'recipe.tar.gz'); | 373 | const tempArchivePath = path.join(recipeTempDirectory, 'recipe.tar.gz'); |
373 | const packageUrl = `${apiBase()}/recipes/download/${recipeId}`; | 374 | |
375 | const internalRecipesDirectory = asarPath(path.join(__dirname, '../../', 'recipes')); | ||
376 | const internalRecipeFile = path.join(internalRecipesDirectory, `${recipeId}.tar.gz`); | ||
374 | 377 | ||
375 | fs.ensureDirSync(recipeTempDirectory); | 378 | fs.ensureDirSync(recipeTempDirectory); |
376 | const res = await fetch(packageUrl); | 379 | |
377 | debug('Recipe downloaded', recipeId); | 380 | let archivePath; |
378 | const buffer = await res.buffer(); | 381 | |
379 | fs.writeFileSync(archivePath, buffer); | 382 | if (await fs.exists(internalRecipeFile)) { |
383 | console.log('[ServerApi::getRecipePackage] Using internal recipe file'); | ||
384 | archivePath = internalRecipeFile; | ||
385 | } else { | ||
386 | console.log('[ServerApi::getRecipePackage] Downloading recipe from server'); | ||
387 | archivePath = tempArchivePath; | ||
388 | |||
389 | const packageUrl = `${apiBase()}/recipes/download/${recipeId}`; | ||
390 | |||
391 | const res = await fetch(packageUrl); | ||
392 | debug('Recipe downloaded', recipeId); | ||
393 | const buffer = await res.buffer(); | ||
394 | fs.writeFileSync(archivePath, buffer); | ||
395 | } | ||
396 | console.log(archivePath); | ||
380 | 397 | ||
381 | await sleep(10); | 398 | await sleep(10); |
382 | 399 | ||