aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLibravatar vantezzen <properly@protonmail.com>2019-09-03 10:34:42 +0200
committerLibravatar vantezzen <properly@protonmail.com>2019-09-03 10:34:42 +0200
commit6a9a42e50dfc9e7811e0b75da6b3ea456372d75e (patch)
treefdf4df53ba7484e709b144ae015213e4e0a180e6 /app
parentAdd legal documents to account import page (diff)
downloadferdium-server-6a9a42e50dfc9e7811e0b75da6b3ea456372d75e.tar.gz
ferdium-server-6a9a42e50dfc9e7811e0b75da6b3ea456372d75e.tar.zst
ferdium-server-6a9a42e50dfc9e7811e0b75da6b3ea456372d75e.zip
Add CONNECT_WITH_FRANZ option
Diffstat (limited to 'app')
-rw-r--r--app/Controllers/Http/RecipeController.js12
-rw-r--r--app/Controllers/Http/UserController.js13
2 files changed, 22 insertions, 3 deletions
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';