mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
refactor: unify backend and frontend servers (#3)
* refactor: unify backend and frontend servers * refactor: correct paths for openapi & drizzle * refactor: move api-client to client * fix: drizzle paths * chore: fix linting issues * fix: form reset issue
This commit is contained in:
73
app/server/core/capabilities.ts
Normal file
73
app/server/core/capabilities.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import * as fs from "node:fs/promises";
|
||||
import Docker from "dockerode";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
export type SystemCapabilities = {
|
||||
docker: boolean;
|
||||
rclone: boolean;
|
||||
};
|
||||
|
||||
let capabilitiesPromise: Promise<SystemCapabilities> | null = null;
|
||||
|
||||
/**
|
||||
* Returns the current system capabilities.
|
||||
* On first call, detects all capabilities and caches the promise.
|
||||
* Subsequent calls return the same cached promise, ensuring detection only happens once.
|
||||
*/
|
||||
export async function getCapabilities(): Promise<SystemCapabilities> {
|
||||
if (capabilitiesPromise === null) {
|
||||
// Start detection and cache the promise
|
||||
capabilitiesPromise = detectCapabilities();
|
||||
}
|
||||
|
||||
return capabilitiesPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects which optional capabilities are available in the current environment
|
||||
*/
|
||||
async function detectCapabilities(): Promise<SystemCapabilities> {
|
||||
return {
|
||||
docker: await detectDocker(),
|
||||
rclone: await detectRclone(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Docker is available by:
|
||||
* 1. Checking if /var/run/docker.sock exists and is accessible
|
||||
* 2. Attempting to ping the Docker daemon
|
||||
*/
|
||||
async function detectDocker(): Promise<boolean> {
|
||||
try {
|
||||
await fs.access("/var/run/docker.sock");
|
||||
|
||||
const docker = new Docker();
|
||||
await docker.ping();
|
||||
|
||||
logger.info("Docker capability: enabled");
|
||||
return true;
|
||||
} catch (_) {
|
||||
logger.warn(
|
||||
"Docker capability: disabled. " +
|
||||
"To enable: mount /var/run/docker.sock and /run/docker/plugins in docker-compose.yml",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if rclone is available by:
|
||||
* 1. Checking if /root/.config/rclone directory exists and is accessible
|
||||
*/
|
||||
async function detectRclone(): Promise<boolean> {
|
||||
try {
|
||||
await fs.access("/root/.config/rclone");
|
||||
|
||||
logger.info("rclone capability: enabled");
|
||||
return true;
|
||||
} catch (_) {
|
||||
logger.warn("rclone capability: disabled. " + "To enable: mount /root/.config/rclone in docker-compose.yml");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user