From 6a9a42e50dfc9e7811e0b75da6b3ea456372d75e Mon Sep 17 00:00:00 2001 From: vantezzen Date: Tue, 3 Sep 2019 10:34:42 +0200 Subject: Add CONNECT_WITH_FRANZ option --- app/Controllers/Http/RecipeController.js | 12 ++++++++++-- app/Controllers/Http/UserController.js | 13 ++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/Controllers/Http/RecipeController.js b/app/Controllers/Http/RecipeController.js index ec0cde9..fd9ed83 100644 --- a/app/Controllers/Http/RecipeController.js +++ b/app/Controllers/Http/RecipeController.js @@ -140,7 +140,10 @@ class RecipeController { const needle = request.input('needle') // Get results - const remoteResults = JSON.parse(await (await fetch('https://api.franzinfra.com/v1/recipes/search?needle=' + encodeURIComponent(needle))).text()); + let remoteResults = []; + if (Env.get('CONNECT_WITH_FRANZ') == 'true') { + remoteResults = JSON.parse(await (await fetch('https://api.franzinfra.com/v1/recipes/search?needle=' + encodeURIComponent(needle))).text()); + } const localResultsArray = (await Recipe.query().where('name', 'LIKE', '%' + needle + '%').fetch()).toJSON(); const localResults = localResultsArray.map(recipe => ({ "id": recipe.recipeId, @@ -184,8 +187,13 @@ class RecipeController { // Check if recipe exists in recipes folder if (await Drive.exists(service + '.tar.gz')) { response.send(await Drive.get(service + '.tar.gz')) - } else { + } else if(Env.get('CONNECT_WITH_FRANZ') == 'true') { response.redirect('https://api.franzinfra.com/v1/recipes/download/' + service) + } else { + return response.status(400).send({ + "message": "Recipe not found", + "code": "recipe-not-found" + }) } } } diff --git a/app/Controllers/Http/UserController.js b/app/Controllers/Http/UserController.js index 7c6cece..2a75f6e 100644 --- a/app/Controllers/Http/UserController.js +++ b/app/Controllers/Http/UserController.js @@ -6,6 +6,7 @@ const Workspace = use('App/Models/Workspace'); const { validateAll } = use('Validator'); +const Env = use('Env') const atob = require('atob'); const btoa = require('btoa'); @@ -149,7 +150,7 @@ class UserController { emailValidated: true, features: {}, firstname: "Franz", - id: "2acd2aa0-0869-4a91-adab-f700ac256dbe", + id: "82c1cf9d-ab58-4da2-b55e-aaa41d2142d8", isPremium: true, isSubscriptionOwner: true, lastname: "Franz", @@ -188,6 +189,16 @@ class UserController { } = request.all() const hashedPassword = crypto.createHash('sha256').update(password).digest('base64'); + + if(Env.get('CONNECT_WITH_FRANZ') == 'false') { + await User.create({ + email: userInf.email, + password: hashedPassword, + username: userInf.firstname + }); + + return response.send('Your account has been created but due to this server\'s configuration, we could not import your Franz account data.\n\nIf you are the server owner, please set CONNECT_WITH_FRANZ to true to enable account imports.') + } const base = 'https://api.franzinfra.com/v1/'; const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Ferdi/5.3.0-beta.1 Chrome/69.0.3497.128 Electron/4.2.4 Safari/537.36'; -- cgit v1.2.3-54-g00ecf