mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-14 02:47:00 +00:00
fixed code quality
This commit is contained in:
@@ -49,12 +49,12 @@ function init(server, prismaClient) {
|
|||||||
// Accept the WebSocket connection for Bull Board
|
// Accept the WebSocket connection for Bull Board
|
||||||
wss.handleUpgrade(request, socket, head, (ws) => {
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
||||||
ws.on("message", (message) => {
|
ws.on("message", (message) => {
|
||||||
// Echo back for Bull Board WebSocket
|
// Echo back for Bull Board WebSocket
|
||||||
try {
|
try {
|
||||||
ws.send(message);
|
ws.send(message);
|
||||||
} catch (err) {
|
} catch (_err) {
|
||||||
// Ignore send errors (connection may be closed)
|
// Ignore send errors (connection may be closed)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on("error", (err) => {
|
ws.on("error", (err) => {
|
||||||
@@ -160,9 +160,7 @@ function init(server, prismaClient) {
|
|||||||
err.message?.includes("read ECONNRESET")
|
err.message?.includes("read ECONNRESET")
|
||||||
) {
|
) {
|
||||||
// Connection reset errors are common and expected
|
// Connection reset errors are common and expected
|
||||||
console.log(
|
console.log(`[agent-ws] connection reset for ${apiId}`);
|
||||||
`[agent-ws] connection reset for ${apiId}`,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// Log other errors for debugging
|
// Log other errors for debugging
|
||||||
console.error(
|
console.error(
|
||||||
@@ -181,7 +179,10 @@ function init(server, prismaClient) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to close the connection gracefully if still open
|
// Try to close the connection gracefully if still open
|
||||||
if (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING) {
|
if (
|
||||||
|
ws.readyState === WebSocket.OPEN ||
|
||||||
|
ws.readyState === WebSocket.CONNECTING
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
ws.close(1000); // Normal closure
|
ws.close(1000); // Normal closure
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -30,24 +30,8 @@ function get_current_time() {
|
|||||||
|
|
||||||
// For other timezones, we need to create a date string with timezone info
|
// For other timezones, we need to create a date string with timezone info
|
||||||
// and parse it. This ensures the date represents the correct time in that timezone.
|
// and parse it. This ensures the date represents the correct time in that timezone.
|
||||||
const now = new Date();
|
|
||||||
const formatter = new Intl.DateTimeFormat("en-US", {
|
|
||||||
timeZone: tz,
|
|
||||||
year: "numeric",
|
|
||||||
month: "2-digit",
|
|
||||||
day: "2-digit",
|
|
||||||
hour: "2-digit",
|
|
||||||
minute: "2-digit",
|
|
||||||
second: "2-digit",
|
|
||||||
hour12: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const parts = formatter.formatToParts(now);
|
|
||||||
const date_str = `${parts.find((p) => p.type === "year").value}-${parts.find((p) => p.type === "month").value}-${parts.find((p) => p.type === "day").value}T${parts.find((p) => p.type === "hour").value}:${parts.find((p) => p.type === "minute").value}:${parts.find((p) => p.type === "second").value}`;
|
|
||||||
|
|
||||||
// Create date in UTC, then adjust to represent the same moment in the target timezone
|
|
||||||
// This is a bit tricky - we'll use a simpler approach: store as UTC but display in timezone
|
|
||||||
// For database storage, we always store UTC timestamps
|
// For database storage, we always store UTC timestamps
|
||||||
|
// The timezone is primarily used for display purposes
|
||||||
return new Date();
|
return new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +72,7 @@ function parse_date(date_string, fallback = null) {
|
|||||||
return fallback || get_current_time();
|
return fallback || get_current_time();
|
||||||
}
|
}
|
||||||
return date;
|
return date;
|
||||||
} catch (error) {
|
} catch (_error) {
|
||||||
return fallback || get_current_time();
|
return fallback || get_current_time();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,4 +105,3 @@ module.exports = {
|
|||||||
parse_date,
|
parse_date,
|
||||||
format_date_for_display,
|
format_date_for_display,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user