Skip to content

Commit 5497e66

Browse files
fix: Resolve all build errors and warnings
- Fix nullish coalescing operator warnings (|| to ??) - Remove unused imports and variables - Fix TypeScript type errors with proper casting - Update ConfirmationModal state type to include missing properties - Fix useEffect dependency warnings - All build errors resolved, only minor unused variable warning remains - Build now passes successfully
1 parent d9e071b commit 5497e66

File tree

2 files changed

+17
-107
lines changed

2 files changed

+17
-107
lines changed

src/app/_components/InstalledScriptsTab.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export function InstalledScriptsTab() {
5353
title: string;
5454
message: string;
5555
confirmText?: string;
56+
confirmButtonText?: string;
57+
cancelButtonText?: string;
5658
onConfirm: () => void;
5759
} | null>(null);
5860
const [controllingScriptId, setControllingScriptId] = useState<number | null>(null);
@@ -227,7 +229,7 @@ export function InstalledScriptsTab() {
227229
setErrorModal({
228230
isOpen: true,
229231
title: `Container ${variables.action === 'start' ? 'Started' : 'Stopped'}`,
230-
message: data.message || `Container has been ${variables.action === 'start' ? 'started' : 'stopped'} successfully.`,
232+
message: data.message ?? `Container has been ${variables.action === 'start' ? 'started' : 'stopped'} successfully.`,
231233
details: undefined,
232234
type: 'success'
233235
});
@@ -236,7 +238,7 @@ export function InstalledScriptsTab() {
236238
fetchContainerStatuses();
237239
} else {
238240
// Show error message from backend
239-
const errorMessage = data.error || 'Unknown error occurred';
241+
const errorMessage = data.error ?? 'Unknown error occurred';
240242
setErrorModal({
241243
isOpen: true,
242244
title: 'Container Control Failed',
@@ -250,7 +252,7 @@ export function InstalledScriptsTab() {
250252
setControllingScriptId(null);
251253

252254
// Show detailed error message
253-
const errorMessage = error.message || 'Unknown error occurred';
255+
const errorMessage = error.message ?? 'Unknown error occurred';
254256
setErrorModal({
255257
isOpen: true,
256258
title: 'Container Control Failed',
@@ -269,13 +271,13 @@ export function InstalledScriptsTab() {
269271
setErrorModal({
270272
isOpen: true,
271273
title: 'Container Destroyed',
272-
message: data.message || 'The container has been successfully destroyed and removed from the database.',
274+
message: data.message ?? 'The container has been successfully destroyed and removed from the database.',
273275
details: undefined,
274276
type: 'success'
275277
});
276278
} else {
277279
// Show error message from backend
278-
const errorMessage = data.error || 'Unknown error occurred';
280+
const errorMessage = data.error ?? 'Unknown error occurred';
279281
setErrorModal({
280282
isOpen: true,
281283
title: 'Container Destroy Failed',
@@ -289,7 +291,7 @@ export function InstalledScriptsTab() {
289291
setControllingScriptId(null);
290292

291293
// Show detailed error message
292-
const errorMessage = error.message || 'Unknown error occurred';
294+
const errorMessage = error.message ?? 'Unknown error occurred';
293295
setErrorModal({
294296
isOpen: true,
295297
title: 'Container Destroy Failed',
@@ -339,7 +341,7 @@ export function InstalledScriptsTab() {
339341
if (scripts.length > 0) {
340342
fetchContainerStatuses();
341343
}
342-
}, []); // Empty dependency array means this runs once when component mounts
344+
}, [scripts.length, fetchContainerStatuses]); // Include dependencies
343345

344346
// Update scripts with container statuses
345347
const scriptsWithStatus = scripts.map(script => ({
@@ -1242,7 +1244,7 @@ export function InstalledScriptsTab() {
12421244
title={errorModal.title}
12431245
message={errorModal.message}
12441246
details={errorModal.details}
1245-
type={errorModal.type || 'error'}
1247+
type={errorModal.type ?? 'error'}
12461248
/>
12471249
)}
12481250
</div>

src/server/api/routers/installedScripts.ts

Lines changed: 7 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,8 @@
11
import { z } from "zod";
22
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
33
import { getDatabase } from "~/server/database";
4-
import { exec } from "child_process";
5-
import { promisify } from "util";
6-
import { getSSHExecutionService } from "~/server/ssh-execution-service";
7-
import type { Server } from "~/types/server";
8-
9-
const execAsync = promisify(exec);
10-
11-
// Helper function to check local container statuses
12-
async function getLocalContainerStatuses(containerIds: string[]): Promise<Record<string, 'running' | 'stopped' | 'unknown'>> {
13-
try {
14-
const { stdout } = await execAsync('pct list');
15-
const statusMap: Record<string, 'running' | 'stopped' | 'unknown'> = {};
16-
17-
// Parse pct list output
18-
const lines = stdout.trim().split('\n');
19-
const dataLines = lines.slice(1); // Skip header
20-
21-
for (const line of dataLines) {
22-
const parts = line.trim().split(/\s+/);
23-
if (parts.length >= 2) {
24-
const vmid = parts[0];
25-
const status = parts[1];
26-
27-
if (vmid && containerIds.includes(vmid)) {
28-
statusMap[vmid] = status === 'running' ? 'running' : 'stopped';
29-
}
30-
}
31-
}
32-
33-
// Set unknown for containers not found in pct list
34-
for (const containerId of containerIds) {
35-
if (!(containerId in statusMap)) {
36-
statusMap[containerId] = 'unknown';
37-
}
38-
}
39-
40-
return statusMap;
41-
} catch (error) {
42-
console.error('Error checking local container statuses:', error);
43-
// Return unknown for all containers on error
44-
const statusMap: Record<string, 'running' | 'stopped' | 'unknown'> = {};
45-
for (const containerId of containerIds) {
46-
statusMap[containerId] = 'unknown';
47-
}
48-
return statusMap;
49-
}
50-
}
51-
52-
// Helper function to check remote container statuses (multiple containers per server)
53-
async function getRemoteContainerStatuses(containerIds: string[], server: Server): Promise<Record<string, 'running' | 'stopped' | 'unknown'>> {
54-
return new Promise((resolve) => {
55-
const sshService = getSSHExecutionService();
56-
const statusMap: Record<string, 'running' | 'stopped' | 'unknown'> = {};
57-
58-
// Initialize all containers as unknown
59-
for (const containerId of containerIds) {
60-
statusMap[containerId] = 'unknown';
61-
}
62-
63-
void sshService.executeCommand(
64-
server,
65-
'pct list',
66-
(data: string) => {
67-
// Parse the output to find all containers
68-
const lines = data.trim().split('\n');
69-
const dataLines = lines.slice(1); // Skip header
70-
71-
for (const line of dataLines) {
72-
const parts = line.trim().split(/\s+/);
73-
if (parts.length >= 2) {
74-
const vmid = parts[0];
75-
const status = parts[1];
76-
77-
// Check if this is one of the containers we're looking for
78-
if (vmid && containerIds.includes(vmid)) {
79-
statusMap[vmid] = status === 'running' ? 'running' : 'stopped';
80-
}
81-
}
82-
}
83-
84-
resolve(statusMap);
85-
},
86-
(error: string) => {
87-
console.error(`Error checking remote containers on server ${server.name}:`, error);
88-
resolve(statusMap); // Return the map with unknown statuses
89-
},
90-
(exitCode: number) => {
91-
if (exitCode !== 0) {
92-
resolve(statusMap); // Return the map with unknown statuses
93-
}
94-
}
95-
);
96-
});
97-
}
4+
// Removed unused imports
5+
986

997
export const installedScriptsRouter = createTRPCRouter({
1008
// Get all installed scripts
@@ -357,7 +265,7 @@ export const installedScriptsRouter = createTRPCRouter({
357265
(error: string) => {
358266
console.error('Command error:', error);
359267
},
360-
(exitCode: number) => {
268+
(_exitCode: number) => {
361269

362270
// Parse the complete output to get config file paths that contain community-script tag
363271
const configFiles = commandOutput.split('\n')
@@ -401,7 +309,7 @@ export const installedScriptsRouter = createTRPCRouter({
401309
containerId,
402310
hostname,
403311
configPath,
404-
serverId: (server as any).id,
312+
serverId: Number((server as any).id),
405313
serverName: (server as any).name
406314
};
407315
readResolve(container);
@@ -624,7 +532,7 @@ export const installedScriptsRouter = createTRPCRouter({
624532

625533
// Determine which servers to check
626534
const serversToCheck = input.serverIds
627-
? allServers.filter(s => input.serverIds!.includes((s as any).id))
535+
? allServers.filter((s: any) => input.serverIds!.includes(Number(s.id)))
628536
: allServers;
629537

630538

@@ -963,7 +871,7 @@ export const installedScriptsRouter = createTRPCRouter({
963871
(error: string) => {
964872
reject(new Error(error));
965873
},
966-
(exitCode: number) => {
874+
(_exitCode: number) => {
967875
resolve();
968876
}
969877
);
@@ -998,7 +906,7 @@ export const installedScriptsRouter = createTRPCRouter({
998906
);
999907
});
1000908
}
1001-
} catch (error) {
909+
} catch (_error) {
1002910
// If status check fails, continue with destroy attempt
1003911
// The destroy command will handle the error appropriately
1004912
}

0 commit comments

Comments
 (0)