Skip to content

Add custom URL support#253

Open
OXeu wants to merge 3 commits into
szabodanika:masterfrom
OXeu:custom-url
Open

Add custom URL support#253
OXeu wants to merge 3 commits into
szabodanika:masterfrom
OXeu:custom-url

Conversation

@OXeu
Copy link
Copy Markdown

@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
Comment thread src/util/hashids.rs
Ok(*id)
}

pub fn alias_comparator(id: &str) -> Box<dyn Fn(&Pasta) -> bool> {
Copy link
Copy Markdown

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
Copy Markdown
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
santiagocezar added a commit to santiagocezar/microbin that referenced this pull request Jan 23, 2026
Co-authored-by: Xeu <thankrain@qq.com>
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