summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/util/util/Database.ts5
-rw-r--r--src/util/util/Paths.ts59
-rw-r--r--src/util/util/index.ts1
3 files changed, 63 insertions, 2 deletions
diff --git a/src/util/util/Database.ts b/src/util/util/Database.ts

index b9f8365e..c67ab568 100644 --- a/src/util/util/Database.ts +++ b/src/util/util/Database.ts
@@ -5,6 +5,7 @@ import { green, red, yellow } from "picocolors"; import { exit } from "process"; import "reflect-metadata"; import { DataSource, DataSourceOptions, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm"; +import { Paths } from "."; import * as Models from "../entities"; import { BaseClass, BaseClassWithoutId } from "../entities"; @@ -41,7 +42,7 @@ function getDataSourceOptions(): DataSourceOptions { const dbConnectionString = process.env.DATABASE || path.join(process.cwd(), "database.db"); const type = dbConnectionString.includes("://") ? dbConnectionString.split(":")[0]?.replace("+srv", "") : ("sqlite" as any); const isSqlite = type.includes("sqlite"); - const migrationsExist = fs.existsSync(path.join(__dirname, "..", "migrations", type)); + const migrationsExist = fs.existsSync(path.join(Paths.MigrationsRoot, type)); //read env vars const synchronizeInsteadOfMigrations = "DB_UNSAFE" in process.env; const verboseDb = "DB_VERBOSE" in process.env; @@ -94,7 +95,7 @@ function getDataSourceOptions(): DataSourceOptions { bigNumberStrings: false, supportBigNumbers: true, name: "default", - migrations: synchronizeInsteadOfMigrations ? [] : [path.join(__dirname, "..", "migrations", type, "*.js")], + migrations: synchronizeInsteadOfMigrations ? [] : [path.join(Paths.MigrationsRoot, type, "*.js")], migrationsRun: !synchronizeInsteadOfMigrations, applicationName: `Fosscord Server`, } as DataSourceOptions; diff --git a/src/util/util/Paths.ts b/src/util/util/Paths.ts new file mode 100644
index 00000000..20b16738 --- /dev/null +++ b/src/util/util/Paths.ts
@@ -0,0 +1,59 @@ +import path from "path"; +import fs from "fs"; + + + + + +export class ProjectPaths { + public static RuntimePath = path.join(__dirname, "..", ".."); + public static ProjectRoot = path.join(ProjectPaths.RuntimePath, ".."); + public static DataDir = path.join(ProjectPaths.ProjectRoot, "data"); + public static ApiPath = path.join(ProjectPaths.RuntimePath, "api"); + public static CdnPath = path.join(ProjectPaths.RuntimePath, "cdn"); + public static GatewayPath = path.join(ProjectPaths.RuntimePath, "gateway"); + public static UtilPath = path.join(ProjectPaths.RuntimePath, "util"); +} + +export class Paths { + public static AssetsPath = path.join(ProjectPaths.ProjectRoot, "assets"); + public static PrivateAssetsPath = path.join(ProjectPaths.DataDir, "assets"); + public static MigrationsRoot = path.join(ProjectPaths.UtilPath, "migrations"); + public static CDNFilePath = path.resolve(process.env.STORAGE_LOCATION || path.join(ProjectPaths.ProjectRoot, "files")); + public static SchemaPath = path.join(ProjectPaths.DataDir, "schemas.json"); + public static IconPath = path.join(Paths.AssetsPath, "icons"); + public static CustomIconPath = path.join(Paths.AssetsPath, "icons", "custom"); +} + +export class TestClientPaths { + public static TestClientRoot = path.join(ProjectPaths.DataDir, "test-client"); + public static TestClientCacheDir = process.env.TEST_CLIENT_CACHE_DIR || process.env.ASSET_CACHE_DIR || path.join(TestClientPaths.TestClientRoot, "cache"); + public static Index = path.join(TestClientPaths.TestClientRoot, "index.html"); + public static Developers = path.join(TestClientPaths.TestClientRoot, "developers.html"); + public static PatchDir = path.join(TestClientPaths.TestClientRoot, "patches"); + public static CacheDir = TestClientPaths.TestClientCacheDir; + public static CacheIndex = path.join(TestClientPaths.TestClientCacheDir, "index.json"); + public static PluginsDir = path.join(TestClientPaths.TestClientRoot, "plugins"); + public static PreloadPluginsDir = path.join(TestClientPaths.TestClientRoot, "preload-plugins"); + public static InlinePluginsDir = path.join(TestClientPaths.TestClientRoot, "inline-plugins"); +} + + +//warnings +if(process.env.ASSET_CACHE_DIR) console.log(`[ENV/WARN] ASSET_CACHE_DIR is deprecated, please use TEST_CLIENT_CACHE_DIR instead!`); + +for(let key in ProjectPaths) { + if(!fs.existsSync((ProjectPaths as any)[key])) { + console.error(`[ERROR] ${(ProjectPaths as any)[key]} does not exist!`); + } +} +for(let key in Paths) { + if(!fs.existsSync((Paths as any)[key])) { + console.error(`[ERROR] ${(Paths as any)[key]} does not exist!`); + } +} +for(let key in TestClientPaths) { + if(!fs.existsSync((TestClientPaths as any)[key])) { + console.error(`[ERROR] ${(TestClientPaths as any)[key]} does not exist!`); + } +} diff --git a/src/util/util/index.ts b/src/util/util/index.ts
index 11f0b72a..af29787b 100644 --- a/src/util/util/index.ts +++ b/src/util/util/index.ts
@@ -23,3 +23,4 @@ export * from "./Snowflake"; export * from "./String"; export * from "./Token"; export * from "./TraverseDirectory"; +export * from "./Paths"; \ No newline at end of file