aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.env.example3
-rw-r--r--README.md5
-rw-r--r--app/Controllers/Http/RecipeController.js12
-rw-r--r--app/Controllers/Http/UserController.js13
4 files changed, 28 insertions, 5 deletions
diff --git a/.env.example b/.env.example
index 91e92a1..c175cd1 100644
--- a/.env.example
+++ b/.env.example
@@ -18,4 +18,5 @@ DB_DATABASE=adonis
18 18
19HASH_DRIVER=bcrypt 19HASH_DRIVER=bcrypt
20 20
21IS_CREATION_ENABLED=true \ No newline at end of file 21IS_CREATION_ENABLED=true
22CONNECT_WITH_FRANZ=true \ No newline at end of file
diff --git a/README.md b/README.md
index 74e1e22..b686fad 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,10 @@ Unofficial Franz server replacement for use with the Ferdi Client.
22 22
23## Configuration 23## Configuration
24franz-server's configuration is saved inside the `.env` file. Besides AdonisJS's settings, ferdi-server has the following custom settings: 24franz-server's configuration is saved inside the `.env` file. Besides AdonisJS's settings, ferdi-server has the following custom settings:
25- `IS_CREATION_ENABLED` (`true` or `false`): Whether to enable the [creation of custom recipes](#creating-and-using-custom-recipes) 25- `IS_CREATION_ENABLED` (`true` or `false`, default: `true`): Whether to enable the [creation of custom recipes](#creating-and-using-custom-recipes)
26- `CONNECT_WITH_FRANZ` (`true` or `false`, default: `true`): Whether to enable connections to the Franz server. By enabling this option, ferdi-server can:
27 - Show the full Franz recipe library instead of only custom recipes
28 - Import Franz accounts
26 29
27## Importing your Franz account 30## Importing your Franz account
28ferdi-server allows you to import your full Franz account, including all its settings. 31ferdi-server allows you to import your full Franz account, including all its settings.
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 {
140 const needle = request.input('needle') 140 const needle = request.input('needle')
141 141
142 // Get results 142 // Get results
143 const remoteResults = JSON.parse(await (await fetch('https://api.franzinfra.com/v1/recipes/search?needle=' + encodeURIComponent(needle))).text()); 143 let remoteResults = [];
144 if (Env.get('CONNECT_WITH_FRANZ') == 'true') {
145 remoteResults = JSON.parse(await (await fetch('https://api.franzinfra.com/v1/recipes/search?needle=' + encodeURIComponent(needle))).text());
146 }
144 const localResultsArray = (await Recipe.query().where('name', 'LIKE', '%' + needle + '%').fetch()).toJSON(); 147 const localResultsArray = (await Recipe.query().where('name', 'LIKE', '%' + needle + '%').fetch()).toJSON();
145 const localResults = localResultsArray.map(recipe => ({ 148 const localResults = localResultsArray.map(recipe => ({
146 "id": recipe.recipeId, 149 "id": recipe.recipeId,
@@ -184,8 +187,13 @@ class RecipeController {
184 // Check if recipe exists in recipes folder 187 // Check if recipe exists in recipes folder
185 if (await Drive.exists(service + '.tar.gz')) { 188 if (await Drive.exists(service + '.tar.gz')) {
186 response.send(await Drive.get(service + '.tar.gz')) 189 response.send(await Drive.get(service + '.tar.gz'))
187 } else { 190 } else if(Env.get('CONNECT_WITH_FRANZ') == 'true') {
188 response.redirect('https://api.franzinfra.com/v1/recipes/download/' + service) 191 response.redirect('https://api.franzinfra.com/v1/recipes/download/' + service)
192 } else {
193 return response.status(400).send({
194 "message": "Recipe not found",
195 "code": "recipe-not-found"
196 })
189 } 197 }
190 } 198 }
191} 199}
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');
6const { 6const {
7 validateAll 7 validateAll
8} = use('Validator'); 8} = use('Validator');
9const Env = use('Env')
9 10
10const atob = require('atob'); 11const atob = require('atob');
11const btoa = require('btoa'); 12const btoa = require('btoa');
@@ -149,7 +150,7 @@ class UserController {
149 emailValidated: true, 150 emailValidated: true,
150 features: {}, 151 features: {},
151 firstname: "Franz", 152 firstname: "Franz",
152 id: "2acd2aa0-0869-4a91-adab-f700ac256dbe", 153 id: "82c1cf9d-ab58-4da2-b55e-aaa41d2142d8",
153 isPremium: true, 154 isPremium: true,
154 isSubscriptionOwner: true, 155 isSubscriptionOwner: true,
155 lastname: "Franz", 156 lastname: "Franz",
@@ -188,6 +189,16 @@ class UserController {
188 } = request.all() 189 } = request.all()
189 190
190 const hashedPassword = crypto.createHash('sha256').update(password).digest('base64'); 191 const hashedPassword = crypto.createHash('sha256').update(password).digest('base64');
192
193 if(Env.get('CONNECT_WITH_FRANZ') == 'false') {
194 await User.create({
195 email: userInf.email,
196 password: hashedPassword,
197 username: userInf.firstname
198 });
199
200 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.')
201 }
191 202
192 const base = 'https://api.franzinfra.com/v1/'; 203 const base = 'https://api.franzinfra.com/v1/';
193 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'; 204 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';