Fix issue allowing multiple files with the same name - auto-rename on upload and rename operations#309
Conversation
Co-authored-by: danielalves96 <62755605+danielalves96@users.noreply.github.com>
Co-authored-by: danielalves96 <62755605+danielalves96@users.noreply.github.com>
|
@copilot this error is related with linter. fix please. |
Co-authored-by: danielalves96 <62755605+danielalves96@users.noreply.github.com>
|
@copilot the auto renaming is working perfectly on uploads, but for renaming doesn`t works. i need this for renaming files or folders too. like windows os |
Co-authored-by: danielalves96 <62755605+danielalves96@users.noreply.github.com>
Implemented auto-renaming for both file and folder rename operations. Now when you rename a file or folder to a name that already exists in the same location, it will automatically append a numeric suffix like
All tests passed. Commit: 6872c95 Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot would be nice add an space before the version of renaming example: and when i renaming, the file doest loaded (for downloads and poreviews) |
Co-authored-by: danielalves96 <62755605+danielalves96@users.noreply.github.com>
Updated the suffix format to include a space before the number. Now it generates names like Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot and when i renaming, the file doest loaded (for downloads and poreviews) |
I need more information to diagnose the issue. Can you please check the server logs and share the full error message? The 500 error suggests something is failing on the server side. Also, can you confirm:
The rename operation only changes the file name in the database, not the underlying file location (objectName), so downloads should continue to work. There might be an issue with how the renamed filename is being processed. |
|
@copilot
|
The error shows the file doesn't exist at the expected path on disk. This is not related to the rename feature - the rename operation only changes the The error
To verify the rename feature isn't the cause, check if:
The rename logic only updates the display name, not the storage location, so it shouldn't affect file downloads. |
- Added a new script to clean up orphan file records in the database. - Introduced `fileExists` method in the StorageProvider interface and implemented it in S3StorageProvider. - Enhanced FilesystemController to check for file existence before download. - Minor formatting adjustments in the Prisma schema for consistency.
…n upload and rename operations (kyantech#309)
Summary
This PR implements automatic renaming of files and folders when a duplicate name is detected, similar to Windows behavior. When a duplicate is detected, the system automatically appends a numeric suffix with a space (e.g.,
file (1).txt,folder (2)) to ensure unique names.Changes Made
registerFilemethod to check for duplicate filenames in the same foldercheckFilemethod to check for duplicate filenames and suggest renamed fileupdateFilemethod to auto-rename files on rename operationsregisterFoldermethod to auto-rename folders on creationupdateFoldermethod to auto-rename folders on rename operationsImplementation Details
New Files
apps/server/src/utils/file-name-generator.ts: Contains utilities for auto-renaminggenerateUniqueFileName(): For file uploadsgenerateUniqueFileNameForRename(): For file rename operationsgenerateUniqueFolderName(): For folder creation and rename operationsparseFileName(): Parse filename into base and extensionModified Files
apps/server/src/modules/file/controller.ts:registerFile()to auto-rename on uploadcheckFile()to return suggested nameupdateFile()to auto-rename on renameapps/server/src/modules/folder/controller.ts:registerFolder()to auto-rename on creationupdateFolder()to auto-rename on rename (instead of returning error)apps/server/.gitignore: Added build artifacts exclusionapps/web/src/app/(shares)/r/[alias]/layout.tsx: Fixed Next.js 15 async headers() usageapps/web/src/app/(shares)/s/[alias]/layout.tsx: Fixed Next.js 15 async headers() usageTesting Results
All tests passed:
(1)suffix with space(2)suffix with spaceValidation Results
Behavior
File Operations:
filename (N).extensionFolder Operations:
foldername (N)General:
checkFileAPI returnssuggestedNameif the filename will be renamednavarro (1)instead ofnavarro(1))Security Summary
✅ CodeQL security scan completed with 0 alerts
Fixes #266
Original prompt
Fixes #266
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.