-
Notifications
You must be signed in to change notification settings - Fork 344
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
fix: file size limit for guest pages #359
Conversation
WalkthroughThe recent update enhances the handling of maximum file size limits in form fields within a client application. Specifically, it improves the logic for setting the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (2)
- client/components/open/forms/OpenFormField.vue (1 hunks)
- client/components/open/forms/fields/components/FieldOptions.vue (1 hunks)
Additional comments: 1
client/components/open/forms/fields/components/FieldOptions.vue (1)
- 346-346: The update to the
mbLimit
computed property correctly implements the logic for determining the maximum file size limit based on the presence of aworkspace
object within theform
object. To ensure consistency and maintainability across components, consider aligning this logic with any related changes made in other components, such asOpenFormField.vue
. This could involve refactoring or extracting shared logic into a utility function or mixin if the logic becomes more complex or is reused in multiple places.
let maxFileSize = (this.form?.workspace && this.form?.workspace.max_file_size) ? this.form?.workspace?.max_file_size : 10 | ||
if (field?.max_file_size > 0) { | ||
maxFileSize = Math.min(field.max_file_size, maxFileSize) | ||
} | ||
inputProperties.mbLimit = maxFileSize |
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.
The logic for determining the file upload size limit (mbLimit
) is correctly implemented. However, it could be refactored for improved readability and maintainability. Consider extracting this logic into a separate method. This not only makes the code cleaner but also easier to test and maintain.
methods: {
+ calculateMbLimit() {
+ let maxFileSize = 10; // Default value
+ if (this.form?.workspace?.max_file_size) {
+ maxFileSize = this.form.workspace.max_file_size;
+ }
+ if (this.field?.max_file_size > 0) {
+ maxFileSize = Math.min(this.field.max_file_size, maxFileSize);
+ }
+ return maxFileSize;
+ },
inputProperties(field) {
const inputProperties = {
// Existing properties...
};
if (field.type === 'files' || (field.type === 'url' && field.file_upload)) {
inputProperties.multiple = (field.multiple !== undefined && field.multiple);
- let maxFileSize = (this.form?.workspace && this.form?.workspace.max_file_size) ? this.form?.workspace?.max_file_size : 10;
- if (field?.max_file_size > 0) {
- maxFileSize = Math.min(field.max_file_size, maxFileSize);
- }
+ inputProperties.mbLimit = this.calculateMbLimit();
inputProperties.accept = (this.form.is_pro && field.allowed_file_types) ? field.allowed_file_types : '';
}
// Rest of the method...
}
}
This refactor introduces a calculateMbLimit
method that encapsulates the logic for determining the maximum file size limit, making the inputProperties
method cleaner and focusing it more on its primary responsibility.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
let maxFileSize = (this.form?.workspace && this.form?.workspace.max_file_size) ? this.form?.workspace?.max_file_size : 10 | |
if (field?.max_file_size > 0) { | |
maxFileSize = Math.min(field.max_file_size, maxFileSize) | |
} | |
inputProperties.mbLimit = maxFileSize | |
methods: { | |
calculateMbLimit() { | |
let maxFileSize = 10; // Default value | |
if (this.form?.workspace?.max_file_size) { | |
maxFileSize = this.form.workspace.max_file_size; | |
} | |
if (this.field?.max_file_size > 0) { | |
maxFileSize = Math.min(this.field.max_file_size, maxFileSize); | |
} | |
return maxFileSize; | |
}, | |
inputProperties(field) { | |
const inputProperties = { | |
// Existing properties... | |
}; | |
if (field.type === 'files' || (field.type === 'url' && field.file_upload)) { | |
inputProperties.multiple = (field.multiple !== undefined && field.multiple); | |
inputProperties.mbLimit = this.calculateMbLimit(); | |
inputProperties.accept = (this.form.is_pro && field.allowed_file_types) ? field.allowed_file_types : ''; | |
} | |
// Rest of the method... | |
} | |
} |
Summary by CodeRabbit