feat(KB-227): allow viewing binary files as read-only in file browser

- Remove binary file restrictions from file service backend

- Add visual read-only indicator for binary files in FileBrowserModal

- Add CSS styles for binary file indicators

- Update tests to expect binary files to be readable
This commit is contained in:
gsxdsm
2026-03-30 18:55:57 -07:00
parent a253bb56af
commit 99f99ca401
4 changed files with 43 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
import { useState, useCallback, useEffect } from "react";
import { X, Save, RotateCcw, Folder } from "lucide-react";
import { X, Save, RotateCcw, Folder, FileType } from "lucide-react";
import { useFileBrowser } from "../hooks/useFileBrowser";
import { useFileEditor } from "../hooks/useFileEditor";
import { useProjectFileBrowser } from "../hooks/useProjectFileBrowser";
@@ -7,6 +7,27 @@ import { useProjectFileEditor } from "../hooks/useProjectFileEditor";
import { FileBrowser } from "./FileBrowser";
import { FileEditor } from "./FileEditor";
/**
* Binary file extensions that should be displayed as read-only.
*/
const BINARY_EXTENSIONS = new Set([
".png", ".jpg", ".jpeg", ".gif", ".webp", ".ico", ".bmp", ".svgz",
".exe", ".dll", ".so", ".dylib",
".zip", ".tar", ".gz", ".bz2", ".xz", ".7z", ".rar",
".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx",
".mp3", ".mp4", ".avi", ".mov", ".webm", ".mkv", ".flv",
".woff", ".woff2", ".ttf", ".otf", ".eot",
".wasm", ".bin",
]);
/**
* Check if a file is a binary file based on extension.
*/
function isBinaryFile(filename: string): boolean {
const ext = filename.slice(filename.lastIndexOf(".")).toLowerCase();
return BINARY_EXTENSIONS.has(ext);
}
type TaskModeProps = {
taskId: string;
worktreePath?: string;
@@ -134,6 +155,12 @@ export function FileBrowserModal(props: FileBrowserModalProps) {
<div className="file-browser-toolbar">
<div className="file-browser-file-info">
{selectedFile}
{selectedFile && isBinaryFile(selectedFile) && (
<span className="file-browser-binary-indicator">
<FileType size={12} />
Binary file read only
</span>
)}
{mtime && (
<span className="file-browser-mtime">
Modified: {new Date(mtime).toLocaleString()}
@@ -176,6 +203,7 @@ export function FileBrowserModal(props: FileBrowserModalProps) {
content={content}
onChange={setContent}
filePath={selectedFile}
readOnly={selectedFile ? isBinaryFile(selectedFile) : false}
/>
</div>