-
Notifications
You must be signed in to change notification settings - Fork 8
Fix file handling for converted files #420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Implemented functionality to generate short-lived URLs for converted files during the upload process. - Updated response structure to include `shortLivedUrl` for both original and converted files, allowing for flexible use cases. - Enhanced error handling to log warnings if short-lived URL generation fails, ensuring fallback to regular URLs. - Added comprehensive tests to verify the presence and correctness of `shortLivedUrl` in upload responses, ensuring robust functionality for file handling.
- Added functionality to determine and attach the MIME type of converted files based on their URLs during the upload process. - Updated response structure to include `mimeType` for both original and converted files, ensuring accurate content type representation. - Improved error handling for URL parsing to ensure robust MIME type extraction, enhancing overall file handling capabilities.
- Updated `parseRawFileData` to prioritize converted values (URL, GCS, mimeType) when available, ensuring accurate representation of processed content. - Implemented checks to prevent editing of converted files, providing clear error messages to users attempting to modify them. - Added tests to verify that file collection correctly uses converted values and enforces editing restrictions on converted files, enhancing overall file management capabilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request enhances converted file handling in the Cortex File Handler by ensuring proper short-lived URLs and MIME type information for both original and converted files in API responses, while keeping Redis storage clean of transient data.
- Adds short-lived URL generation for converted files alongside original files in upload and checkHash responses
- Implements MIME type detection for converted files based on file extensions
- Updates file parsing logic to prefer converted file data (URL, GCS, MIME type) as primary values when available while preserving original displayFilename
- Prevents persistence of transient shortLivedUrl fields to Redis storage
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| helper-apps/cortex-file-handler/src/blobHandler.js | Adds short-lived URL and MIME type generation for converted files in both busboy and uploadFile flows |
| helper-apps/cortex-file-handler/src/index.js | Implements short-lived URL generation for converted files in checkHash operations with MIME type detection |
| helper-apps/cortex-file-handler/src/redis.js | Removes shortLivedUrl fields before persisting to Redis to keep storage clean of transient data |
| helper-apps/cortex-file-handler/src/services/storage/StorageService.js | Adds mimeType field to converted file responses in retention update operations |
| lib/fileUtils.js | Updates parseRawFileData to prefer converted values, adds getActualContentMimeType utility, enhances isTextMimeType detection, and updates file resolution logic |
| pathways/system/entity/tools/sys_tool_readfile.js | Expands KNOWN_TEXT_EXTENSIONS set with comprehensive list of code file extensions for better text file detection |
| pathways/system/entity/tools/sys_tool_editfile.js | Adds converted file edit prevention and uses getActualContentMimeType for proper MIME type determination |
| tests/unit/core/shortLivedUrl.test.js | Updates test expectations to verify converted.shortLivedUrl preference in URL resolution |
| tests/unit/core/fileCollection.test.js | Adds comprehensive tests for MIME type detection from URLs vs displayFilename |
| tests/integration/features/tools/fileCollection.test.js | Adds integration tests verifying converted file handling across multiple scenarios |
| helper-apps/cortex-file-handler/tests/shortLivedUrlConversion.test.js | Adds test verifying upload response includes shortLivedUrl for converted files |
| helper-apps/cortex-file-handler/package.json | Bumps version to 2.8.0 |
| helper-apps/cortex-file-handler/package-lock.json | Updates version lock to 2.8.0 |
Files not reviewed (1)
- helper-apps/cortex-file-handler/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import logger from '../../../../lib/logger.js'; | ||
| import { axios } from '../../../../lib/requestExecutor.js'; | ||
| import { uploadFileToCloud, findFileInCollection, loadFileCollection, getMimeTypeFromFilename, resolveFileParameter, deleteFileByHash, isTextMimeType, updateFileMetadata, writeFileDataToRedis, invalidateFileCollectionCache } from '../../../../lib/fileUtils.js'; | ||
| import { uploadFileToCloud, findFileInCollection, loadFileCollection, getMimeTypeFromFilename, resolveFileParameter, deleteFileByHash, isTextMimeType, updateFileMetadata, writeFileDataToRedis, invalidateFileCollectionCache, getActualContentMimeType } from '../../../../lib/fileUtils.js'; |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import resolveFileParameter.
| import { uploadFileToCloud, findFileInCollection, loadFileCollection, getMimeTypeFromFilename, resolveFileParameter, deleteFileByHash, isTextMimeType, updateFileMetadata, writeFileDataToRedis, invalidateFileCollectionCache, getActualContentMimeType } from '../../../../lib/fileUtils.js'; | |
| import { uploadFileToCloud, findFileInCollection, loadFileCollection, getMimeTypeFromFilename, deleteFileByHash, isTextMimeType, updateFileMetadata, writeFileDataToRedis, invalidateFileCollectionCache, getActualContentMimeType } from '../../../../lib/fileUtils.js'; |
This pull request enhances the Cortex File Handler's support for converted files by ensuring that both the original and converted files have proper short-lived URLs and MIME type information in responses, while keeping persistent storage clean of transient data. It also updates tests to verify these behaviors and improves file parsing logic to prefer converted file data when available.
Short-lived URL and MIME type handling for converted files:
shortLivedUrland detection ofmimeTypefor converted files in both upload and file handler logic, ensuring these are included in API responses but not persisted to Redis. [1] [2] [3] [4] [5] [6] [7]API response consistency and code improvements:
convertedblock (when available) withurl,shortLivedUrl,gcs, andmimeTypefields, and clarified the distinction between original and converted file URLs in the response. [1] [2]Testing enhancements:
shortLivedUrlfor the converted file and that it points to the correct file type.File parsing improvements:
Dependency and version updates:
2.8.0and added themime-typesimport where necessary. [1] [2] [3] [4]