Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Commit efb28a0

Browse files
committed
♻️ Refactor: Apply formatting and consistency improvements
This commit applies consistent formatting and removes unnecessary blank lines across several files, improving code readability and maintainability. No functional changes are included.
1 parent 15a6d01 commit efb28a0

File tree

7 files changed

+285
-285
lines changed

7 files changed

+285
-285
lines changed

src/core/database/containerStats.ts

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,57 +35,57 @@ const getAll = db.prepare(`
3535
`);
3636

3737
export function addContainerStats(stats: container_stats) {
38-
return executeDbOperation(
39-
"Add Container Stats",
40-
() =>
41-
insert.run(
42-
stats.id,
43-
stats.hostId,
44-
stats.name,
45-
stats.image,
46-
stats.status,
47-
stats.state,
48-
stats.cpu_usage,
49-
stats.memory_usage || 0,
50-
stats.network_rx_rate,
51-
stats.network_tx_rate,
52-
stats.network_rx_bytes,
53-
stats.network_tx_bytes,
54-
stats.timestamp || new Date().toISOString(),
55-
),
56-
() => {
57-
if (
58-
typeof stats.id !== "string" ||
59-
typeof stats.hostId !== "number" ||
60-
typeof stats.name !== "string" ||
61-
typeof stats.image !== "string" ||
62-
typeof stats.status !== "string" ||
63-
typeof stats.state !== "string" ||
64-
typeof stats.cpu_usage !== "number" ||
65-
typeof stats.memory_usage !== "number" ||
66-
typeof stats.network_rx_rate !== "number" ||
67-
typeof stats.network_tx_rate !== "number" ||
68-
typeof stats.network_rx_bytes !== "number" ||
69-
typeof stats.network_tx_bytes !== "number"
70-
) {
71-
throw new TypeError("Invalid container stats parameters");
72-
}
73-
},
74-
);
38+
return executeDbOperation(
39+
"Add Container Stats",
40+
() =>
41+
insert.run(
42+
stats.id,
43+
stats.hostId,
44+
stats.name,
45+
stats.image,
46+
stats.status,
47+
stats.state,
48+
stats.cpu_usage,
49+
stats.memory_usage || 0,
50+
stats.network_rx_rate,
51+
stats.network_tx_rate,
52+
stats.network_rx_bytes,
53+
stats.network_tx_bytes,
54+
stats.timestamp || new Date().toISOString(),
55+
),
56+
() => {
57+
if (
58+
typeof stats.id !== "string" ||
59+
typeof stats.hostId !== "number" ||
60+
typeof stats.name !== "string" ||
61+
typeof stats.image !== "string" ||
62+
typeof stats.status !== "string" ||
63+
typeof stats.state !== "string" ||
64+
typeof stats.cpu_usage !== "number" ||
65+
typeof stats.memory_usage !== "number" ||
66+
typeof stats.network_rx_rate !== "number" ||
67+
typeof stats.network_tx_rate !== "number" ||
68+
typeof stats.network_rx_bytes !== "number" ||
69+
typeof stats.network_tx_bytes !== "number"
70+
) {
71+
throw new TypeError("Invalid container stats parameters");
72+
}
73+
},
74+
);
7575
}
7676

7777
export function getContainerStats(): container_stats[] {
78-
return executeDbOperation("Get All Container Stats", () =>
79-
getAll.all(),
80-
) as container_stats[];
78+
return executeDbOperation("Get All Container Stats", () =>
79+
getAll.all(),
80+
) as container_stats[];
8181
}
8282

8383
export function getLastContainerStats(
84-
hostId: number,
85-
containerId: string,
84+
hostId: number,
85+
containerId: string,
8686
): container_stats | undefined {
87-
return executeDbOperation(
88-
"Get Last Container Stat",
89-
() => getOne.get(hostId, containerId) as container_stats,
90-
);
87+
return executeDbOperation(
88+
"Get Last Container Stat",
89+
() => getOne.get(hostId, containerId) as container_stats,
90+
);
9191
}

src/core/database/database.ts

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ const uid = userInfo().uid;
1313
export let db: Database;
1414

1515
try {
16-
const databasePath = path.join(dataFolder, "dockstatapi.db");
17-
console.log("Database path:", databasePath);
18-
console.log(`Running as: ${username} (${uid}:${gid})`);
16+
const databasePath = path.join(dataFolder, "dockstatapi.db");
17+
console.log("Database path:", databasePath);
18+
console.log(`Running as: ${username} (${uid}:${gid})`);
1919

20-
if (!existsSync(dataFolder)) {
21-
await mkdir(dataFolder, { recursive: true, mode: 0o777 });
22-
console.log("Created data directory:", dataFolder);
23-
}
20+
if (!existsSync(dataFolder)) {
21+
await mkdir(dataFolder, { recursive: true, mode: 0o777 });
22+
console.log("Created data directory:", dataFolder);
23+
}
2424

25-
db = new Database(databasePath, { create: true });
26-
console.log("Database opened successfully");
25+
db = new Database(databasePath, { create: true });
26+
console.log("Database opened successfully");
2727

28-
db.exec("PRAGMA journal_mode = WAL;");
28+
db.exec("PRAGMA journal_mode = WAL;");
2929
} catch (error) {
30-
console.error(`Cannot start DockStatAPI: ${error}`);
31-
process.exit(500);
30+
console.error(`Cannot start DockStatAPI: ${error}`);
31+
process.exit(500);
3232
}
3333

3434
export function init() {
35-
db.exec(`
35+
db.exec(`
3636
CREATE TABLE IF NOT EXISTS backend_log_entries (
3737
timestamp STRING NOT NULL,
3838
level TEXT NOT NULL,
@@ -110,11 +110,11 @@ export function init() {
110110
)
111111
`);
112112

113-
const themeRows = db
114-
.prepare("SELECT COUNT(*) AS count FROM themes")
115-
.get() as { count: number };
113+
const themeRows = db
114+
.prepare("SELECT COUNT(*) AS count FROM themes")
115+
.get() as { count: number };
116116

117-
const defaultCss = `
117+
const defaultCss = `
118118
.root,
119119
#root,
120120
#docs-root {
@@ -136,55 +136,55 @@ export function init() {
136136
}
137137
`;
138138

139-
const defaultThemeOptions = {
140-
backgroundAnimation: {
141-
enabled: true,
142-
from: ["#c084fc", "#818cf9", "#60a5fa"],
143-
},
144-
};
145-
146-
if (themeRows.count === 0) {
147-
db.prepare(
148-
"INSERT INTO themes (name, creator, vars, options, tags) VALUES (?,?,?,?,?)",
149-
).run(
150-
"default",
151-
"Its4Nik",
152-
defaultCss,
153-
JSON.stringify(defaultThemeOptions),
154-
"default, dark",
155-
);
156-
}
157-
158-
const configRow = db
159-
.prepare("SELECT COUNT(*) AS count FROM config")
160-
.get() as { count: number };
161-
162-
if (configRow.count === 0) {
163-
db.prepare(
164-
"INSERT INTO config (keep_data_for, fetching_interval) VALUES (7, 5)",
165-
).run();
166-
}
167-
168-
const hostRow = db
169-
.prepare("SELECT COUNT(*) AS count FROM docker_hosts")
170-
.get() as { count: number };
171-
172-
if (hostRow.count === 0) {
173-
db.prepare(
174-
"INSERT INTO docker_hosts (name, hostAddress, secure) VALUES (?, ?, ?)",
175-
).run("Localhost", "localhost:2375", false);
176-
}
177-
178-
const storeRow = db
179-
.prepare("SELECT COUNT(*) AS count FROM store_repos")
180-
.get() as { count: number };
181-
182-
if (storeRow.count === 0) {
183-
db.prepare("INSERT INTO store_repos (slug, base) VALUES (?, ?)").run(
184-
"DockStacks",
185-
"https://raw.githubusercontent.com/Its4Nik/DockStacks/refs/heads/main/Index.json",
186-
);
187-
}
139+
const defaultThemeOptions = {
140+
backgroundAnimation: {
141+
enabled: true,
142+
from: ["#c084fc", "#818cf9", "#60a5fa"],
143+
},
144+
};
145+
146+
if (themeRows.count === 0) {
147+
db.prepare(
148+
"INSERT INTO themes (name, creator, vars, options, tags) VALUES (?,?,?,?,?)",
149+
).run(
150+
"default",
151+
"Its4Nik",
152+
defaultCss,
153+
JSON.stringify(defaultThemeOptions),
154+
"default, dark",
155+
);
156+
}
157+
158+
const configRow = db
159+
.prepare("SELECT COUNT(*) AS count FROM config")
160+
.get() as { count: number };
161+
162+
if (configRow.count === 0) {
163+
db.prepare(
164+
"INSERT INTO config (keep_data_for, fetching_interval) VALUES (7, 5)",
165+
).run();
166+
}
167+
168+
const hostRow = db
169+
.prepare("SELECT COUNT(*) AS count FROM docker_hosts")
170+
.get() as { count: number };
171+
172+
if (hostRow.count === 0) {
173+
db.prepare(
174+
"INSERT INTO docker_hosts (name, hostAddress, secure) VALUES (?, ?, ?)",
175+
).run("Localhost", "localhost:2375", false);
176+
}
177+
178+
const storeRow = db
179+
.prepare("SELECT COUNT(*) AS count FROM store_repos")
180+
.get() as { count: number };
181+
182+
if (storeRow.count === 0) {
183+
db.prepare("INSERT INTO store_repos (slug, base) VALUES (?, ?)").run(
184+
"DockStacks",
185+
"https://raw.githubusercontent.com/Its4Nik/DockStacks/refs/heads/main/Index.json",
186+
);
187+
}
188188
}
189189

190190
init();

src/core/database/themes.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,52 @@ import { db } from "./database";
44
import { executeDbOperation } from "./helper";
55

66
const stmt = {
7-
insert: db.prepare(`
7+
insert: db.prepare(`
88
INSERT INTO themes (name, creator, vars, options, tags) VALUES (?, ?, ?, ?, ?)
99
`),
10-
remove: db.prepare("DELETE FROM themes WHERE name = ?"),
11-
read: db.prepare(
12-
"SELECT name, creator, vars, tags FROM themes WHERE name = ?",
13-
),
14-
readOptions: db.prepare("SELECT options FROM themes WHERE name = ?"),
15-
readAll: db.prepare("SELECT * FROM themes"),
10+
remove: db.prepare("DELETE FROM themes WHERE name = ?"),
11+
read: db.prepare(
12+
"SELECT name, creator, vars, tags FROM themes WHERE name = ?",
13+
),
14+
readOptions: db.prepare("SELECT options FROM themes WHERE name = ?"),
15+
readAll: db.prepare("SELECT * FROM themes"),
1616
};
1717

1818
export function getThemes() {
19-
return executeDbOperation("Get Themes", () => stmt.readAll.all()) as Theme[];
19+
return executeDbOperation("Get Themes", () => stmt.readAll.all()) as Theme[];
2020
}
2121

2222
export function addTheme({ name, creator, options, vars, tags }: Theme) {
23-
return executeDbOperation("Save Theme", () =>
24-
stmt.insert.run(
25-
name,
26-
creator,
27-
vars,
28-
JSON.stringify(options),
29-
tags.toString(),
30-
),
31-
);
23+
return executeDbOperation("Save Theme", () =>
24+
stmt.insert.run(
25+
name,
26+
creator,
27+
vars,
28+
JSON.stringify(options),
29+
tags.toString(),
30+
),
31+
);
3232
}
3333

3434
export function getSpecificTheme(name: string): Theme {
35-
return executeDbOperation(
36-
"Getting specific Theme",
37-
() => stmt.read.get(name) as Theme,
38-
);
35+
return executeDbOperation(
36+
"Getting specific Theme",
37+
() => stmt.read.get(name) as Theme,
38+
);
3939
}
4040

4141
export function getThemeOptions(name: string): ThemeOptions {
42-
const data = executeDbOperation(
43-
"Getting Theme Options",
44-
() => (stmt.readOptions.get(name) as { options: string }).options,
45-
);
42+
const data = executeDbOperation(
43+
"Getting Theme Options",
44+
() => (stmt.readOptions.get(name) as { options: string }).options,
45+
);
4646

47-
logger.debug(`RAW DB: ${JSON.stringify(stmt.readOptions.get(name))}`);
47+
logger.debug(`RAW DB: ${JSON.stringify(stmt.readOptions.get(name))}`);
4848

49-
return JSON.parse(data);
49+
return JSON.parse(data);
5050
}
5151

5252
export function deleteTheme(name: string) {
53-
logger.debug(`Removing ${name} from themes `);
54-
return executeDbOperation("Remove Theme", () => stmt.remove.run(name));
53+
logger.debug(`Removing ${name} from themes `);
54+
return executeDbOperation("Remove Theme", () => stmt.remove.run(name));
5555
}

0 commit comments

Comments
 (0)