Title: feat(api): expand the public v2 files surface by TheodoreSpeaks · Pull Request #6160 · simstudioai/sim · GitHub
Open Graph Title: feat(api): expand the public v2 files surface by TheodoreSpeaks · Pull Request #6160 · simstudioai/sim
X Title: feat(api): expand the public v2 files surface by TheodoreSpeaks · Pull Request #6160 · simstudioai/sim
Description: Summary Expands /api/v2/files from list + upload + download + archive-one to cover what the internal files surface does: folders, rename, restore, move, bulk archive, share, and content replace v2FileSchema gains folderId / folderPath / updatedAt, the list gains scope=active|archived (Recently Deleted was unreachable, which made the restore endpoints useless), and upload gains folderId No folder-management routes. Files are folder-aware (folderId / folderPath on the projection, folderId on upload, and POST /api/v2/files/move) but this PR publishes no folder CRUD. File folders already live in the shared folder table as resourceType: 'file' (#6045 cut them over, #6051 dropped workspace_file_folders), and the remaining file-specific folder machinery is being folded into the generic folder engine — publishing /api/v2/files/folders/** would pin that transitional split into a public contract. A folder id is a folder.id and survives the unification, so the file-side fields are safe; folder management belongs on /api/v2/folders once it serves resourceType: 'file' Share and content replace had real logic sitting in the session routes, so it moved into lib/workspace-files/orchestration/ first (performUpsertWorkspaceFileShare, performGetWorkspaceFileShare, performUpdateWorkspaceFileContent) and the internal routes now call it — one implementation, not a parallel one WorkspaceFilesOrchestrationErrorCode was a narrower private copy of the shared OrchestrationErrorCode; reconciled onto the shared union so every route uses v2ErrorForOrchestration and the hand-rolled status switch in files/[fileId]/route.ts is gone Extracted the file projection that was inlined twice into app/api/v2/files/utils.ts (toV2File, toV2FileFolder) OpenAPI: 7 new operations in openapi-v2-files-audit.json, all under the existing Files tag — no new sidebar entries Two deliberate departures from the internal surface: Presigned upload is not exposed. Presign only does an advisory quota pre-check; the storage debit happens in the separate /register step, so presign → PUT bytes → never register leaves unaccounted bytes in the bucket with no orphan reaper. The buffered multipart path debits inside uploadWorkspaceFile's own transaction, so it's the only public path. Share drops the caller-supplied token. It exists so the UI can copy a link before saving; over an API key it lets a caller mint predictable public URLs (any string ≥16 chars, no entropy check) and a collision surfaces as an unhandled unique-index 500. v2 tokens are always server-generated. The OpenAPI description also spells out that disable is not revoke — upsertFileShare preserves the token and stored password/allow-list, so re-enabling resurrects the identical URL. Also fixed at the source rather than propagated: updateWorkspaceFileContent, renameWorkspaceFile, and restoreWorkspaceFile now throw a classified OrchestrationError('not_found') instead of a bare Error, so nothing downstream string-sniffs 'File not found' or 'Storage limit exceeded' (the latter was already a classified payload_too_large). Out of scope, on purpose: bulk zip download (~150 lines of budget accounting and archiver wiring with no lib home — needs its own extraction pass), style / csv-preview / compiled-check / inline-image (editor-internal), and /api/tools/file/manage's write/append/compress/decompress. Known gaps (not fixed here) No v2 way to enumerate file folders. /api/v2/folders currently rejects resourceType=file, so a caller can set folderId on upload/move only with an id it already holds. This is the deliberate consequence of not publishing a transitional folder surface; it closes when the generic folder engine takes over file folders (it needs the path-segment name rules and the per-workspace advisory lock first). v2 list pagination is still in-memory — listWorkspaceFiles returns the full set for the scope and the route sorts and slices. Adding scope makes the set larger, so this gets worse before it gets better. Shares have no expiry column, no per-workspace cap, and no creation-side rate limit. The EE disablePublicFileSharing policy resolves against getUserPermissionConfig(userId, workspaceId) — worth confirming it behaves for a workspace-scoped API key, whose userId is the billed account rather than the acting human. Duplicate-name semantics are unchanged and shared: both surfaces auto-suffix via allocateUniqueWorkspaceFileName, so an upload can return 201 with a name different from the one sent — clients must read name back off the response. CONFLICT fires only when a unique name can't be allocated after several attempts. (My first draft of the OpenAPI description claimed 409 on any collision; Bugbot caught it and it's corrected.) PATCH /api/v2/files/{fileId} is the exact-or-fail path. v2 access denials stay 403 rather than being masked as 404 on reads — that matches every existing v2 route (v2WorkspaceAccessError); masking would be a surface-wide change, not a files-only one. Type of Change New feature Testing bun run check:api-validation:strict — passes (route baseline bumped 1041 → 1049 for the 8 new route files) bun run check:openapi — passes, 7 specs / 94 operations / 85 contracts cross-checked bun run type-check — passes bun run lint:check — passes bunx vitest run app/api/v2/files lib/workspace-files lib/uploads app/api/workspaces — 48 files, 425 tests passing One route.test.ts per route file: gate-off, invalid input, 403, 429, and happy path each, plus targeted cases for share PUT rejecting an unknown token, a bare re-enable keeping the existing token, scope=archived listing only archived items, and an upload landing in the folder named by folderId Checklist Code follows project style guidelines Self-reviewed my changes Tests added/updated and passing No new warnings introduced I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
Open Graph Description: Summary Expands /api/v2/files from list + upload + download + archive-one to cover what the internal files surface does: folders, rename, restore, move, bulk archive, share, and content replace v2...
X Description: Summary Expands /api/v2/files from list + upload + download + archive-one to cover what the internal files surface does: folders, rename, restore, move, bulk archive, share, and content replace v2...
Opengraph URL: https://github.com/simstudioai/sim/pull/6160
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:c702f332-9ff6-5be0-caad-d218af15b10e |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E64C:2833F1:63CFD4:89BC1A:6AFB3FD9 |
| html-safe-nonce | 5901e3fb0a57c165cf35660c2ec5312c687b1ca0e42bd59118483f0bd7cae1de |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjRDOjI4MzNGMTo2M0NGRDQ6ODlCQzFBOjZBRkIzRkQ5IiwidmlzaXRvcl9pZCI6IjE5MzQyMzExNzQ4NTk0MDczMjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8858834bea5634a86df42ba171c3dd7761c44bdf633ffaf1529ddd8b9f5758cd |
| hovercard-subject-tag | pull_request:4183232300 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/6160/files |
| twitter:image | https://avatars.githubusercontent.com/u/19564703?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/19564703?s=400&v=4 |
| og:image:alt | Summary Expands /api/v2/files from list + upload + download + archive-one to cover what the internal files surface does: folders, rename, restore, move, bulk archive, share, and content replace v2... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | d849b928f455c800985398e7f1b659425adb312a5fa14fba5d9a14e62e9fe5dd |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | a6c2f87cbcb6414452377b4967858ed6a66f1109 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width