Skip to content
Permalink
Browse files

Initial commit

  • Loading branch information
vantezzen committed Aug 22, 2019
0 parents commit b018adf240679ec59a7344e30be39400f1ecd8af
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
@@ -0,0 +1,19 @@
HOST=127.0.0.1
PORT=3333
NODE_ENV=development

APP_NAME=AdonisJs
APP_URL=http://${HOST}:${PORT}

CACHE_VIEWS=false

APP_KEY=

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=root
DB_PASSWORD=
DB_DATABASE=adonis

HASH_DRIVER=bcrypt
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
@@ -0,0 +1,11 @@
# Node modules
node_modules

# Adonis directory for storing tmp files
tmp

# Environment variables, never commit this file
.env

# The development sqlite file
database/development.sqlite
21 LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 vantezzen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,17 @@
# ferdi-server
Unofficial Franz server replacement for use with the Ferdi Client.

## Setup
1. Clone this repository
2. Install the [AdonisJS CLI](https://adonisjs.com/)
3. Run the database migrations with
```js
adonis migration:run
```
4. Start the server with
```js
adonis serve --dev
```

## License
ferdi-server is licensed under the MIT License
21 ace
@@ -0,0 +1,21 @@
'use strict'

/*
|--------------------------------------------------------------------------
| Ace Commands
|--------------------------------------------------------------------------
|
| The ace file is just a regular Javascript file but with no extension. You
| can call `node ace` followed by the command name and it just works.
|
| Also you can use `adonis` followed by the command name, since the adonis
| global proxies all the ace commands.
|
*/

const { Ignitor } = require('@adonisjs/ignitor')

new Ignitor(require('@adonisjs/fold'))
.appRoot(__dirname)
.fireAce()
.catch(console.error)
@@ -0,0 +1,94 @@
'use strict'

const User = use('App/Models/User');
const Service = use('App/Models/Service');

class ServiceController {
// Create a new service for user
async create({
request,
response,
auth
}) {
try {
await auth.getUser()
} catch (error) {
return response.send('Missing or invalid api token')
}

const data = request.all();

const service = await Service.create({
userId: auth.user.id,
name: data.name,
recipeId: data.recipeId,
settings: JSON.stringify(data)
});

return response.send({
"data": {
userId: auth.user.id,
id: service.id,
"isEnabled": true,
"isNotificationEnabled": true,
"isBadgeEnabled": true,
"isMuted": false,
"isDarkModeEnabled": "",
"spellcheckerLanguage": "",
"order": 1,
"customRecipe": false,
"hasCustomIcon": false,
"workspaces": [],
"iconUrl": null,
...data,
},
"status": ["created"]
})
}

// List all services a user has created
async list({
request,
response,
auth
}) {
try {
await auth.getUser()
} catch (error) {
return response.send('Missing or invalid api token')
}


const services = (await auth.user.services().fetch()).rows;
// Convert to array with all data Franz wants
const servicesArray = services.map(service => ({
"customRecipe": false,
"hasCustomIcon": false,
"isBadgeEnabled": true,
"isDarkModeEnabled": "",
"isEnabled": true,
"isMuted": false,
"isNotificationEnabled": true,
"order": 1,
"spellcheckerLanguage": "",
"workspaces": [],
"iconUrl": null,
...JSON.parse(service.settings),
"id": service.id,
"name": service.name,
"recipeId": service.recipeId,
"userId": auth.user.id,
}))

return response.send(servicesArray)
}

// Download a recipe (currently simply redirects to Franz's API)
download({ request, response, params }) {
const service = params.recipe;

response.redirect('https://api.franzinfra.com/v1/recipes/download/' + service)
}
}

module.exports = ServiceController

0 comments on commit b018adf

Please sign in to comment.
You can’t perform that action at this time.