Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add custom URL support #253

wants to merge 3 commits into from

Conversation

OXeu
Copy link

@OXeu OXeu commented Feb 24, 2024

Support #83

What changed

  • 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

Why 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.

OXeu added 3 commits February 23, 2024 23:32
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
@OXeu OXeu changed the title Add custom url support Add custom URL support Feb 24, 2024
@@ -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> {
Copy link
Contributor

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"?

Copy link
Author

@OXeu OXeu Oct 23, 2024

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

@szabodanika szabodanika self-assigned this Nov 2, 2024
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.

3 participants