homeio
PublicForked from doctor-io/homeio
files.md
File Manager
Purpose
The file manager browses FILES_ROOT, reads and writes text files, streams uploads/downloads, extracts archives, creates folders, copies/moves/renames entries, manages stars and trash, mounts SMB shares, exports local folders, shows USB drives, and integrates Google Drive accounts.
Locations
- Server-side:
lib/server/modules/files/ - Client-side:
modules/files/ - Routes:
app/api/v1/files/
Key Files
| File | Role |
|---|---|
lib/server/modules/files/service.ts | Main filesystem service and FileServiceError |
lib/server/modules/files/path-resolver.ts | resolvePathWithinFilesRoot() path jail |
lib/server/modules/files/trash-service.ts | Trash move/restore/delete |
lib/server/modules/files/network-storage.ts | SMB mount/discovery |
lib/server/modules/files/local-sharing.ts | Local folder sharing |
lib/server/modules/files/usb-storage.ts | USB drive list/mount/unmount/eject |
lib/server/modules/files/google-drive.ts | Google Drive token/connections |
lib/server/modules/files/google-drive-api.ts | Google Drive file API operations |
lib/server/modules/files/google-oauth-config.ts | Google OAuth client credential settings |
services/upload-server/main.go | Bare-metal upload sidecar for direct-to-disk uploads |
modules/files/components/manager/file-manager.tsx | Main file manager container |
modules/files/components/panels/google-drive-panel.tsx | Google Drive browser panel |
modules/files/components/dialogs/file-manager-dialogs.tsx | File manager modal dialogs, including upload progress |
modules/files/components/manager/file-manager-state.ts | Reducer state shape |
modules/files/hooks/files-api.ts | Fetch/XHR helpers, including abortable upload |
modules/files/hooks/useFiles.ts | Main file query/mutation hook |
Public API
- Server:
listDirectory(),readFileForViewer(),writeTextFile(),uploadFiles(),pasteEntry(),renameEntry(),toggleStarEntry(),searchFiles(),unzipEntry() - Client hooks:
useFiles(),useNetworkShares(),useLocalFolderShares(),useTrashActions(),useUsbDrives(),useGoogleDrive(),useGoogleDriveFiles(),useUnzipFile() - Components:
FileManager,FileManagerSidebar,FileManagerToolbar,FileManagerView
Contracts
lib/shared/contracts/files.tslib/shared/contracts/usb.tslib/shared/contracts/google-drive.ts
Database Tables
files_network_sharesfiles_local_sharesfiles_google_drive_tokensfiles_trash_entries
API Routes Owned
GET /api/v1/filesGET /api/v1/files/rootGET/PUT /api/v1/files/contentGET /api/v1/files/assetGET /api/v1/files/downloadPOST /api/v1/files/uploadPOST /api/v1/files/opsGET /api/v1/files/searchGET /api/v1/files/starredGET /api/v1/files/zipPOST /api/v1/files/trash/*GET/POST/DELETE /api/v1/files/network/shares*GET/POST /api/v1/files/network/discover/*GET/POST/DELETE /api/v1/files/shared/folders*GET /api/v1/files/usbGET /api/v1/files/usb/streamPOST /api/v1/files/usb/[driveId]/mount|unmount|ejectGET/POST/PATCH/DELETE /api/v1/files/google-drive/*GET/PUT/DELETE /api/v1/settings/google-oauth
Known Issues
lib/server/modules/files/service.tsis very large.modules/files/components/manager/file-manager-state.tshas a large state shape.- The audit found
getCurrentEntries()infile-manager-derived.tsusingunknown[]parameters. - File routes are protected by
requireApiSession(); path jailing remains the main filesystem safety control. - Large uploads are stream-parsed by the Next route with
busboy; bare-metal installs also build the Go upload sidecar atservices/upload-server/main.go. - Large uploads still depend on
next.config.mjsexperimental.proxyClientMaxBodySize: "10gb"and any external reverse-proxy body-size limits. - Upload progress is shown in
UploadProgressDialog; closing the dialog cancels the active XHR through anAbortController. - Google Drive needs Settings → Integrations OAuth credentials before the connect flow can start.
How To Extend
To add a new file operation:
- Add request/response types in
lib/shared/contracts/files.ts. - Add server logic to
lib/server/modules/files/service.tsor a focused file inlib/server/modules/files/. - Use
resolvePathWithinFilesRoot()for any host path. - Add a route under
app/api/v1/files/. - Add query/mutation support in
modules/files/hooks/files-api.tsanduseFiles.ts. - Wire UI in
modules/files/components/manager/ormodules/files/components/dialogs/. - For upload changes, preserve
AbortSignalcancellation inuploadFilesToPath()and avoid reintroducing full-body buffering. - For Google Drive changes, update
lib/shared/contracts/google-drive.ts, query keys, and the Drive panel/hooks together. - Add server and route tests.