-
-
Notifications
You must be signed in to change notification settings - Fork 175
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
Add custom URL support #253
base: master
Are you sure you want to change the base?
Conversation
Support szabodanika#83 - add MICROBIN_ENABLE_CUSTOM_URL argument, default: false - replace pasta.id == id to lambda function `alias_comparator` for better code reuse. - add custom_alias field in database
@@ -16,3 +20,15 @@ pub fn to_u64(hash_id: &str) -> Result<u64, &str> { | |||
let id = ids.first().ok_or("No ID found in hash ID")?; | |||
Ok(*id) | |||
} | |||
|
|||
pub fn alias_comparator(id: &str) -> Box<dyn Fn(&Pasta) -> bool> { |
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.
why does this return a function? that seems overly complicated. Further more the name is a bit generic. To me its not clear at all what the function does given its name. Half of the logic living in the returned closure does not help parsing it.
I might be missing something but why is the returned closure used everywhere else as "comparator"?
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.
why does this return a function? that seems overly complicated. Further more the name is a bit generic. To me its not clear at all what the function does given its name. Half of the logic living in the returned closure does not help parsing it.
I might be missing something but why is the returned closure used everywhere else as "comparator"?
This function is to find the entry that is equal to the hash_id, animal_id or custom_url in the link. Because there are many places that use the same and repeated comparison logic, I have separated it out. I am not good at naming, maybe it should be renamed
Support #83
What changed
pasta.id == id
to lambda functionalias_comparator
for better code reuse.custom_alias
field in databaseWhy replace pasta.id == id
There are a large number of statements in the code that compare
pasta.id == id
, and implementing custom URL inevitably introduces additional fields, requiring a large number of duplicate judgments to be written at all positions. Therefore, I choose to extract the comparison logic into a lambda function to reduce duplicate code.Todo
Custom URL validity check.