diff --git a/backend/app.ts b/backend/app.ts index 85165c8..4c3619b 100644 --- a/backend/app.ts +++ b/backend/app.ts @@ -9,13 +9,13 @@ import { path, isProd } from '@tycrek/joint'; import { epcss } from '@tycrek/express-postcss'; import { log } from './log'; -import { JSONDatabase, ensureFiles } from './sql/json'; import { get } from './data'; import { UserConfig } from './UserConfig'; -import { MySQLDatabase } from './sql/mysql'; -import { buildFrontendRouter } from './routers/_frontend'; import { DBManager } from './sql/database'; +import { JSONDatabase } from './sql/json'; +import { MySQLDatabase } from './sql/mysql'; import { PostgreSQLDatabase } from './sql/postgres'; +import { buildFrontendRouter } from './routers/_frontend'; /** * Top-level metadata exports @@ -79,8 +79,9 @@ async function main() { App.pkgVersion = pkg.version; - // Ensure data files exist - await ensureFiles(); + // Ensure data directory exists + log.debug('Checking data dir') + await fs.ensureDir(path.join('.ass-data')); // Set default server configuration const serverConfig: ServerConfiguration = { @@ -130,6 +131,7 @@ async function main() { } } catch (err) { throw new Error(`Failed to configure SQL`); } } else { // default to json database + log.debug('DB not set! Defaulting to JSON'); await DBManager.use(new JSONDatabase()); } diff --git a/backend/data.ts b/backend/data.ts index 72e2f8c..118105f 100644 --- a/backend/data.ts +++ b/backend/data.ts @@ -1,7 +1,4 @@ -import { AssFile, AssUser, NID, FilesSchema, UsersSchema } from 'ass'; - -import fs from 'fs-extra'; -import { path } from '@tycrek/joint'; +import { AssFile, AssUser, NID } from 'ass'; import { log } from './log'; import { UserConfig } from './UserConfig'; @@ -12,14 +9,6 @@ import { DBManager } from './sql/database'; */ type DataSector = 'files' | 'users'; -/** - * Absolute filepaths for JSON data files - */ -const PATHS = { - files: path.join('.ass-data/files.json'), - users: path.join('.ass-data/users.json') -}; - /** * database kind -> name mapping */ diff --git a/backend/routers/api.ts b/backend/routers/api.ts index e2aa2bc..d5bad9b 100644 --- a/backend/routers/api.ts +++ b/backend/routers/api.ts @@ -45,14 +45,9 @@ router.post('/setup', BodyParserJson(), async (req, res) => { } // set rate limits - if (UserConfig.config.rateLimit?.api) setRateLimiter('api', UserConfig.config.rateLimit.api); - if (UserConfig.config.rateLimit?.login) setRateLimiter('login', UserConfig.config.rateLimit.login); - if (UserConfig.config.rateLimit?.upload) setRateLimiter('upload', UserConfig.config.rateLimit.upload); - - // set rate limits - if (UserConfig.config.rateLimit?.api) setRateLimiter('api', UserConfig.config.rateLimit.api); - if (UserConfig.config.rateLimit?.login) setRateLimiter('login', UserConfig.config.rateLimit.login); - if (UserConfig.config.rateLimit?.upload) setRateLimiter('upload', UserConfig.config.rateLimit.upload); + if (UserConfig.config.rateLimit?.api) setRateLimiter('api', UserConfig.config.rateLimit.api); + if (UserConfig.config.rateLimit?.login) setRateLimiter('login', UserConfig.config.rateLimit.login); + if (UserConfig.config.rateLimit?.upload) setRateLimiter('upload', UserConfig.config.rateLimit.upload);; log.success('Setup', 'completed'); diff --git a/backend/sql/json.ts b/backend/sql/json.ts index 6703ed2..173058f 100644 --- a/backend/sql/json.ts +++ b/backend/sql/json.ts @@ -58,8 +58,6 @@ export const ensureFiles = (): Promise => new Promise(async (resolve, reje log.debug('Checking data files'); try { - // Create data directory - await fs.ensureDir(path.join('.ass-data')); // * Default files.json await createEmptyJson(PATHS.files, { diff --git a/frontend/setup.mts b/frontend/setup.mts index c4372d8..310d3e6 100644 --- a/frontend/setup.mts +++ b/frontend/setup.mts @@ -113,8 +113,8 @@ document.addEventListener('DOMContentLoaded', () => { password: Elements.mySqlPassword.value, database: Elements.mySqlDatabase.value } - } - }; + }; + } } else if (Elements.pgsqlTab.active) { if (Elements.pgsqlHost.value != null && Elements.pgsqlHost.value != '') { config.database = { @@ -126,8 +126,8 @@ document.addEventListener('DOMContentLoaded', () => { password: Elements.pgsqlPassword.value, database: Elements.pgsqlDatabase.value } - } - }; + }; + } } // append rate limit config, if specified