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

Commit ea8693a

Browse files
committed
Fix: Linting (No more any :D)
1 parent 8e0967b commit ea8693a

31 files changed

Lines changed: 259 additions & 3064 deletions

src/config/db.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import logger from "../utils/logger";
33

44
const dbPath: string = "./src/data/database.db";
55

6-
const db: sqlite3.Database = new sqlite3.Database(dbPath, (error: any) => {
7-
if (error) {
8-
logger.error("Error opening database:", error.message);
6+
const db: sqlite3.Database = new sqlite3.Database(dbPath, (error: unknown) => {
7+
if (error as Error) {
8+
logger.error("Error opening database:", (error as Error).message);
99
} else {
1010
db.run(
1111
`CREATE TABLE IF NOT EXISTS data (

src/config/loggerConfig.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const red = "\x1b[31m";
77
const green = "\x1b[32m";
88
const yellow = "\x1b[33m";
99
const blue = "\x1b[34m";
10-
const pink = "\x1b[38;5;213m"; // Pink color for sync logs
1110

1211
const ignoreExitListenerLogs = format((info) => {
1312
if (

src/config/swaggerConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const options: {
1818
};
1919
};
2020
security: Array<{
21-
passwordAuth: any[];
21+
passwordAuth: unknown[];
2222
}>;
2323
};
2424
apis: string[];

src/controllers/containerController.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ const getContainers = async (req: Request, res: Response): Promise<void> => {
1010
const containers = await docker.listContainers();
1111

1212
res.status(200).json(containers);
13-
} catch (error: any) {
13+
} catch (error: unknown) {
1414
logger.error(
15-
`Error fetching containers from host: ${host} - ${error.message || "Unknown error"} - Full error: ${JSON.stringify(error, null, 2)}`,
15+
`Error fetching containers from host: ${host} - ${(error as Error).message || "Unknown error"} - Full error: ${JSON.stringify(error, null, 2)}`,
1616
);
1717
res.status(500).json({
18-
error: `Error fetching containers: ${error.message || "Unknown error"}`,
18+
error: `Error fetching containers: ${(error as Error).message || "Unknown error"}`,
1919
});
2020
}
2121
};
@@ -36,13 +36,15 @@ const getContainerStats = async (
3636
`Successfully fetched stats for container: ${containerID} from host: ${containerHost}`,
3737
);
3838
res.status(200).json(stats);
39-
} catch (error: any) {
39+
} catch (error: unknown) {
4040
logger.error(
41-
`Error fetching stats for container: ${containerID} from host: ${containerHost} - ${error.message}`,
41+
`Error fetching stats for container: ${containerID} from host: ${containerHost} - ${(error as Error).message}`,
4242
);
4343
res
4444
.status(500)
45-
.json({ error: `Error fetching container stats: ${error.message}` });
45+
.json({
46+
error: `Error fetching container stats: ${(error as Error).message}`,
47+
});
4648
}
4749
};
4850

src/controllers/fetchData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ const fetchData = async (): Promise<void> => {
6666
} else {
6767
logger.info("No state change detected, notifications not triggered.");
6868
}
69-
} catch (error: any) {
69+
} catch (error: unknown) {
7070
logger.error(
71-
`Error fetching data: ${JSON.stringify(error)} \nStack trace: ${error.stack}`,
71+
`Error fetching data: ${JSON.stringify(error)} \nStack trace: ${(error as Error).stack}`,
7272
);
7373
}
7474
};

src/controllers/frontendConfiguration.ts

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ const dataPath: string = "./src/data/frontendConfiguration.json";
44
const expression: string =
55
"https?://(www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}([-a-zA-Z0-9()@:%_+.~#?&//=]*)";
66
const regex = new RegExp(expression);
7+
import { FrontendConfig } from "../typings/frontendConfig";
78

89
///////////////////////////////////////////////////////////////
910
// Hide Containers:
1011
async function hideContainer(containerName: string) {
1112
try {
1213
const data = await readData();
1314
const containerIndex = data.findIndex(
14-
(container: any) => container.name === containerName,
15+
(container) => container.name === containerName,
1516
);
1617

1718
if (containerIndex !== -1) {
@@ -21,27 +22,27 @@ async function hideContainer(containerName: string) {
2122
data.push({ name: containerName, hidden: true });
2223
await saveData(data);
2324
}
24-
} catch (error: any) {
25-
logger.error(error);
26-
throw new Error(error);
25+
} catch (error: unknown) {
26+
logger.error(error as Error);
27+
throw new Error(error as string);
2728
}
2829
}
2930

3031
async function unhideContainer(containerName: string) {
3132
try {
3233
const data = await readData();
3334
const containerIndex = data.findIndex(
34-
(container: any) => container.name === containerName,
35+
(container) => container.name === containerName,
3536
);
3637

3738
if (containerIndex !== -1) {
3839
delete data[containerIndex].hidden;
3940
await saveData(data);
4041
cleanupData();
4142
}
42-
} catch (error: any) {
43-
logger.error(error);
44-
throw new Error(error);
43+
} catch (error: unknown) {
44+
logger.error(error as Error);
45+
throw new Error(error as string);
4546
}
4647
}
4748

@@ -51,7 +52,7 @@ async function addTagToContainer(containerName: string, tag: string) {
5152
try {
5253
const data = await readData();
5354
const containerIndex = data.findIndex(
54-
(container: any) => container.name === containerName,
55+
(container) => container.name === containerName,
5556
);
5657

5758
if (containerIndex !== -1) {
@@ -64,39 +65,39 @@ async function addTagToContainer(containerName: string, tag: string) {
6465
data.push({ name: containerName, tags: [tag] });
6566
await saveData(data);
6667
}
67-
} catch (error: any) {
68-
logger.error(error);
69-
throw new Error(error);
68+
} catch (error: unknown) {
69+
logger.error(error as Error);
70+
throw new Error(error as string);
7071
}
7172
}
7273

7374
async function removeTagFromContainer(containerName: string, tag: string) {
7475
try {
7576
const data = await readData();
7677
const containerIndex = data.findIndex(
77-
(container: any) => container.name === containerName,
78+
(container) => container.name === containerName,
7879
);
7980

8081
if (containerIndex !== -1 && data[containerIndex].tags) {
8182
data[containerIndex].tags = data[containerIndex].tags.filter(
82-
(t: any) => t !== tag,
83+
(t) => t !== tag,
8384
);
8485
await saveData(data);
8586
cleanupData();
8687
}
87-
} catch (error: any) {
88+
} catch (error: unknown) {
8889
logger.error(error);
89-
throw new Error(error);
90+
throw new Error(error as string);
9091
}
9192
}
9293

9394
///////////////////////////////////////////////////////////////
9495
// Pin containers
9596
async function pinContainer(containerName: string) {
9697
try {
97-
const data: any = await readData();
98-
const containerIndex: number = data.findIndex(
99-
(container: any) => container.name === containerName,
98+
const data = await readData();
99+
const containerIndex = data.findIndex(
100+
(container) => container.name === containerName,
100101
);
101102

102103
if (containerIndex !== -1) {
@@ -106,27 +107,27 @@ async function pinContainer(containerName: string) {
106107
data.push({ name: containerName, pinned: true });
107108
await saveData(data);
108109
}
109-
} catch (error: any) {
110-
logger.error(error);
111-
throw new Error(error);
110+
} catch (error: unknown) {
111+
logger.error(error as Error);
112+
throw new Error(error as string);
112113
}
113114
}
114115

115116
async function unpinContainer(containerName: string) {
116117
try {
117118
const data = await readData();
118119
const containerIndex = data.findIndex(
119-
(container: any) => container.name === containerName,
120+
(container) => container.name === containerName,
120121
);
121122

122123
if (containerIndex !== -1) {
123124
delete data[containerIndex].pinned;
124125
await saveData(data);
125126
cleanupData();
126127
}
127-
} catch (error: any) {
128-
logger.error(error);
129-
throw new Error(error);
128+
} catch (error: unknown) {
129+
logger.error(error as Error);
130+
throw new Error(error as string);
130131
}
131132
}
132133

@@ -135,9 +136,9 @@ async function unpinContainer(containerName: string) {
135136
async function setLink(containerName: string, link: string) {
136137
if (link.match(regex)) {
137138
try {
138-
const data: any = await readData();
139-
const containerIndex: any = data.findIndex(
140-
(container: any) => container.name === containerName,
139+
const data = await readData();
140+
const containerIndex = data.findIndex(
141+
(container) => container.name === containerName,
141142
);
142143

143144
if (containerIndex !== -1) {
@@ -147,9 +148,9 @@ async function setLink(containerName: string, link: string) {
147148
data.push({ name: containerName, link: `${link}` });
148149
await saveData(data);
149150
}
150-
} catch (error: any) {
151+
} catch (error: unknown) {
151152
logger.error(error);
152-
throw new Error(error);
153+
throw new Error(error as string);
153154
}
154155
} else {
155156
logger.error(`Provided link is not valid: ${link}`);
@@ -161,17 +162,17 @@ async function removeLink(containerName: string) {
161162
try {
162163
const data = await readData();
163164
const containerIndex = data.findIndex(
164-
(container: any) => container.name === containerName,
165+
(container) => container.name === containerName,
165166
);
166167

167168
if (containerIndex !== -1) {
168169
delete data[containerIndex].link;
169170
await saveData(data);
170171
cleanupData();
171172
}
172-
} catch (error: any) {
173-
logger.error(error);
174-
throw new Error(error);
173+
} catch (error: unknown) {
174+
logger.error(error as Error);
175+
throw new Error(error as string);
175176
}
176177
}
177178

@@ -181,7 +182,7 @@ async function setIcon(containerName: string, icon: string, custom: boolean) {
181182
try {
182183
const data = await readData();
183184
const containerIndex: number = data.findIndex(
184-
(container: any) => container.name === containerName,
185+
(container) => container.name === containerName,
185186
);
186187

187188
if (custom === true) {
@@ -199,39 +200,41 @@ async function setIcon(containerName: string, icon: string, custom: boolean) {
199200
data.push({ name: containerName, icon: `${icon}` });
200201
await saveData(data);
201202
}
202-
} catch (error: any) {
203-
logger.error(error);
204-
throw new Error(error);
203+
} catch (error: unknown) {
204+
logger.error(error as Error);
205+
throw new Error(error as string);
205206
}
206207
}
207208

208209
async function removeIcon(containerName: string) {
209210
try {
210211
const data = await readData();
211212
const containerIndex = data.findIndex(
212-
(container: any) => container.name === containerName,
213+
(container) => container.name === containerName,
213214
);
214215

215216
if (containerIndex !== -1) {
216217
delete data[containerIndex].icon;
217218
await saveData(data);
218219
cleanupData();
219220
}
220-
} catch (error: any) {
221-
logger.error(error);
222-
throw new Error(error);
221+
} catch (error: unknown) {
222+
logger.error(error as Error);
223+
throw new Error(error as string);
223224
}
224225
}
225226

226227
///////////////////////////////////////////////////////////////
227228
// Data specific functionss
228229
async function readData() {
229230
try {
230-
const data = await fs.promises.readFile(dataPath, "utf-8");
231-
return JSON.parse(data);
232-
} catch (error: any) {
233-
console.error("readData");
234-
if (error.code === "ENOENT") {
231+
const data: FrontendConfig = JSON.parse(
232+
await fs.promises.readFile(dataPath, "utf-8"),
233+
);
234+
return data;
235+
} catch (error: unknown) {
236+
console.error(`Error while reading ${dataPath}: ${error as Error}`);
237+
if (error as Error) {
235238
await saveData([]);
236239
return [];
237240
} else {
@@ -240,23 +243,23 @@ async function readData() {
240243
}
241244
}
242245

243-
async function saveData(data: any) {
246+
async function saveData(data: FrontendConfig) {
244247
try {
245248
await fs.promises.writeFile(
246249
dataPath,
247250
JSON.stringify(data, null, 2),
248251
"utf-8",
249252
);
250253
logger.info("Succesfully wrote to file");
251-
} catch (error: any) {
252-
logger.error(error);
254+
} catch (error: unknown) {
255+
logger.error(error as Error);
253256
}
254257
}
255258

256259
async function cleanupData() {
257260
try {
258261
const data = await readData();
259-
let cleanedData = [];
262+
let cleanedData: FrontendConfig = [];
260263

261264
if (data && Array.isArray(data)) {
262265
cleanedData = data.filter((container) => {
@@ -273,8 +276,8 @@ async function cleanupData() {
273276
}
274277

275278
await saveData(cleanedData);
276-
} catch (error: any) {
277-
logger.error(error);
279+
} catch (error: unknown) {
280+
logger.error(error as Error);
278281
}
279282
}
280283

src/controllers/highAvailability.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ async function readConfig(): Promise<HighAvailabilityConfig | null> {
102102
fs.readFileSync(haMasterPath, "utf-8"),
103103
);
104104
return data;
105-
} catch (error: any) {
105+
} catch (error: unknown) {
106106
logger.error(`Error reading HA-Config: ${(error as Error).message}`);
107107
return null;
108108
} finally {

src/controllers/notificationController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ async function sendNotification(containerId: string) {
5656
notify("whatsapp", containerId);
5757
}
5858
}
59+
60+
export default sendNotification;

0 commit comments

Comments
 (0)