Add custom URL support#253
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
| Ok(*id) | ||
| } | ||
|
|
||
| pub fn alias_comparator(id: &str) -> Box<dyn Fn(&Pasta) -> bool> { |
There was a problem hiding this comment.
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.
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
Co-authored-by: Xeu <thankrain@qq.com>
Support #83
What changed
pasta.id == idto lambda functionalias_comparatorfor better code reuse.custom_aliasfield 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.