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

Commit 93f3f79

Browse files
committed
CQL: Apply lint fixes [skip ci]
1 parent 47900c0 commit 93f3f79

9 files changed

Lines changed: 1141 additions & 1141 deletions

File tree

src/core/database/containerStats.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,43 @@ const insert = db.prepare(`
1010
const get = db.prepare("SELECT * FROM container_stats");
1111

1212
export function addContainerStats(
13-
id: string,
14-
hostId: string,
15-
name: string,
16-
image: string,
17-
status: string,
18-
state: string,
19-
cpu_usage: number,
20-
memory_usage: number
13+
id: string,
14+
hostId: string,
15+
name: string,
16+
image: string,
17+
status: string,
18+
state: string,
19+
cpu_usage: number,
20+
memory_usage: number,
2121
) {
22-
return executeDbOperation(
23-
"Add Container Stats",
24-
() =>
25-
insert.run(
26-
id,
27-
hostId,
28-
name,
29-
image,
30-
status,
31-
state,
32-
cpu_usage,
33-
memory_usage
34-
),
35-
() => {
36-
if (
37-
typeof id !== "string" ||
38-
typeof hostId !== "string" ||
39-
typeof cpu_usage !== "number" ||
40-
typeof memory_usage !== "number"
41-
) {
42-
throw new TypeError("Invalid container stats parameters");
43-
}
44-
}
45-
);
22+
return executeDbOperation(
23+
"Add Container Stats",
24+
() =>
25+
insert.run(
26+
id,
27+
hostId,
28+
name,
29+
image,
30+
status,
31+
state,
32+
cpu_usage,
33+
memory_usage,
34+
),
35+
() => {
36+
if (
37+
typeof id !== "string" ||
38+
typeof hostId !== "string" ||
39+
typeof cpu_usage !== "number" ||
40+
typeof memory_usage !== "number"
41+
) {
42+
throw new TypeError("Invalid container stats parameters");
43+
}
44+
},
45+
);
4646
}
4747

4848
export function getContainerStats(): containerStatistics[] {
49-
return executeDbOperation("Get Container Stats", () =>
50-
get.all()
51-
) as containerStatistics[];
49+
return executeDbOperation("Get Container Stats", () =>
50+
get.all(),
51+
) as containerStatistics[];
5252
}

src/core/database/database.ts

Lines changed: 32 additions & 32 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,
@@ -95,25 +95,25 @@ export function init() {
9595
);
9696
`);
9797

98-
const configRow = db
99-
.prepare("SELECT COUNT(*) AS count FROM config")
100-
.get() as { count: number };
101-
102-
if (configRow.count === 0) {
103-
db.prepare(
104-
'INSERT INTO config (keep_data_for, fetching_interval, api_key) VALUES (7, 5, "changeme")'
105-
).run();
106-
}
107-
108-
const hostRow = db
109-
.prepare("SELECT COUNT(*) AS count FROM docker_hosts")
110-
.get() as { count: number };
111-
112-
if (hostRow.count === 0) {
113-
db.prepare(
114-
"INSERT INTO docker_hosts (name, hostAddress, secure) VALUES (?, ?, ?)"
115-
).run("Localhost", "localhost:2375", false);
116-
}
98+
const configRow = db
99+
.prepare("SELECT COUNT(*) AS count FROM config")
100+
.get() as { count: number };
101+
102+
if (configRow.count === 0) {
103+
db.prepare(
104+
'INSERT INTO config (keep_data_for, fetching_interval, api_key) VALUES (7, 5, "changeme")',
105+
).run();
106+
}
107+
108+
const hostRow = db
109+
.prepare("SELECT COUNT(*) AS count FROM docker_hosts")
110+
.get() as { count: number };
111+
112+
if (hostRow.count === 0) {
113+
db.prepare(
114+
"INSERT INTO docker_hosts (name, hostAddress, secure) VALUES (?, ?, ?)",
115+
).run("Localhost", "localhost:2375", false);
116+
}
117117
}
118118

119119
init();

src/core/database/dockerHosts.ts

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

55
const stmt = {
6-
insert: db.prepare(
7-
"INSERT INTO docker_hosts (name, hostAddress, secure) VALUES (?, ?, ?)"
8-
),
9-
selectAll: db.prepare(
10-
"SELECT id, name, hostAddress, secure FROM docker_hosts ORDER BY id DESC"
11-
),
12-
update: db.prepare(
13-
"UPDATE docker_hosts SET hostAddress = ?, secure = ?, name = ? WHERE id = ?"
14-
),
15-
delete: db.prepare("DELETE FROM docker_hosts WHERE id = ?"),
6+
insert: db.prepare(
7+
"INSERT INTO docker_hosts (name, hostAddress, secure) VALUES (?, ?, ?)",
8+
),
9+
selectAll: db.prepare(
10+
"SELECT id, name, hostAddress, secure FROM docker_hosts ORDER BY id DESC",
11+
),
12+
update: db.prepare(
13+
"UPDATE docker_hosts SET hostAddress = ?, secure = ?, name = ? WHERE id = ?",
14+
),
15+
delete: db.prepare("DELETE FROM docker_hosts WHERE id = ?"),
1616
};
1717

1818
export function addDockerHost(host: DockerHost) {
19-
return executeDbOperation(
20-
"Add Docker Host",
21-
() => stmt.insert.run(host.name, host.hostAddress, host.secure),
22-
() => {
23-
if (!host.name || !host.hostAddress)
24-
throw new Error("Missing required fields");
25-
if (typeof host.secure !== "boolean")
26-
throw new TypeError("Invalid secure type");
27-
}
28-
);
19+
return executeDbOperation(
20+
"Add Docker Host",
21+
() => stmt.insert.run(host.name, host.hostAddress, host.secure),
22+
() => {
23+
if (!host.name || !host.hostAddress)
24+
throw new Error("Missing required fields");
25+
if (typeof host.secure !== "boolean")
26+
throw new TypeError("Invalid secure type");
27+
},
28+
);
2929
}
3030

3131
export function getDockerHosts(): DockerHost[] {
32-
return executeDbOperation("Get Docker Hosts", () => {
33-
const rows = stmt.selectAll.all() as Array<
34-
Omit<DockerHost, "secure"> & { secure: number }
35-
>;
36-
return rows.map((row) => ({
37-
...row,
38-
secure: row.secure === 1,
39-
}));
40-
});
32+
return executeDbOperation("Get Docker Hosts", () => {
33+
const rows = stmt.selectAll.all() as Array<
34+
Omit<DockerHost, "secure"> & { secure: number }
35+
>;
36+
return rows.map((row) => ({
37+
...row,
38+
secure: row.secure === 1,
39+
}));
40+
});
4141
}
4242
1;
4343
export function updateDockerHost(host: DockerHost) {
44-
return executeDbOperation(
45-
"Update Docker Host",
46-
() => stmt.update.run(host.hostAddress, host.secure, host.name, host.id),
47-
() => {
48-
if (!host.id || typeof host.id !== "number")
49-
throw new Error("Invalid host ID");
50-
}
51-
);
44+
return executeDbOperation(
45+
"Update Docker Host",
46+
() => stmt.update.run(host.hostAddress, host.secure, host.name, host.id),
47+
() => {
48+
if (!host.id || typeof host.id !== "number")
49+
throw new Error("Invalid host ID");
50+
},
51+
);
5252
}
5353

5454
export function deleteDockerHost(id: number) {
55-
return executeDbOperation(
56-
"Delete Docker Host",
57-
() => stmt.delete.run(id),
58-
() => {
59-
if (typeof id !== "number") throw new TypeError("Invalid ID type");
60-
}
61-
);
55+
return executeDbOperation(
56+
"Delete Docker Host",
57+
() => stmt.delete.run(id),
58+
() => {
59+
if (typeof id !== "number") throw new TypeError("Invalid ID type");
60+
},
61+
);
6262
}

src/core/database/hostStats.ts

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,50 @@ const selectStmt = db.prepare(`
1616
`);
1717

1818
export function addHostStats(stats: HostStats) {
19-
return executeDbOperation(
20-
"Update Host Stats",
21-
() =>
22-
insert.run(
23-
stats.hostId,
24-
stats.hostName,
25-
stats.dockerVersion,
26-
stats.apiVersion,
27-
stats.os,
28-
stats.architecture,
29-
stats.totalMemory,
30-
stats.totalCPU,
31-
JSON.stringify(stats.labels),
32-
stats.containers,
33-
stats.containersRunning,
34-
stats.containersStopped,
35-
stats.containersPaused,
36-
stats.images
37-
),
38-
() => {
39-
if (
40-
typeof stats.hostId !== "number" ||
41-
typeof stats.hostName !== "string" ||
42-
typeof stats.dockerVersion !== "string" ||
43-
typeof stats.apiVersion !== "string" ||
44-
typeof stats.os !== "string" ||
45-
typeof stats.architecture !== "string" ||
46-
typeof stats.totalMemory !== "number" ||
47-
typeof stats.totalCPU !== "number" ||
48-
typeof JSON.stringify(stats.labels) !== "string" ||
49-
typeof stats.containers !== "number" ||
50-
typeof stats.containersRunning !== "number" ||
51-
typeof stats.containersStopped !== "number" ||
52-
typeof stats.containersPaused !== "number" ||
53-
typeof stats.images !== "number"
54-
) {
55-
throw new TypeError(`Invalid Host Stats! - ${stats}`);
56-
}
57-
}
58-
);
19+
return executeDbOperation(
20+
"Update Host Stats",
21+
() =>
22+
insert.run(
23+
stats.hostId,
24+
stats.hostName,
25+
stats.dockerVersion,
26+
stats.apiVersion,
27+
stats.os,
28+
stats.architecture,
29+
stats.totalMemory,
30+
stats.totalCPU,
31+
JSON.stringify(stats.labels),
32+
stats.containers,
33+
stats.containersRunning,
34+
stats.containersStopped,
35+
stats.containersPaused,
36+
stats.images,
37+
),
38+
() => {
39+
if (
40+
typeof stats.hostId !== "number" ||
41+
typeof stats.hostName !== "string" ||
42+
typeof stats.dockerVersion !== "string" ||
43+
typeof stats.apiVersion !== "string" ||
44+
typeof stats.os !== "string" ||
45+
typeof stats.architecture !== "string" ||
46+
typeof stats.totalMemory !== "number" ||
47+
typeof stats.totalCPU !== "number" ||
48+
typeof JSON.stringify(stats.labels) !== "string" ||
49+
typeof stats.containers !== "number" ||
50+
typeof stats.containersRunning !== "number" ||
51+
typeof stats.containersStopped !== "number" ||
52+
typeof stats.containersPaused !== "number" ||
53+
typeof stats.images !== "number"
54+
) {
55+
throw new TypeError(`Invalid Host Stats! - ${stats}`);
56+
}
57+
},
58+
);
5959
}
6060

6161
export function getHostStats(): HostStats[] {
62-
return executeDbOperation("Get Host Stats", () =>
63-
selectStmt.all()
64-
) as HostStats[];
62+
return executeDbOperation("Get Host Stats", () =>
63+
selectStmt.all(),
64+
) as HostStats[];
6565
}

0 commit comments

Comments
 (0)