aboutsummaryrefslogtreecommitdiffstats
path: root/app/Controllers/Http
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controllers/Http')
-rw-r--r--app/Controllers/Http/Api/Static/AnnouncementsController.ts9
-rw-r--r--app/Controllers/Http/Api/Static/EmptyController.ts4
-rw-r--r--app/Controllers/Http/Api/Static/FeaturesController.ts4
-rw-r--r--app/Controllers/Http/Dashboard/AccountController.ts14
-rw-r--r--app/Controllers/Http/Dashboard/DataController.ts4
-rw-r--r--app/Controllers/Http/Dashboard/DeleteController.ts6
-rw-r--r--app/Controllers/Http/Dashboard/ExportController.ts4
-rw-r--r--app/Controllers/Http/Dashboard/ForgotPasswordController.ts10
-rw-r--r--app/Controllers/Http/Dashboard/LogOutController.ts4
-rw-r--r--app/Controllers/Http/Dashboard/LoginController.ts17
-rw-r--r--app/Controllers/Http/Dashboard/ResetPasswordController.ts10
-rw-r--r--app/Controllers/Http/Dashboard/TransferController.ts18
-rw-r--r--app/Controllers/Http/DashboardController.ts2
-rw-r--r--app/Controllers/Http/HomeController.ts2
-rw-r--r--app/Controllers/Http/RecipeController.ts38
-rw-r--r--app/Controllers/Http/ServiceController.ts51
-rw-r--r--app/Controllers/Http/StaticsController.ts2
-rw-r--r--app/Controllers/Http/UserController.ts33
-rw-r--r--app/Controllers/Http/WorkspaceController.ts19
19 files changed, 114 insertions, 137 deletions
diff --git a/app/Controllers/Http/Api/Static/AnnouncementsController.ts b/app/Controllers/Http/Api/Static/AnnouncementsController.ts
index c20707b..85aed4d 100644
--- a/app/Controllers/Http/Api/Static/AnnouncementsController.ts
+++ b/app/Controllers/Http/Api/Static/AnnouncementsController.ts
@@ -1,12 +1,13 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2import Application from '@ioc:Adonis/Core/Application'; 2import app from '@adonisjs/core/services/app';
3import path from 'node:path'; 3import path from 'node:path';
4import fs from 'fs-extra'; 4import fs from 'fs-extra';
5 5
6export default class AnnouncementsController { 6export default class AnnouncementsController {
7 public async show({ response, params }: HttpContextContract) { 7 public async show({ response, params }: HttpContext) {
8 const announcement = path.join( 8 const announcement = path.join(
9 Application.resourcesPath(), 9 app.appRoot.host,
10 'resources',
10 'announcements', 11 'announcements',
11 `${params.version}.json`, 12 `${params.version}.json`,
12 ); 13 );
diff --git a/app/Controllers/Http/Api/Static/EmptyController.ts b/app/Controllers/Http/Api/Static/EmptyController.ts
index a07790e..80d70b7 100644
--- a/app/Controllers/Http/Api/Static/EmptyController.ts
+++ b/app/Controllers/Http/Api/Static/EmptyController.ts
@@ -1,7 +1,7 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2 2
3export default class EmptyController { 3export default class EmptyController {
4 public async show({ response }: HttpContextContract) { 4 public async show({ response }: HttpContext) {
5 return response.send([]); 5 return response.send([]);
6 } 6 }
7} 7}
diff --git a/app/Controllers/Http/Api/Static/FeaturesController.ts b/app/Controllers/Http/Api/Static/FeaturesController.ts
index d471b11..ce964de 100644
--- a/app/Controllers/Http/Api/Static/FeaturesController.ts
+++ b/app/Controllers/Http/Api/Static/FeaturesController.ts
@@ -1,7 +1,7 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2 2
3export default class FeaturesController { 3export default class FeaturesController {
4 public async show({ response }: HttpContextContract) { 4 public async show({ response }: HttpContext) {
5 return response.send({ 5 return response.send({
6 isServiceProxyEnabled: true, 6 isServiceProxyEnabled: true,
7 isWorkspaceEnabled: true, 7 isWorkspaceEnabled: true,
diff --git a/app/Controllers/Http/Dashboard/AccountController.ts b/app/Controllers/Http/Dashboard/AccountController.ts
index 3c4e919..a748c75 100644
--- a/app/Controllers/Http/Dashboard/AccountController.ts
+++ b/app/Controllers/Http/Dashboard/AccountController.ts
@@ -1,12 +1,12 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2import { schema, rules, validator } from '@ioc:Adonis/Core/Validator'; 2import { schema, rules, validator } from '@adonisjs/validator';
3import crypto from 'node:crypto'; 3import crypto from 'node:crypto';
4 4
5export default class AccountController { 5export default class AccountController {
6 /** 6 /**
7 * Shows the user account page 7 * Shows the user account page
8 */ 8 */
9 public async show({ auth, view }: HttpContextContract) { 9 public async show({ auth, view }: HttpContext) {
10 return view.render('dashboard/account', { 10 return view.render('dashboard/account', {
11 username: auth.user?.username, 11 username: auth.user?.username,
12 email: auth.user?.email, 12 email: auth.user?.email,
@@ -17,13 +17,7 @@ export default class AccountController {
17 /** 17 /**
18 * Stores user account data 18 * Stores user account data
19 */ 19 */
20 public async store({ 20 public async store({ auth, request, response, session, view }: HttpContext) {
21 auth,
22 request,
23 response,
24 session,
25 view,
26 }: HttpContextContract) {
27 try { 21 try {
28 await validator.validate({ 22 await validator.validate({
29 schema: schema.create({ 23 schema: schema.create({
diff --git a/app/Controllers/Http/Dashboard/DataController.ts b/app/Controllers/Http/Dashboard/DataController.ts
index f77702f..5f22979 100644
--- a/app/Controllers/Http/Dashboard/DataController.ts
+++ b/app/Controllers/Http/Dashboard/DataController.ts
@@ -1,10 +1,10 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2 2
3export default class DataController { 3export default class DataController {
4 /** 4 /**
5 * Display the data page 5 * Display the data page
6 */ 6 */
7 public async show({ view, auth }: HttpContextContract) { 7 public async show({ view, auth }: HttpContext) {
8 const { user } = auth; 8 const { user } = auth;
9 9
10 const services = await user?.related('services').query(); 10 const services = await user?.related('services').query();
diff --git a/app/Controllers/Http/Dashboard/DeleteController.ts b/app/Controllers/Http/Dashboard/DeleteController.ts
index ef8188c..76e41ca 100644
--- a/app/Controllers/Http/Dashboard/DeleteController.ts
+++ b/app/Controllers/Http/Dashboard/DeleteController.ts
@@ -1,17 +1,17 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2 2
3export default class DeleteController { 3export default class DeleteController {
4 /** 4 /**
5 * Display the delete page 5 * Display the delete page
6 */ 6 */
7 public async show({ view }: HttpContextContract) { 7 public async show({ view }: HttpContext) {
8 return view.render('dashboard/delete'); 8 return view.render('dashboard/delete');
9 } 9 }
10 10
11 /** 11 /**
12 * Delete user and session 12 * Delete user and session
13 */ 13 */
14 public async delete({ auth, response }: HttpContextContract) { 14 public async delete({ auth, response }: HttpContext) {
15 auth.user?.delete(); 15 auth.user?.delete();
16 auth.use('web').logout(); 16 auth.use('web').logout();
17 17
diff --git a/app/Controllers/Http/Dashboard/ExportController.ts b/app/Controllers/Http/Dashboard/ExportController.ts
index 7155eab..6b20a82 100644
--- a/app/Controllers/Http/Dashboard/ExportController.ts
+++ b/app/Controllers/Http/Dashboard/ExportController.ts
@@ -1,4 +1,4 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2 2
3// eslint-disable-next-line @typescript-eslint/no-explicit-any 3// eslint-disable-next-line @typescript-eslint/no-explicit-any
4function deepParseToJSON(obj: any): Record<string, unknown> { 4function deepParseToJSON(obj: any): Record<string, unknown> {
@@ -35,7 +35,7 @@ export default class ExportController {
35 /** 35 /**
36 * Display the export page 36 * Display the export page
37 */ 37 */
38 public async show({ auth, response }: HttpContextContract) { 38 public async show({ auth, response }: HttpContext) {
39 const user = auth.user!; 39 const user = auth.user!;
40 const services = await user.related('services').query(); 40 const services = await user.related('services').query();
41 const workspaces = await user.related('workspaces').query(); 41 const workspaces = await user.related('workspaces').query();
diff --git a/app/Controllers/Http/Dashboard/ForgotPasswordController.ts b/app/Controllers/Http/Dashboard/ForgotPasswordController.ts
index da05bbd..1878c4d 100644
--- a/app/Controllers/Http/Dashboard/ForgotPasswordController.ts
+++ b/app/Controllers/Http/Dashboard/ForgotPasswordController.ts
@@ -1,19 +1,19 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2import { schema, rules, validator } from '@ioc:Adonis/Core/Validator'; 2import { schema, rules, validator } from '@adonisjs/validator';
3import User from 'App/Models/User'; 3import User from '#app/Models/User';
4 4
5export default class ForgotPasswordController { 5export default class ForgotPasswordController {
6 /** 6 /**
7 * Display the forgot password form 7 * Display the forgot password form
8 */ 8 */
9 public async show({ view }: HttpContextContract) { 9 public async show({ view }: HttpContext) {
10 return view.render('dashboard/forgotPassword'); 10 return view.render('dashboard/forgotPassword');
11 } 11 }
12 12
13 /** 13 /**
14 * Send forget password email to user 14 * Send forget password email to user
15 */ 15 */
16 public async forgotPassword({ view, request }: HttpContextContract) { 16 public async forgotPassword({ view, request }: HttpContext) {
17 try { 17 try {
18 await validator.validate({ 18 await validator.validate({
19 schema: schema.create({ 19 schema: schema.create({
diff --git a/app/Controllers/Http/Dashboard/LogOutController.ts b/app/Controllers/Http/Dashboard/LogOutController.ts
index 41cbd31..f085d00 100644
--- a/app/Controllers/Http/Dashboard/LogOutController.ts
+++ b/app/Controllers/Http/Dashboard/LogOutController.ts
@@ -1,10 +1,10 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2 2
3export default class LogOutController { 3export default class LogOutController {
4 /** 4 /**
5 * Login a user 5 * Login a user
6 */ 6 */
7 public async logout({ auth, response }: HttpContextContract) { 7 public async logout({ auth, response }: HttpContext) {
8 auth.logout(); 8 auth.logout();
9 9
10 return response.redirect('/user/login'); 10 return response.redirect('/user/login');
diff --git a/app/Controllers/Http/Dashboard/LoginController.ts b/app/Controllers/Http/Dashboard/LoginController.ts
index ffb9eeb..3367a2f 100644
--- a/app/Controllers/Http/Dashboard/LoginController.ts
+++ b/app/Controllers/Http/Dashboard/LoginController.ts
@@ -1,26 +1,21 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2import { schema, rules, validator } from '@ioc:Adonis/Core/Validator'; 2import { schema, rules, validator } from '@adonisjs/validator';
3import User from 'App/Models/User'; 3import User from '#app/Models/User';
4import crypto from 'node:crypto'; 4import crypto from 'node:crypto';
5import { handleVerifyAndReHash } from '../../../../helpers/PasswordHash'; 5import { handleVerifyAndReHash } from '../../../../helpers/PasswordHash.js';
6 6
7export default class LoginController { 7export default class LoginController {
8 /** 8 /**
9 * Display the login form 9 * Display the login form
10 */ 10 */
11 public async show({ view }: HttpContextContract) { 11 public async show({ view }: HttpContext) {
12 return view.render('dashboard/login'); 12 return view.render('dashboard/login');
13 } 13 }
14 14
15 /** 15 /**
16 * Login a user 16 * Login a user
17 */ 17 */
18 public async login({ 18 public async login({ request, response, auth, session }: HttpContext) {
19 request,
20 response,
21 auth,
22 session,
23 }: HttpContextContract) {
24 try { 19 try {
25 await validator.validate({ 20 await validator.validate({
26 schema: schema.create({ 21 schema: schema.create({
diff --git a/app/Controllers/Http/Dashboard/ResetPasswordController.ts b/app/Controllers/Http/Dashboard/ResetPasswordController.ts
index 0b9053f..261d773 100644
--- a/app/Controllers/Http/Dashboard/ResetPasswordController.ts
+++ b/app/Controllers/Http/Dashboard/ResetPasswordController.ts
@@ -1,6 +1,6 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2import { schema, rules, validator } from '@ioc:Adonis/Core/Validator'; 2import { schema, rules, validator } from '@adonisjs/validator';
3import Token from 'App/Models/Token'; 3import Token from '#app/Models/Token';
4import moment from 'moment'; 4import moment from 'moment';
5import crypto from 'node:crypto'; 5import crypto from 'node:crypto';
6 6
@@ -8,7 +8,7 @@ export default class ResetPasswordController {
8 /** 8 /**
9 * Display the reset password form 9 * Display the reset password form
10 */ 10 */
11 public async show({ view, request }: HttpContextContract) { 11 public async show({ view, request }: HttpContext) {
12 const { token } = request.qs(); 12 const { token } = request.qs();
13 13
14 if (token) { 14 if (token) {
@@ -29,7 +29,7 @@ export default class ResetPasswordController {
29 request, 29 request,
30 session, 30 session,
31 view, 31 view,
32 }: HttpContextContract) { 32 }: HttpContext) {
33 try { 33 try {
34 await validator.validate({ 34 await validator.validate({
35 schema: schema.create({ 35 schema: schema.create({
diff --git a/app/Controllers/Http/Dashboard/TransferController.ts b/app/Controllers/Http/Dashboard/TransferController.ts
index b113e50..ab50bcf 100644
--- a/app/Controllers/Http/Dashboard/TransferController.ts
+++ b/app/Controllers/Http/Dashboard/TransferController.ts
@@ -1,7 +1,7 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2import { schema, validator } from '@ioc:Adonis/Core/Validator'; 2import { schema, validator } from '@adonisjs/validator';
3import Service from 'App/Models/Service'; 3import Service from '#app/Models/Service';
4import Workspace from 'App/Models/Workspace'; 4import Workspace from '#app/Models/Workspace';
5import { v4 as uuidv4 } from 'uuid'; 5import { v4 as uuidv4 } from 'uuid';
6 6
7const importSchema = schema.create({ 7const importSchema = schema.create({
@@ -16,17 +16,11 @@ export default class TransferController {
16 /** 16 /**
17 * Display the transfer page 17 * Display the transfer page
18 */ 18 */
19 public async show({ view }: HttpContextContract) { 19 public async show({ view }: HttpContext) {
20 return view.render('dashboard/transfer'); 20 return view.render('dashboard/transfer');
21 } 21 }
22 22
23 public async import({ 23 public async import({ auth, request, response, session, view }: HttpContext) {
24 auth,
25 request,
26 response,
27 session,
28 view,
29 }: HttpContextContract) {
30 let file; 24 let file;
31 try { 25 try {
32 file = await validator.validate({ 26 file = await validator.validate({
diff --git a/app/Controllers/Http/DashboardController.ts b/app/Controllers/Http/DashboardController.ts
index a6f5b44..2a9fb13 100644
--- a/app/Controllers/Http/DashboardController.ts
+++ b/app/Controllers/Http/DashboardController.ts
@@ -1,4 +1,4 @@
1// import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' 1// import type { HttpContext } from '@adonisjs/core/http';
2 2
3export default class DashboardController {} 3export default class DashboardController {}
4 4
diff --git a/app/Controllers/Http/HomeController.ts b/app/Controllers/Http/HomeController.ts
index dbe9fbd..bae3bc2 100644
--- a/app/Controllers/Http/HomeController.ts
+++ b/app/Controllers/Http/HomeController.ts
@@ -1,4 +1,4 @@
1// import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' 1// import type { HttpContext } from '@adonisjs/core/http'
2 2
3export default class HomeController { 3export default class HomeController {
4 public async index() { 4 public async index() {
diff --git a/app/Controllers/Http/RecipeController.ts b/app/Controllers/Http/RecipeController.ts
index 5186a11..fd3c57e 100644
--- a/app/Controllers/Http/RecipeController.ts
+++ b/app/Controllers/Http/RecipeController.ts
@@ -1,10 +1,10 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2import fs from 'fs-extra'; 2import fs from 'fs-extra';
3import Application from '@ioc:Adonis/Core/Application'; 3import app from '@adonisjs/core/services/app';
4import path from 'node:path'; 4import path from 'node:path';
5import Recipe from 'App/Models/Recipe'; 5import Recipe from '#app/Models/Recipe';
6import { isCreationEnabled } from 'Config/app'; 6import { isCreationEnabled } from '#config/app';
7import { validator, schema, rules } from '@ioc:Adonis/Core/Validator'; 7import { validator, schema, rules } from '@adonisjs/validator';
8import targz from 'targz'; 8import targz from 'targz';
9import semver from 'semver'; 9import semver from 'semver';
10import Drive from '@ioc:Adonis/Core/Drive'; 10import Drive from '@ioc:Adonis/Core/Drive';
@@ -49,9 +49,9 @@ const compress = (src: string, dest: string) =>
49 49
50export default class RecipesController { 50export default class RecipesController {
51 // List official and custom recipes 51 // List official and custom recipes
52 public async list({ response }: HttpContextContract) { 52 public async list({ response }: HttpContext) {
53 const officialRecipes = fs.readJsonSync( 53 const officialRecipes = fs.readJsonSync(
54 path.join(Application.appRoot, 'recipes', 'all.json'), 54 path.join(app.appRoot.host, 'recipes', 'all.json'),
55 ); 55 );
56 const customRecipesArray = await Recipe.all(); 56 const customRecipesArray = await Recipe.all();
57 const customRecipes = customRecipesArray.map(recipe => ({ 57 const customRecipes = customRecipesArray.map(recipe => ({
@@ -69,11 +69,11 @@ export default class RecipesController {
69 69
70 // TODO: Test this endpoint 70 // TODO: Test this endpoint
71 // Create a new recipe using the new.html page 71 // Create a new recipe using the new.html page
72 public async create({ request, response }: HttpContextContract) { 72 public async create({ request, response }: HttpContext) {
73 // Check if recipe creation is enabled 73 // Check if recipe creation is enabled
74 if (isCreationEnabled === 'false') { 74 if (isCreationEnabled === 'false') {
75 return response.send( 75 return response.send(
76 'This server doesn\'t allow the creation of new recipes.', 76 "This server doesn't allow the creation of new recipes.",
77 ); 77 );
78 } 78 }
79 79
@@ -101,19 +101,19 @@ export default class RecipesController {
101 } 101 }
102 102
103 // Clear temporary recipe folder 103 // Clear temporary recipe folder
104 await fs.emptyDir(Application.tmpPath('recipe')); 104 await fs.emptyDir(app.tmpPath('recipe'));
105 105
106 // Move uploaded files to temporary path 106 // Move uploaded files to temporary path
107 const files = request.file('files'); 107 const files = request.file('files');
108 if (!files) { 108 if (!files) {
109 return response.abort('Error processsing files.'); 109 return response.abort('Error processsing files.');
110 } 110 }
111 await files.move(Application.tmpPath('recipe')); 111 await files.move(app.tmpPath('recipe'));
112 112
113 // Compress files to .tar.gz file 113 // Compress files to .tar.gz file
114 const source = Application.tmpPath('recipe'); 114 const source = app.tmpPath('recipe');
115 const destination = path.join( 115 const destination = path.join(
116 Application.appRoot, 116 app.appRoot.host,
117 `/recipes/archives/${data.id}.tar.gz`, 117 `/recipes/archives/${data.id}.tar.gz`,
118 ); 118 );
119 119
@@ -138,7 +138,7 @@ export default class RecipesController {
138 } 138 }
139 139
140 // Search official and custom recipes 140 // Search official and custom recipes
141 public async search({ request, response }: HttpContextContract) { 141 public async search({ request, response }: HttpContext) {
142 // Validate user input 142 // Validate user input
143 let data; 143 let data;
144 try { 144 try {
@@ -183,21 +183,21 @@ export default class RecipesController {
183 return response.send(results); 183 return response.send(results);
184 } 184 }
185 185
186 public popularRecipes({ response }: HttpContextContract) { 186 public popularRecipes({ response }: HttpContext) {
187 return response.send( 187 return response.send(
188 fs 188 fs
189 .readJsonSync(path.join(Application.appRoot, 'recipes', 'all.json')) 189 .readJsonSync(path.join(app.appRoot.host, 'recipes', 'all.json'))
190 // eslint-disable-next-line @typescript-eslint/no-explicit-any 190 // eslint-disable-next-line @typescript-eslint/no-explicit-any
191 .filter((recipe: any) => recipe.featured), 191 .filter((recipe: any) => recipe.featured),
192 ); 192 );
193 } 193 }
194 194
195 // TODO: test this endpoint 195 // TODO: test this endpoint
196 public update({ request, response }: HttpContextContract) { 196 public update({ request, response }: HttpContext) {
197 const updates = []; 197 const updates = [];
198 const recipes = request.all(); 198 const recipes = request.all();
199 const allJson = fs.readJsonSync( 199 const allJson = fs.readJsonSync(
200 path.join(Application.appRoot, 'recipes', 'all.json'), 200 path.join(app.appRoot.host, 'recipes', 'all.json'),
201 ); 201 );
202 202
203 for (const recipe of Object.keys(recipes)) { 203 for (const recipe of Object.keys(recipes)) {
@@ -216,7 +216,7 @@ export default class RecipesController {
216 216
217 // TODO: test this endpoint 217 // TODO: test this endpoint
218 // Download a recipe 218 // Download a recipe
219 public async download({ response, params }: HttpContextContract) { 219 public async download({ response, params }: HttpContext) {
220 // Validate user input 220 // Validate user input
221 let data; 221 let data;
222 try { 222 try {
diff --git a/app/Controllers/Http/ServiceController.ts b/app/Controllers/Http/ServiceController.ts
index 76e72e4..df5f623 100644
--- a/app/Controllers/Http/ServiceController.ts
+++ b/app/Controllers/Http/ServiceController.ts
@@ -1,11 +1,11 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2import { schema } from '@ioc:Adonis/Core/Validator'; 2import { schema } from '@adonisjs/validator';
3import Service from 'App/Models/Service'; 3import Service from '#app/Models/Service';
4import { url } from 'Config/app'; 4import { url } from '#config/app';
5import { v4 as uuid } from 'uuid'; 5import { v4 as uuid } from 'uuid';
6import * as fs from 'fs-extra'; 6import * as fs from 'fs-extra';
7import path from 'node:path'; 7import path from 'node:path';
8import Application from '@ioc:Adonis/Core/Application'; 8import app from '@adonisjs/core/services/app';
9import sanitize from 'sanitize-filename'; 9import sanitize from 'sanitize-filename';
10 10
11const createSchema = schema.create({ 11const createSchema = schema.create({
@@ -15,7 +15,7 @@ const createSchema = schema.create({
15 15
16export default class ServiceController { 16export default class ServiceController {
17 // Create a new service for user 17 // Create a new service for user
18 public async create({ request, response, auth }: HttpContextContract) { 18 public async create({ request, response, auth }: HttpContext) {
19 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'. 19 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'.
20 const user = auth.user ?? request.user; 20 const user = auth.user ?? request.user;
21 21
@@ -76,7 +76,7 @@ export default class ServiceController {
76 } 76 }
77 77
78 // List all services a user has created 78 // List all services a user has created
79 public async list({ request, response, auth }: HttpContextContract) { 79 public async list({ request, response, auth }: HttpContext) {
80 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'. 80 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'.
81 const user = auth.user ?? request.user; 81 const user = auth.user ?? request.user;
82 82
@@ -110,7 +110,7 @@ export default class ServiceController {
110 iconUrl: settings.iconId 110 iconUrl: settings.iconId
111 ? `${url}/v1/icon/${settings.iconId}` 111 ? `${url}/v1/icon/${settings.iconId}`
112 : // eslint-disable-next-line unicorn/no-null 112 : // eslint-disable-next-line unicorn/no-null
113 null, 113 null,
114 id: service.serviceId, 114 id: service.serviceId,
115 name: service.name, 115 name: service.name,
116 recipeId: service.recipeId, 116 recipeId: service.recipeId,
@@ -121,12 +121,7 @@ export default class ServiceController {
121 return response.send(servicesArray); 121 return response.send(servicesArray);
122 } 122 }
123 123
124 public async delete({ 124 public async delete({ request, params, auth, response }: HttpContext) {
125 request,
126 params,
127 auth,
128 response,
129 }: HttpContextContract) {
130 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'. 125 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'.
131 const user = auth.user ?? request.user; 126 const user = auth.user ?? request.user;
132 127
@@ -147,7 +142,7 @@ export default class ServiceController {
147 } 142 }
148 143
149 // TODO: Test if icon upload works 144 // TODO: Test if icon upload works
150 public async edit({ request, response, auth, params }: HttpContextContract) { 145 public async edit({ request, response, auth, params }: HttpContext) {
151 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'. 146 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'.
152 const user = auth.user ?? request.user; 147 const user = auth.user ?? request.user;
153 148
@@ -182,11 +177,11 @@ export default class ServiceController {
182 iconId = uuid() + uuid(); 177 iconId = uuid() + uuid();
183 } while ( 178 } while (
184 // eslint-disable-next-line no-await-in-loop 179 // eslint-disable-next-line no-await-in-loop
185 await fs.exists(path.join(Application.tmpPath('uploads'), iconId)) 180 await fs.exists(path.join(app.tmpPath('uploads'), iconId))
186 ); 181 );
187 iconId = `${iconId}.${icon.extname}`; 182 iconId = `${iconId}.${icon.extname}`;
188 183
189 await icon.move(Application.tmpPath('uploads'), { 184 await icon.move(app.tmpPath('uploads'), {
190 name: iconId, 185 name: iconId,
191 overwrite: true, 186 overwrite: true,
192 }); 187 });
@@ -235,11 +230,11 @@ export default class ServiceController {
235 }; 230 };
236 231
237 if (settings.customIcon === 'delete') { 232 if (settings.customIcon === 'delete') {
238 fs.remove( 233 fs.remove(path.join(app.tmpPath('uploads'), settings.iconId)).catch(
239 path.join(Application.tmpPath('uploads'), settings.iconId), 234 error => {
240 ).catch(error => { 235 console.error(error);
241 console.error(error); 236 },
242 }); 237 );
243 238
244 settings.iconId = undefined; 239 settings.iconId = undefined;
245 settings.customIconVersion = undefined; 240 settings.customIconVersion = undefined;
@@ -274,7 +269,7 @@ export default class ServiceController {
274 } 269 }
275 270
276 // TODO: Test if this works 271 // TODO: Test if this works
277 public async reorder({ request, response, auth }: HttpContextContract) { 272 public async reorder({ request, response, auth }: HttpContext) {
278 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'. 273 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'.
279 const user = auth.user ?? request.user; 274 const user = auth.user ?? request.user;
280 275
@@ -333,7 +328,7 @@ export default class ServiceController {
333 iconUrl: settings.iconId 328 iconUrl: settings.iconId
334 ? `${url}/v1/icon/${settings.iconId}` 329 ? `${url}/v1/icon/${settings.iconId}`
335 : // eslint-disable-next-line unicorn/no-null 330 : // eslint-disable-next-line unicorn/no-null
336 null, 331 null,
337 id: service.serviceId, 332 id: service.serviceId,
338 name: service.name, 333 name: service.name,
339 recipeId: service.recipeId, 334 recipeId: service.recipeId,
@@ -345,24 +340,24 @@ export default class ServiceController {
345 } 340 }
346 341
347 // TODO: Test if this works 342 // TODO: Test if this works
348 public async icon({ params, response }: HttpContextContract) { 343 public async icon({ params, response }: HttpContext) {
349 let { id } = params; 344 let { id } = params;
350 345
351 id = sanitize(id); 346 id = sanitize(id);
352 if (id === '') { 347 if (id === '') {
353 return response.status(404).send({ 348 return response.status(404).send({
354 status: 'Icon doesn\'t exist', 349 status: "Icon doesn't exist",
355 }); 350 });
356 } 351 }
357 352
358 const iconPath = path.join(Application.tmpPath('uploads'), id); 353 const iconPath = path.join(app.tmpPath('uploads'), id);
359 354
360 try { 355 try {
361 await fs.access(iconPath); 356 await fs.access(iconPath);
362 } catch { 357 } catch {
363 // File not available. 358 // File not available.
364 return response.status(404).send({ 359 return response.status(404).send({
365 status: 'Icon doesn\'t exist', 360 status: "Icon doesn't exist",
366 }); 361 });
367 } 362 }
368 363
diff --git a/app/Controllers/Http/StaticsController.ts b/app/Controllers/Http/StaticsController.ts
index e221177..a94a9ba 100644
--- a/app/Controllers/Http/StaticsController.ts
+++ b/app/Controllers/Http/StaticsController.ts
@@ -1,3 +1,3 @@
1// import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' 1// import type { HttpContext } from '@adonisjs/core/http'
2 2
3export default class StaticsController {} 3export default class StaticsController {}
diff --git a/app/Controllers/Http/UserController.ts b/app/Controllers/Http/UserController.ts
index ef7cfdd..bcf0171 100644
--- a/app/Controllers/Http/UserController.ts
+++ b/app/Controllers/Http/UserController.ts
@@ -1,15 +1,17 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2import { schema, rules } from '@ioc:Adonis/Core/Validator'; 2import { schema, rules } from '@adonisjs/validator';
3import User from 'App/Models/User'; 3import User from '#app/Models/User';
4import { connectWithFranz, isRegistrationEnabled } from '../../../config/app'; 4import {
5 connectWithFranz,
6 isRegistrationEnabled,
7} from '../../../config/app.js';
5import crypto from 'node:crypto'; 8import crypto from 'node:crypto';
6import { v4 as uuid } from 'uuid'; 9import { v4 as uuid } from 'uuid';
7import Workspace from 'App/Models/Workspace'; 10import Workspace from '#app/Models/Workspace';
8import Service from 'App/Models/Service'; 11import Service from '#app/Models/Service';
9import fetch from 'node-fetch';
10 12
11// TODO: This file needs to be refactored and cleaned up to include types 13// TODO: This file needs to be refactored and cleaned up to include types
12import { handleVerifyAndReHash } from '../../../helpers/PasswordHash'; 14import { handleVerifyAndReHash } from '../../../helpers/PasswordHash.js';
13 15
14const newPostSchema = schema.create({ 16const newPostSchema = schema.create({
15 firstname: schema.string(), 17 firstname: schema.string(),
@@ -54,7 +56,7 @@ const franzRequest = (route: any, method: any, auth: any) =>
54 56
55export default class UsersController { 57export default class UsersController {
56 // Register a new user 58 // Register a new user
57 public async signup({ request, response, auth }: HttpContextContract) { 59 public async signup({ request, response, auth }: HttpContext) {
58 if (isRegistrationEnabled === 'false') { 60 if (isRegistrationEnabled === 'false') {
59 return response.status(401).send({ 61 return response.status(401).send({
60 message: 'Registration is disabled on this server', 62 message: 'Registration is disabled on this server',
@@ -100,7 +102,7 @@ export default class UsersController {
100 } 102 }
101 103
102 // Login using an existing user 104 // Login using an existing user
103 public async login({ request, response, auth }: HttpContextContract) { 105 public async login({ request, response, auth }: HttpContext) {
104 if (!request.header('Authorization')) { 106 if (!request.header('Authorization')) {
105 return response.status(401).send({ 107 return response.status(401).send({
106 message: 'Please provide authorization', 108 message: 'Please provide authorization',
@@ -149,7 +151,7 @@ export default class UsersController {
149 } 151 }
150 152
151 // Return information about the current user 153 // Return information about the current user
152 public async me({ request, response, auth }: HttpContextContract) { 154 public async me({ request, response, auth }: HttpContext) {
153 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'. 155 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'.
154 const user = auth.user ?? request.user; 156 const user = auth.user ?? request.user;
155 157
@@ -179,7 +181,7 @@ export default class UsersController {
179 }); 181 });
180 } 182 }
181 183
182 public async updateMe({ request, response, auth }: HttpContextContract) { 184 public async updateMe({ request, response, auth }: HttpContext) {
183 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'. 185 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'.
184 const user = auth.user ?? request.user; 186 const user = auth.user ?? request.user;
185 187
@@ -220,7 +222,7 @@ export default class UsersController {
220 }); 222 });
221 } 223 }
222 224
223 public async newToken({ request, response, auth }: HttpContextContract) { 225 public async newToken({ request, response, auth }: HttpContext) {
224 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'. 226 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'.
225 const user = auth.user ?? request.user; 227 const user = auth.user ?? request.user;
226 228
@@ -235,7 +237,7 @@ export default class UsersController {
235 }); 237 });
236 } 238 }
237 239
238 public async import({ request, response, view }: HttpContextContract) { 240 public async import({ request, response, view }: HttpContext) {
239 if (isRegistrationEnabled === 'false') { 241 if (isRegistrationEnabled === 'false') {
240 return response.status(401).send({ 242 return response.status(401).send({
241 message: 'Registration is disabled on this server', 243 message: 'Registration is disabled on this server',
@@ -290,7 +292,8 @@ export default class UsersController {
290 'x-franz-source': 'Web', 292 'x-franz-source': 'Web',
291 }, 293 },
292 }); 294 });
293 const content = await rawResponse.json(); 295 // eslint-disable-next-line @typescript-eslint/no-explicit-any
296 const content: any = await rawResponse.json();
294 297
295 if (!content.message || content.message !== 'Successfully logged in') { 298 if (!content.message || content.message !== 'Successfully logged in') {
296 const errorMessage = 299 const errorMessage =
diff --git a/app/Controllers/Http/WorkspaceController.ts b/app/Controllers/Http/WorkspaceController.ts
index 70af343..6cecf69 100644
--- a/app/Controllers/Http/WorkspaceController.ts
+++ b/app/Controllers/Http/WorkspaceController.ts
@@ -1,6 +1,6 @@
1import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; 1import type { HttpContext } from '@adonisjs/core/http';
2import { validator, schema } from '@ioc:Adonis/Core/Validator'; 2import { validator, schema } from '@adonisjs/validator';
3import Workspace from 'App/Models/Workspace'; 3import Workspace from '#app/Models/Workspace';
4import { v4 as uuid } from 'uuid'; 4import { v4 as uuid } from 'uuid';
5 5
6const createSchema = schema.create({ 6const createSchema = schema.create({
@@ -17,7 +17,7 @@ const deleteSchema = schema.create({
17 17
18export default class WorkspaceController { 18export default class WorkspaceController {
19 // Create a new workspace for user 19 // Create a new workspace for user
20 public async create({ request, response, auth }: HttpContextContract) { 20 public async create({ request, response, auth }: HttpContext) {
21 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'. 21 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'.
22 const user = auth.user ?? request.user; 22 const user = auth.user ?? request.user;
23 23
@@ -67,7 +67,7 @@ export default class WorkspaceController {
67 }); 67 });
68 } 68 }
69 69
70 public async edit({ request, response, auth, params }: HttpContextContract) { 70 public async edit({ request, response, auth, params }: HttpContext) {
71 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'. 71 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'.
72 const user = auth.user ?? request.user; 72 const user = auth.user ?? request.user;
73 73
@@ -113,12 +113,7 @@ export default class WorkspaceController {
113 }); 113 });
114 } 114 }
115 115
116 public async delete({ 116 public async delete({ request, response, auth, params }: HttpContext) {
117 request,
118 response,
119 auth,
120 params,
121 }: HttpContextContract) {
122 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'. 117 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'.
123 const user = auth.user ?? request.user; 118 const user = auth.user ?? request.user;
124 119
@@ -155,7 +150,7 @@ export default class WorkspaceController {
155 } 150 }
156 151
157 // List all workspaces a user has created 152 // List all workspaces a user has created
158 public async list({ request, response, auth }: HttpContextContract) { 153 public async list({ request, response, auth }: HttpContext) {
159 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'. 154 // @ts-expect-error Property 'user' does not exist on type 'HttpContextContract'.
160 const user = auth.user ?? request.user; 155 const user = auth.user ?? request.user;
161 156