Skip to content

Conversation

@daneryl
Copy link
Collaborator

@daneryl daneryl commented Dec 12, 2025

No description provided.

@daneryl daneryl marked this pull request as ready for review December 15, 2025 20:15
Copilot AI review requested due to automatic review settings December 15, 2025 20:15
Copy link
Contributor

Copilot AI left a 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 PR refactors the file download routes to use the v2 DownloadFileController implementation, consolidating permission checking logic and removing duplicate code. The changes streamline file access endpoints while maintaining backward compatibility through deprecated routes.

  • Replaced multiple individual route handlers with the DownloadFileController.customHandler pattern
  • Removed redundant validation and storage logic from routes.ts by leveraging the v2 controller
  • Cleaned up code formatting in DownloadFileController by removing unnecessary await and parentheses

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
app/api/files/routes.ts Refactored file download routes to use DownloadFileController, removed unused imports, consolidated deprecated redirect routes with prettier-ignore formatting
app/api/core/infrastructure/express/DownloadFileController.ts Simplified stream creation by removing unnecessary await and parentheses when calling getFile().read()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

//prettier-ignore
app.use('/uploaded_documents/:fileName', (req, res) => { res.redirect(301, `/api/files/${req.params.fileName}`); });
//prettier-ignore
app.get('/api/attachments/download', async (req, res) => { res.redirect(301, `/api/files/${req.query.file}?download=true`); });
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The redirect route for '/api/attachments/download' no longer validates the required 'file' query parameter. The original implementation had validation ensuring 'file' was a required string property. Now, if req.query.file is undefined, this will redirect to '/api/files/undefined?download=true', which could result in unexpected behavior. Consider adding validation or a check to ensure req.query.file exists before redirecting.

Suggested change
app.get('/api/attachments/download', async (req, res) => { res.redirect(301, `/api/files/${req.query.file}?download=true`); });
app.get(
'/api/attachments/download',
validation.validateRequest({
type: 'object',
properties: {
query: {
type: 'object',
required: ['file'],
properties: {
file: { type: 'string' },
},
},
},
}),
async (req, res) => {
res.redirect(301, `/api/files/${req.query.file}?download=true`);
}
);

Copilot uses AI. Check for mistakes.
app.use('/uploaded_documents/:fileName', (req, res) => { res.redirect(301, `/api/files/${req.params.fileName}`); });
//prettier-ignore
app.get('/api/attachments/download', async (req, res) => { res.redirect(301, `/api/files/${req.query.file}?download=true`); });
// Deprecated routes, keeping for Backwards compatibility
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate comment "Deprecated routes, keeping for Backwards compatibility" appears on both line 282 and line 289. Remove one of these duplicate comments to improve code clarity.

Suggested change
// Deprecated routes, keeping for Backwards compatibility

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants