Skip to content

Commit

Permalink
Merge pull request #2 from Mirasaki/dev
Browse files Browse the repository at this point in the history
feat: RemoteDirectoryAccess
  • Loading branch information
Mirasaki authored Aug 18, 2023
2 parents 55387ac + bb65681 commit eb9ac90
Show file tree
Hide file tree
Showing 9 changed files with 771 additions and 93 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</div>

<p align="center">
Allows remote access to local files and JSON databases through a simple configuration file. Minimal set-up, maximum configuration and extendibility.
Allows remote access to local files, directories and JSON databases through a simple configuration file. Minimal set-up, maximum configuration and extendibility.
</p>

<br />
Expand Down
33 changes: 22 additions & 11 deletions config/config.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,75 @@ import { UserConfig } from './internal/types';

// This is meant as a complete example of the configuration

// Docs: https://wiki.mirasaki.dev/docs/remote-file-access-api/configuration

const userConfig: UserConfig = {
API_KEY: '__REPLACE_THIS_WITH_A_STRONG_API_KEY',
PORT: 9000,
REMOTE_FILES: [
{
NAME: 'Air Raids',
FILE_NAME: 'AirRaid.txt',
DIRECTORY: '/home/mirasaki/OmegaManager/servers/0/profiles',
DIRECTORY: 'C:\\OmegaManager\\servers\\0\\profiles',
// Linux:
// DIRECTORY: '/home/mirasaki/projects/started-but-never-finished-381',
USE_LATEST_LINES: 500
},
{
NAME: 'Loot Chests',
FILE_NAME: 'LootChests_LOG.txt',
DIRECTORY: '/home/mirasaki/OmegaManager/servers/0/profiles/CJ_LootChests',
DIRECTORY: 'C:\\OmegaManager\\servers\\0\\profiles\\CJ_LootChests',
USE_LATEST_LINES: 500,
},
{
NAME: 'Treasure',
FILE_NAME: 'Treasure.txt',
DIRECTORY: '/home/mirasaki/OmegaManager/servers/0/profiles/Treasure',
DIRECTORY: 'C:\\OmegaManager\\servers\\0\\profiles\\Treasure',
USE_LATEST_LINES: 500
},

{
NAME: 'Code Lock - Access',
DIRECTORY: '/home/mirasaki/OmegaManager/servers/0/profiles/CodeLock/Logs/Access',
DIRECTORY: 'C:\\OmegaManager\\servers\\0\\profiles\\CodeLock\\Logs\\Access',
},
{
NAME: 'Code Lock - Attach',
DIRECTORY: '/home/mirasaki/OmegaManager/servers/0/profiles/CodeLock/Logs/Attach',
DIRECTORY: 'C:\\OmegaManager\\servers\\0\\profiles\\CodeLock\\Logs\\Attach',
},
{
NAME: 'Code Lock - Raid',
DIRECTORY: '/home/mirasaki/OmegaManager/servers/0/profiles/CodeLock/Logs/Raid',
DIRECTORY: 'C:\\OmegaManager\\servers\\0\\profiles\\CodeLock\\Logs\\Raid',
},

{
NAME: 'Casino',
DIRECTORY: '/home/mirasaki/OmegaManager/servers/0/profiles/DayZCasinoV2',
DIRECTORY: 'C:\\OmegaManager\\servers\\0\\profiles\\DayZCasinoV2',
EXTENSION: 'csv'
},
{
NAME: 'Expansion',
DIRECTORY: '/home/mirasaki/OmegaManager/servers/0/profiles/ExpansionMod/Logs',
DIRECTORY: 'C:\\OmegaManager\\servers\\0\\profiles\\ExpansionMod\\Logs',
},
{
NAME: 'Hacking',
DIRECTORY: '/home/mirasaki/OmegaManager/servers/0/profiles/HackingSystemV2/Logs',
DIRECTORY: 'C:\\OmegaManager\\servers\\0\\profiles\\HackingSystemV2\\Logs',
},
{
NAME: 'King of the Hill',
DIRECTORY: '/home/mirasaki/OmegaManager/servers/0/profiles/KOTH/Logs',
DIRECTORY: 'C:\\OmegaManager\\servers\\0\\profiles\\KOTH\\Logs',
}
],
REMOTE_DIRECTORIES: [
{
NAME: 'Server 0 - Profiles',
DIRECTORY: 'C:\\OmegaManager\\servers\\0\\profiles',
EXTENSIONS: null
}
],
REMOTE_JSON_DATABASES: [
{
NAME: 'LB Banking | Balance',
DIRECTORY: '/home/mirasaki/OmegaManager/servers/0/profiles/LB_Banking/Players',
DIRECTORY: 'C:\\OmegaManager\\servers\\0\\profiles\\LB_Banking\\Players',
}
]
};
Expand Down
13 changes: 13 additions & 0 deletions config/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface RequiredUserConfig {
API_KEY: string;
/** File configuration to allow remote access to files */
REMOTE_FILES: RemoteFileAccess[];
REMOTE_DIRECTORIES: RemoteDirectoryAccess[];
/** JSON database configuration, allows remote management of local JSON data */
REMOTE_JSON_DATABASES: JsonDatabase[];
/**
Expand Down Expand Up @@ -59,6 +60,18 @@ export interface RemoteFileAccess {
EXTENSION?: string | null;
}

export interface RemoteDirectoryAccess {
/** The name for this remote access content, should be unique */
NAME: string;
/**
* The absolute path to the directory that should be accessed remotely.
* Escape paths on Windows: `C:\\Users\\OmegaManager\\servers\\0\\profiles`
*/
DIRECTORY: string;
/** Whitelisted file extensions - everything is whitelisted if empty or null */
EXTENSIONS?: string[] | null;
}

export interface JsonDatabase {
/** The name for this remote json database, should be unique */
NAME: string;
Expand Down
13 changes: 13 additions & 0 deletions config/internal/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ export const validateConfig = () => {
}
}

// Validate all our remote directory access configs
for (const rdCfg of mergedConfig.REMOTE_DIRECTORIES) {
const normalizedPath = path.normalize(rdCfg.DIRECTORY);

// Always required valid DIRECTORY
if (!existsSync(normalizedPath)) {
console.error(stripIndents`
[Configuration - REMOTE_DIRECTORIES] "DIRECTORY" path does not exist (${rdCfg.DIRECTORY})
`);
process.exit(1);
}
}

// Validate all JSON database configs
for (const jsonDbCfg of mergedConfig.REMOTE_JSON_DATABASES) {
const normalizedPath = path.normalize(jsonDbCfg.DIRECTORY);
Expand Down
Loading

0 comments on commit eb9ac90

Please sign in to comment.