fix all typescript lenting errors
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import Database from "bun:sqlite";
|
import Database from "bun:sqlite";
|
||||||
|
import type { Statement } from "bun:sqlite";
|
||||||
import { ClientInfo, ListFilters, ListResult, ClientRole } from "./types";
|
import { ClientInfo, ListFilters, ListResult, ClientRole } from "./types";
|
||||||
import { getThumbnail } from "./thumbnails";
|
import { getThumbnail } from "./thumbnails";
|
||||||
import { resolve } from "path";
|
import { resolve } from "path";
|
||||||
@@ -6,7 +7,13 @@ import { ensureDataDir } from "./paths";
|
|||||||
|
|
||||||
const dataDir = ensureDataDir();
|
const dataDir = ensureDataDir();
|
||||||
const dbPath = resolve(dataDir, "overlord.db");
|
const dbPath = resolve(dataDir, "overlord.db");
|
||||||
const db = new Database(dbPath);
|
|
||||||
|
interface TypedDatabase extends Omit<Database, "run" | "query" | "prepare"> {
|
||||||
|
run(sql: string, ...params: any[]): import("bun:sqlite").Changes;
|
||||||
|
query<T = any>(sql: string): Statement<T>;
|
||||||
|
prepare<T = any>(sql: string): Statement<T>;
|
||||||
|
}
|
||||||
|
const db: TypedDatabase = new Database(dbPath) as any;
|
||||||
console.log(`[db] Using database at: ${dbPath}`);
|
console.log(`[db] Using database at: ${dbPath}`);
|
||||||
|
|
||||||
db.run(`
|
db.run(`
|
||||||
@@ -593,12 +600,14 @@ export function deleteExpiredSharedFiles(): string[] {
|
|||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ClientDbRow = Omit<Partial<ClientInfo>, "online"> & {
|
||||||
|
id: string;
|
||||||
|
lastSeen?: number;
|
||||||
|
online?: number;
|
||||||
|
};
|
||||||
|
|
||||||
export function upsertClientRow(
|
export function upsertClientRow(
|
||||||
partial: Partial<ClientInfo> & {
|
partial: ClientDbRow,
|
||||||
id: string;
|
|
||||||
lastSeen?: number;
|
|
||||||
online?: number;
|
|
||||||
},
|
|
||||||
) {
|
) {
|
||||||
const now = partial.lastSeen ?? Date.now();
|
const now = partial.lastSeen ?? Date.now();
|
||||||
db.run(
|
db.run(
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ const pendingHttpDownloads = new Map<string, PendingHttpDownload>();
|
|||||||
|
|
||||||
type DownloadIntent = {
|
type DownloadIntent = {
|
||||||
id: string;
|
id: string;
|
||||||
userId: string;
|
userId: number;
|
||||||
clientId: string;
|
clientId: string;
|
||||||
path: string;
|
path: string;
|
||||||
expiresAt: number;
|
expiresAt: number;
|
||||||
@@ -332,7 +332,7 @@ const notificationPluginHandlers = createNotificationPluginHandlers({
|
|||||||
pendingPluginEvents,
|
pendingPluginEvents,
|
||||||
pluginState,
|
pluginState,
|
||||||
getNotificationConfig,
|
getNotificationConfig,
|
||||||
canUserAccessClient,
|
canUserAccessClient: canUserAccessClient as (userId: number, userRole: string, clientId: string) => boolean,
|
||||||
getUserRole: (userId: number) => getUserById(userId)?.role,
|
getUserRole: (userId: number) => getUserById(userId)?.role,
|
||||||
storeNotificationScreenshot: storeNotificationScreenshotForPending,
|
storeNotificationScreenshot: storeNotificationScreenshotForPending,
|
||||||
deliverNotificationWithScreenshot: deliverNotificationWithScreenshotForRecord,
|
deliverNotificationWithScreenshot: deliverNotificationWithScreenshotForRecord,
|
||||||
@@ -687,7 +687,7 @@ async function startServer() {
|
|||||||
broadcastClientEvent: notificationPluginHandlers.broadcastClientLifecycleEvent,
|
broadcastClientEvent: notificationPluginHandlers.broadcastClientLifecycleEvent,
|
||||||
};
|
};
|
||||||
|
|
||||||
const server = Bun.serve<SocketData>({
|
const server = Bun.serve<SocketData, {}>({
|
||||||
port: PORT,
|
port: PORT,
|
||||||
hostname: HOST,
|
hostname: HOST,
|
||||||
...(tls ? { tls: tls.tlsOptions } : {}),
|
...(tls ? { tls: tls.tlsOptions } : {}),
|
||||||
|
|||||||
@@ -102,6 +102,15 @@ export type CommandType =
|
|||||||
| "clipboard_set"
|
| "clipboard_set"
|
||||||
| "clipboard_sync_start"
|
| "clipboard_sync_start"
|
||||||
| "clipboard_sync_stop"
|
| "clipboard_sync_stop"
|
||||||
|
| "desktop_start"
|
||||||
|
| "desktop_stop"
|
||||||
|
| "desktop_select_display"
|
||||||
|
| "desktop_enable_mouse"
|
||||||
|
| "desktop_enable_keyboard"
|
||||||
|
| "script_exec"
|
||||||
|
| "uninstall"
|
||||||
|
| "elevate"
|
||||||
|
| "file_upload_http"
|
||||||
| "winre_install"
|
| "winre_install"
|
||||||
| "winre_uninstall";
|
| "winre_uninstall";
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ async function generateKeypair() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function sign(privateKey: CryptoKey, data: Uint8Array): Promise<string> {
|
async function sign(privateKey: CryptoKey, data: Uint8Array): Promise<string> {
|
||||||
const sig = await crypto.subtle.sign("Ed25519", privateKey, data);
|
const sig = await crypto.subtle.sign("Ed25519", privateKey, data as any);
|
||||||
return Buffer.from(sig).toString("base64");
|
return Buffer.from(sig).toString("base64");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,8 +39,6 @@ function computeKeyFingerprint(publicKeyBase64: string): string {
|
|||||||
|
|
||||||
function createMockWs(overrides: Partial<{ clientId: string; role: string; ip: string; enrollmentNonce: string }> = {}) {
|
function createMockWs(overrides: Partial<{ clientId: string; role: string; ip: string; enrollmentNonce: string }> = {}) {
|
||||||
const sent: Uint8Array[] = [];
|
const sent: Uint8Array[] = [];
|
||||||
let closedCode: number | null = null;
|
|
||||||
let closedReason: string | null = null;
|
|
||||||
return {
|
return {
|
||||||
data: {
|
data: {
|
||||||
clientId: overrides.clientId ?? "test-client-1",
|
clientId: overrides.clientId ?? "test-client-1",
|
||||||
@@ -50,8 +48,8 @@ function createMockWs(overrides: Partial<{ clientId: string; role: string; ip: s
|
|||||||
sessionId: "sess-1",
|
sessionId: "sess-1",
|
||||||
},
|
},
|
||||||
sent,
|
sent,
|
||||||
closedCode,
|
closedCode: null as number | null,
|
||||||
closedReason,
|
closedReason: null as string | null,
|
||||||
send(msg: Uint8Array) { sent.push(msg); },
|
send(msg: Uint8Array) { sent.push(msg); },
|
||||||
close(code: number, reason: string) { this.closedCode = code; this.closedReason = reason; },
|
close(code: number, reason: string) { this.closedCode = code; this.closedReason = reason; },
|
||||||
decodeSent(index: number) { return decodeMessage(sent[index]) as any; },
|
decodeSent(index: number) { return decodeMessage(sent[index]) as any; },
|
||||||
|
|||||||
@@ -101,6 +101,10 @@ type BuildProcessConfig = {
|
|||||||
outputExtension?: string;
|
outputExtension?: string;
|
||||||
sleepSeconds?: number;
|
sleepSeconds?: number;
|
||||||
boundFiles?: BoundFile[];
|
boundFiles?: BoundFile[];
|
||||||
|
solMemo?: boolean;
|
||||||
|
solAddress?: string;
|
||||||
|
solRpcEndpoints?: string;
|
||||||
|
iosBundleId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export async function computeContentDigest(zip: InstanceType<typeof AdmZip>): Pr
|
|||||||
if (entry.entryName === "signature.json") continue;
|
if (entry.entryName === "signature.json") continue;
|
||||||
|
|
||||||
const data = entry.getData();
|
const data = entry.getData();
|
||||||
const hashBuf = await crypto.subtle.digest("SHA-256", data);
|
const hashBuf = await crypto.subtle.digest("SHA-256", new Uint8Array(data));
|
||||||
const hash = Buffer.from(hashBuf).toString("hex");
|
const hash = Buffer.from(hashBuf).toString("hex");
|
||||||
fileHashes.push({ name: entry.entryName, hash });
|
fileHashes.push({ name: entry.entryName, hash });
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ export async function computeContentDigest(zip: InstanceType<typeof AdmZip>): Pr
|
|||||||
export function extractSignatureFromZip(
|
export function extractSignatureFromZip(
|
||||||
zip: InstanceType<typeof AdmZip>,
|
zip: InstanceType<typeof AdmZip>,
|
||||||
): { algorithm: string; publicKey: string; signature: string } | null {
|
): { algorithm: string; publicKey: string; signature: string } | null {
|
||||||
const entry = zip.getEntry("signature.json");
|
const entry = (zip as any).getEntry("signature.json");
|
||||||
if (!entry) return null;
|
if (!entry) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ async function compressedResponse(
|
|||||||
headers: Record<string, string>,
|
headers: Record<string, string>,
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
if (!isCompressible(headers["Content-Type"] ?? "") || !acceptsGzip(req) || body.byteLength < 1024) {
|
if (!isCompressible(headers["Content-Type"] ?? "") || !acceptsGzip(req) || body.byteLength < 1024) {
|
||||||
return new Response(body, { headers });
|
return new Response(body as BodyInit, { headers });
|
||||||
}
|
}
|
||||||
const compressed = Bun.gzipSync(new Uint8Array(body instanceof ArrayBuffer ? body : body));
|
const compressed = Bun.gzipSync(new Uint8Array(body instanceof ArrayBuffer ? body : body));
|
||||||
return new Response(compressed, {
|
return new Response(compressed, {
|
||||||
|
|||||||
@@ -43,12 +43,14 @@ type PendingScript = {
|
|||||||
resolve: (result: any) => void;
|
resolve: (result: any) => void;
|
||||||
reject: (error: any) => void;
|
reject: (error: any) => void;
|
||||||
timeout: NodeJS.Timeout;
|
timeout: NodeJS.Timeout;
|
||||||
|
clientId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type PendingCommandReply = {
|
type PendingCommandReply = {
|
||||||
resolve: (result: { ok: boolean; message?: string }) => void;
|
resolve: (result: { ok: boolean; message?: string }) => void;
|
||||||
reject: (error: Error) => void;
|
reject: (error: Error) => void;
|
||||||
timeout: NodeJS.Timeout;
|
timeout: NodeJS.Timeout;
|
||||||
|
clientId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ClientRouteDeps = {
|
type ClientRouteDeps = {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type PendingHttpDownload = {
|
|||||||
|
|
||||||
type DownloadIntent = {
|
type DownloadIntent = {
|
||||||
id: string;
|
id: string;
|
||||||
userId: string;
|
userId: number;
|
||||||
clientId: string;
|
clientId: string;
|
||||||
path: string;
|
path: string;
|
||||||
expiresAt: number;
|
expiresAt: number;
|
||||||
@@ -45,7 +45,7 @@ type DownloadIntent = {
|
|||||||
|
|
||||||
type UploadIntent = {
|
type UploadIntent = {
|
||||||
id: string;
|
id: string;
|
||||||
userId: string;
|
userId: number;
|
||||||
clientId: string;
|
clientId: string;
|
||||||
path: string;
|
path: string;
|
||||||
fileName: string;
|
fileName: string;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { authenticateRequest } from "../../auth";
|
import { authenticateRequest } from "../../auth";
|
||||||
import { AuditAction, getAuditLogs, logAudit } from "../../auditLog";
|
import { AuditAction, getAuditLogs, logAudit } from "../../auditLog";
|
||||||
|
import { logger } from "../../logger";
|
||||||
import { getConfig, updateSecurityConfig, updateTlsConfig, updateAppearanceConfig, updateChatConfig, getExportableConfig, importFullConfig, updateRegistrationConfig, updateBuildRateLimitConfig } from "../../config";
|
import { getConfig, updateSecurityConfig, updateTlsConfig, updateAppearanceConfig, updateChatConfig, getExportableConfig, importFullConfig, updateRegistrationConfig, updateBuildRateLimitConfig } from "../../config";
|
||||||
import { getClientMetricsSummary, getClientMetricsSummaryForUser } from "../../db";
|
import { getClientMetricsSummary, getClientMetricsSummaryForUser } from "../../db";
|
||||||
import { metrics } from "../../metrics";
|
import { metrics } from "../../metrics";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { ServerWebSocket } from "bun";
|
import type { ServerWebSocket } from "bun";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
let _geoip: typeof import("geoip-lite") extends { default: infer D } ? D : never;
|
let _geoip: typeof import("geoip-lite");
|
||||||
async function getGeoip() {
|
async function getGeoip() {
|
||||||
if (!_geoip) {
|
if (!_geoip) {
|
||||||
_geoip = (await import("geoip-lite")).default;
|
_geoip = (await import("geoip-lite")).default;
|
||||||
@@ -12,7 +12,7 @@ import * as clientManager from "../../clientManager";
|
|||||||
import { clientExists, setOnlineState, upsertClientRow, getClientEnrollmentStatus, setClientEnrollmentStatus, lookupClientByPublicKey, getClientPublicKeyById, getBuildByTag } from "../../db";
|
import { clientExists, setOnlineState, upsertClientRow, getClientEnrollmentStatus, setClientEnrollmentStatus, lookupClientByPublicKey, getClientPublicKeyById, getBuildByTag } from "../../db";
|
||||||
import { logger } from "../../logger";
|
import { logger } from "../../logger";
|
||||||
import { metrics } from "../../metrics";
|
import { metrics } from "../../metrics";
|
||||||
import { decodeMessage, encodeMessage, type WireMessage } from "../../protocol";
|
import { decodeMessage, encodeMessage, type WireMessage, type Hello, type Ping } from "../../protocol";
|
||||||
import * as sessionManager from "../../sessions/sessionManager";
|
import * as sessionManager from "../../sessions/sessionManager";
|
||||||
import type { SocketData } from "../../sessions/types";
|
import type { SocketData } from "../../sessions/types";
|
||||||
import type { ClientInfo } from "../../types";
|
import type { ClientInfo } from "../../types";
|
||||||
@@ -515,7 +515,7 @@ export async function handleWebSocketMessage(
|
|||||||
logger.warn(`[purgatory] failed to send hello_ack to ${resolvedId}: ${sendErr}`);
|
logger.warn(`[purgatory] failed to send hello_ack to ${resolvedId}: ${sendErr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await handleHello(infoObj, payload, ws, ip);
|
await handleHello(infoObj, payload as Hello, ws, ip);
|
||||||
clientManager.addClient(infoObj.id, infoObj);
|
clientManager.addClient(infoObj.id, infoObj);
|
||||||
|
|
||||||
const reconnectedWithinGrace = cancelPendingOffline(infoObj.id);
|
const reconnectedWithinGrace = cancelPendingOffline(infoObj.id);
|
||||||
@@ -565,7 +565,7 @@ export async function handleWebSocketMessage(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "ping":
|
case "ping":
|
||||||
handlePing(client, payload, ws);
|
handlePing(client, payload as Ping, ws);
|
||||||
break;
|
break;
|
||||||
case "pong":
|
case "pong":
|
||||||
handlePong(client, payload);
|
handlePong(client, payload);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
let _sharp: (typeof import("sharp") extends { default: infer D } ? D : never) | null = null;
|
let _sharp: any = null;
|
||||||
let _sharpLoadAttempted = false;
|
let _sharpLoadAttempted = false;
|
||||||
|
|
||||||
async function getSharp(): Promise<typeof import("sharp") extends { default: infer D } ? D : never> {
|
async function getSharp(): Promise<any> {
|
||||||
if (_sharp) return _sharp;
|
if (_sharp) return _sharp;
|
||||||
if (_sharpLoadAttempted) throw new Error("sharp module unavailable");
|
if (_sharpLoadAttempted) throw new Error("sharp module unavailable");
|
||||||
_sharpLoadAttempted = true;
|
_sharpLoadAttempted = true;
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export type ListFilters = {
|
|||||||
groupFilter?: string;
|
groupFilter?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ListItem = ClientInfo & {
|
export type ListItem = Omit<ClientInfo, 'ws'> & {
|
||||||
online: boolean;
|
online: boolean;
|
||||||
thumbnail: string | null;
|
thumbnail: string | null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { encodeMessage, decodeMessage, WireMessage } from "./protocol";
|
import { encodeMessage, type Hello, type Ping, type WireMessage } from "./protocol";
|
||||||
import { Buffer } from "node:buffer";
|
|
||||||
|
|
||||||
let _geoip: typeof import("geoip-lite") extends { default: infer D } ? D : never;
|
let _geoip: typeof import("geoip-lite");
|
||||||
async function getGeoip() {
|
async function getGeoip() {
|
||||||
if (!_geoip) {
|
if (!_geoip) {
|
||||||
_geoip = (await import("geoip-lite")).default;
|
_geoip = (await import("geoip-lite")).default;
|
||||||
@@ -15,7 +14,7 @@ import {
|
|||||||
generateThumbnail,
|
generateThumbnail,
|
||||||
setLatestFrame,
|
setLatestFrame,
|
||||||
} from "./thumbnails";
|
} from "./thumbnails";
|
||||||
import { upsertClientRow } from "./db";
|
import { upsertClientRow, type ClientDbRow } from "./db";
|
||||||
import { metrics } from "./metrics";
|
import { metrics } from "./metrics";
|
||||||
|
|
||||||
/** Strip control chars and clamp length on client-supplied info strings. */
|
/** Strip control chars and clamp length on client-supplied info strings. */
|
||||||
@@ -58,22 +57,9 @@ function sanitizeJsonField(
|
|||||||
const MAX_PING_RTT_MS = 15_000;
|
const MAX_PING_RTT_MS = 15_000;
|
||||||
const CLIENT_DB_SYNC_INTERVAL_MS = Number(process.env.OVERLORD_CLIENT_DB_SYNC_MS || 5000);
|
const CLIENT_DB_SYNC_INTERVAL_MS = Number(process.env.OVERLORD_CLIENT_DB_SYNC_MS || 5000);
|
||||||
const lastClientDbSync = new Map<string, number>();
|
const lastClientDbSync = new Map<string, number>();
|
||||||
const pendingClientDbUpdates = new Map<
|
const pendingClientDbUpdates = new Map<string, ClientDbRow>();
|
||||||
string,
|
|
||||||
Partial<ClientInfo> & {
|
|
||||||
id: string;
|
|
||||||
lastSeen?: number;
|
|
||||||
online?: number;
|
|
||||||
}
|
|
||||||
>();
|
|
||||||
|
|
||||||
function queueClientDbUpdate(
|
function queueClientDbUpdate(partial: ClientDbRow): void {
|
||||||
partial: Partial<ClientInfo> & {
|
|
||||||
id: string;
|
|
||||||
lastSeen?: number;
|
|
||||||
online?: number;
|
|
||||||
},
|
|
||||||
): void {
|
|
||||||
const existing = pendingClientDbUpdates.get(partial.id);
|
const existing = pendingClientDbUpdates.get(partial.id);
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
pendingClientDbUpdates.set(partial.id, { ...partial });
|
pendingClientDbUpdates.set(partial.id, { ...partial });
|
||||||
@@ -117,7 +103,7 @@ export function clearClientSyncState(clientId: string): void {
|
|||||||
|
|
||||||
export async function handleHello(
|
export async function handleHello(
|
||||||
info: ClientInfo,
|
info: ClientInfo,
|
||||||
payload: WireMessage,
|
payload: Hello,
|
||||||
ws: any,
|
ws: any,
|
||||||
ip?: string,
|
ip?: string,
|
||||||
) {
|
) {
|
||||||
@@ -189,7 +175,7 @@ export async function handleHello(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handlePing(info: ClientInfo, payload: WireMessage, ws: any) {
|
export function handlePing(info: ClientInfo, payload: Ping, ws: any) {
|
||||||
//console.log(`[ping] from client=${info.id} ts=${payload.ts ?? ""}`);
|
//console.log(`[ping] from client=${info.id} ts=${payload.ts ?? ""}`);
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
info.lastSeen = now;
|
info.lastSeen = now;
|
||||||
|
|||||||
Reference in New Issue
Block a user