From 7791af03c1e6154b10285303e935661b5753f3ae Mon Sep 17 00:00:00 2001 From: Sylvie Date: Sun, 3 Dec 2023 16:57:30 -0700 Subject: [PATCH] feat: add port to MySQL config --- backend/UserConfig.ts | 2 ++ common/types.d.ts | 2 ++ frontend/setup.mts | 12 +++++++----- views/setup.pug | 2 ++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/backend/UserConfig.ts b/backend/UserConfig.ts index fa16b37..8b452e0 100644 --- a/backend/UserConfig.ts +++ b/backend/UserConfig.ts @@ -57,6 +57,7 @@ const Checkers: UserConfigTypeChecker = { user: basicStringChecker, password: basicStringChecker, database: basicStringChecker, + port: (val) => numChecker(val) && val >= 1 && val <= 65535 }, postgres: { port: (val) => numChecker(val) && val >= 1 && val <= 65535 @@ -114,6 +115,7 @@ export class UserConfig { if (!Checkers.sql.mySql.user(config.database.options.user)) throw new Error('Invalid databse user'); if (!Checkers.sql.mySql.password(config.database.options.password)) throw new Error('Invalid database password'); if (!Checkers.sql.mySql.database(config.database.options.database)) throw new Error('Invalid database'); + if (!Checkers.sql.mySql.port(config.database.options.port)) throw new Error('Invalid database port'); if (config.database.kind == 'postgres') { if (!Checkers.sql.postgres.port((config.database.options as PostgresConfiguration).port)) { throw new Error("Invalid database port"); diff --git a/common/types.d.ts b/common/types.d.ts index ddc3cd8..2d13284 100644 --- a/common/types.d.ts +++ b/common/types.d.ts @@ -58,6 +58,7 @@ declare module 'ass' { interface MySQLConfiguration { host: string; + port: number; user: string; password: string; database: string; @@ -126,6 +127,7 @@ declare module 'ass' { sql: { mySql: { host: (val: any) => boolean; + port: (val: any) => boolean; user: (val: any) => boolean; password: (val: any) => boolean; database: (val: any) => boolean; diff --git a/frontend/setup.mts b/frontend/setup.mts index 310d3e6..25e730f 100644 --- a/frontend/setup.mts +++ b/frontend/setup.mts @@ -45,6 +45,7 @@ document.addEventListener('DOMContentLoaded', () => { mySqlTab: document.querySelector('#mysql-tab') as SlTab, mySqlHost: document.querySelector('#mysql-host') as SlInput, + mySqlPort: document.querySelector('#mysql-port') as SlInput, mySqlUser: document.querySelector('#mysql-user') as SlInput, mySqlPassword: document.querySelector('#mysql-password') as SlInput, mySqlDatabase: document.querySelector('#mysql-database') as SlInput, @@ -108,8 +109,9 @@ document.addEventListener('DOMContentLoaded', () => { config.database = { kind: 'mysql', options: { - host: Elements.mySqlHost.value, - user: Elements.mySqlUser.value, + host: Elements.mySqlHost.value, + port: parseInt(Elements.mySqlPort.value), + user: Elements.mySqlUser.value, password: Elements.mySqlPassword.value, database: Elements.mySqlDatabase.value } @@ -120,9 +122,9 @@ document.addEventListener('DOMContentLoaded', () => { config.database = { kind: 'postgres', options: { - host: Elements.pgsqlHost.value, - port: parseInt(Elements.pgsqlPort.value), - user: Elements.pgsqlUser.value, + host: Elements.pgsqlHost.value, + port: parseInt(Elements.pgsqlPort.value), + user: Elements.pgsqlUser.value, password: Elements.pgsqlPassword.value, database: Elements.pgsqlDatabase.value } diff --git a/views/setup.pug b/views/setup.pug index 5426e4e..76b62dc 100644 --- a/views/setup.pug +++ b/views/setup.pug @@ -44,6 +44,8 @@ block content sl-tab-panel(name='mysql') h3.setup-text-item-title Host sl-input#mysql-host(type='text' placeholder='mysql.example.com' clearable): sl-icon(slot='prefix' name='fas-server' library='fa') + h3.setup-text-item-title Port + sl-input#mysql-port(type='number' placeholder='3306' min='1' max='65535' no-spin-buttons clearable): sl-icon(slot='prefix' name='fas-hashtag' library='fa') h3.setup-text-item-title User sl-input#mysql-user(type='text' placeholder='myassql' clearable): sl-icon(slot='prefix' name='fas-user' library='fa') h3.setup-text-item-title Password