@muhammedaksam/easiarr 1.1.7 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Unraid Detection and Compatibility Utilities
3
+ * Provides detection of Unraid environment and path adjustments
4
+ */
5
+
6
+ import { existsSync } from "node:fs"
7
+ import { homedir } from "node:os"
8
+ import { join } from "node:path"
9
+ import { debugLog } from "./debug"
10
+
11
+ // Unraid-specific paths
12
+ const UNRAID_IDENTIFIERS = [
13
+ "/boot/config/plugins", // Unraid plugin directory
14
+ "/etc/unraid-version", // Unraid version file
15
+ "/var/local/emhttp", // Unraid emhttp directory
16
+ ]
17
+
18
+ const UNRAID_APPDATA_PATH = "/mnt/user/appdata"
19
+ const COMPOSE_MANAGER_PLUGIN_PATH = "/boot/config/plugins/compose.manager"
20
+
21
+ /**
22
+ * Detect if running on Unraid OS
23
+ * Checks for Unraid-specific filesystem paths
24
+ */
25
+ export function isUnraid(): boolean {
26
+ for (const path of UNRAID_IDENTIFIERS) {
27
+ if (existsSync(path)) {
28
+ debugLog("Unraid", `Detected Unraid OS (found ${path})`)
29
+ return true
30
+ }
31
+ }
32
+ return false
33
+ }
34
+
35
+ /**
36
+ * Get the default appdata path for Unraid
37
+ * Returns /mnt/user/appdata/easiarr on Unraid, ~/.easiarr otherwise
38
+ */
39
+ export function getUnraidAppDataPath(): string {
40
+ if (isUnraid()) {
41
+ return join(UNRAID_APPDATA_PATH, "easiarr")
42
+ }
43
+ return join(homedir(), ".easiarr")
44
+ }
45
+
46
+ /**
47
+ * Check if Docker Compose Manager plugin is installed
48
+ * This plugin allows managing compose stacks via Unraid's web UI
49
+ */
50
+ export function hasComposeManager(): boolean {
51
+ return existsSync(COMPOSE_MANAGER_PLUGIN_PATH)
52
+ }
53
+
54
+ /**
55
+ * Get the recommended Compose Manager project directory
56
+ * Compose Manager expects projects in /boot/config/plugins/compose.manager/projects/
57
+ */
58
+ export function getComposeManagerProjectPath(projectName: string = "easiarr"): string {
59
+ return join(COMPOSE_MANAGER_PLUGIN_PATH, "projects", projectName)
60
+ }
61
+
62
+ /**
63
+ * Get platform-appropriate default root directory
64
+ * Adjusts paths for Unraid vs standard Linux/Mac
65
+ */
66
+ export function getDefaultRootDir(): string {
67
+ if (isUnraid()) {
68
+ // On Unraid, use /mnt/user/data for media and /mnt/user/appdata for configs
69
+ return "/mnt/user/data"
70
+ }
71
+ // Standard path
72
+ return join(homedir(), "easiarr")
73
+ }
74
+
75
+ /**
76
+ * Get platform-appropriate config directory
77
+ */
78
+ export function getConfigDir(): string {
79
+ if (isUnraid()) {
80
+ return UNRAID_APPDATA_PATH
81
+ }
82
+ return join(homedir(), ".easiarr")
83
+ }
84
+
85
+ /**
86
+ * Get Unraid-specific information for display
87
+ */
88
+ export function getUnraidInfo(): {
89
+ isUnraid: boolean
90
+ hasComposeManager: boolean
91
+ appDataPath: string
92
+ composeManagerPath: string | null
93
+ } {
94
+ const onUnraid = isUnraid()
95
+ return {
96
+ isUnraid: onUnraid,
97
+ hasComposeManager: onUnraid ? hasComposeManager() : false,
98
+ appDataPath: onUnraid ? UNRAID_APPDATA_PATH : join(homedir(), ".easiarr"),
99
+ composeManagerPath: onUnraid && hasComposeManager() ? getComposeManagerProjectPath() : null,
100
+ }
101
+ }