2024-04-09 19:48:18 +02:00
|
|
|
use url::{ParseError, Url};
|
|
|
|
|
|
2024-05-19 07:17:13 +02:00
|
|
|
pub fn generate_object_id(domain: &str, uuid: &str) -> Result<Url, ParseError> {
|
2024-06-27 05:44:40 +02:00
|
|
|
Url::parse(&format!("https://{}/apbridge/object/{}", domain, uuid))
|
2024-05-19 07:17:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn generate_user_id(domain: &str, uuid: &str) -> Result<Url, ParseError> {
|
2024-06-27 05:44:40 +02:00
|
|
|
Url::parse(&format!("https://{}/apbridge/user/{}", domain, uuid))
|
2024-05-19 07:17:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn generate_random_object_id(domain: &str) -> Result<Url, ParseError> {
|
|
|
|
|
let id: String = uuid::Uuid::new_v4().to_string();
|
2024-06-27 05:13:38 +02:00
|
|
|
generate_object_id(domain, &id)
|
2024-04-09 19:48:18 +02:00
|
|
|
}
|
2024-05-05 18:18:39 +02:00
|
|
|
|
|
|
|
|
/// Generate a follow accept id
|
2024-06-27 05:13:38 +02:00
|
|
|
pub fn generate_follow_accept_id(domain: &str, db_id: &str) -> Result<Url, ParseError> {
|
|
|
|
|
Url::parse(&format!("https://{}/apbridge/follow/{}", domain, db_id))
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-03 03:49:07 +02:00
|
|
|
pub fn generate_follow_req_id(domain: &str, db_id: &str) -> Result<Url, ParseError> {
|
|
|
|
|
Url::parse(&format!("https://{}/apbridge/followreq/{}", domain, db_id))
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 19:35:04 +02:00
|
|
|
pub fn generate_lysand_post_url(domain: &str, db_id: &str) -> Result<Url, ParseError> {
|
|
|
|
|
Url::parse(&format!(
|
|
|
|
|
"https://{}/apbridge/lysand/object/{}",
|
|
|
|
|
domain, db_id
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-27 05:13:38 +02:00
|
|
|
// TODO for later aprl: needs to be base64url!!!
|
|
|
|
|
pub fn generate_create_id(
|
|
|
|
|
domain: &str,
|
|
|
|
|
create_db_id: &str,
|
|
|
|
|
basesixfour_url: &str,
|
|
|
|
|
) -> Result<Url, ParseError> {
|
2024-06-18 03:43:59 +02:00
|
|
|
Url::parse(&format!(
|
2024-06-27 05:13:38 +02:00
|
|
|
"https://{}/apbridge/create/{}/{}",
|
|
|
|
|
domain, create_db_id, basesixfour_url
|
2024-06-18 03:43:59 +02:00
|
|
|
))
|
2024-05-05 18:18:39 +02:00
|
|
|
}
|
2024-06-27 05:13:38 +02:00
|
|
|
|
|
|
|
|
pub fn generate_random_create_id(domain: &str, basesixfour_url: &str) -> Result<Url, ParseError> {
|
|
|
|
|
let id: String = uuid::Uuid::new_v4().to_string();
|
|
|
|
|
generate_create_id(domain, &id, basesixfour_url)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn base_url_encode(url: &Url) -> String {
|
|
|
|
|
base64_url::encode(&url.to_string())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn base_url_decode(encoded: &str) -> String {
|
|
|
|
|
String::from_utf8(base64_url::decode(encoded).unwrap()).unwrap()
|
|
|
|
|
}
|