Merge branch 'master' into szabodanika

This commit is contained in:
Daniel Szabo 2022-11-06 23:10:41 +02:00
commit c6e5c6f018
10 changed files with 91 additions and 18 deletions

18
src/util/hashids.rs Normal file
View file

@ -0,0 +1,18 @@
use harsh::Harsh;
use lazy_static::lazy_static;
lazy_static! {
pub static ref HARSH: Harsh = Harsh::builder().length(6).build().unwrap();
}
pub fn to_hashids(number: u64) -> String {
HARSH.encode(&[number])
}
pub fn to_u64(hash_id: &str) -> Result<u64, &str> {
let ids = HARSH
.decode(hash_id)
.map_err(|_e| "Failed to decode hash ID")?;
let id = ids.get(0).ok_or("No ID found in hash ID")?;
Ok(*id)
}