67 lines
2.0 KiB
Rust
67 lines
2.0 KiB
Rust
// TODO: this whole ass module bro i mean c'mon.... just just clean it
|
|
pub const INVITE_CREATE: &'static str = "/invite/create"; // requires none
|
|
|
|
pub const CHANNELS_LIST: &'static str = "/channels/list"; // requires none
|
|
pub const CHANNELS_CREATE: &'static str = "/channels/create"; // requires @name @kind
|
|
pub const CHANNELS_DELETE: &'static str = "/channels/delete"; // requires @channel_id
|
|
|
|
pub const MESSAGE_SEND: &'static str = "/message/send"; // requires @content
|
|
|
|
pub const SERVER_META: &'static str = "/meta"; // open
|
|
|
|
pub const GET_ONLINE_MEMBERS: &'static str = "/members/get_online";
|
|
// @requires: admin permissions
|
|
//
|
|
pub const SET_PERMS_BY_ADMIN: &'static str = "/admin/setpermisions";
|
|
pub const SET_NEW_ADMIN: &'static str = "/owner/newadmin"; // @requiers: owner perms
|
|
// potentially adding more bases later
|
|
pub const DYNAMIC_ROUTE_BASES: [(&'static str, bool);3] = [
|
|
("/join", true), // open
|
|
("/public", true), // open : valid sections := neighbors|rules|description
|
|
("/user", false), // TODO: valid sections := /meta/<name>|/dm/<name>
|
|
];
|
|
pub const DYN_JOIN: &'static str = DYNAMIC_ROUTE_BASES[0].0;
|
|
|
|
pub struct DynRoute {
|
|
pub base: String,
|
|
pub dynamic: String,
|
|
}
|
|
|
|
|
|
pub fn resolve_dynamic_route(uri: &str) -> Option<DynRoute> {
|
|
let mut valid = false;
|
|
let mut base_ref = "";
|
|
for base in DYNAMIC_ROUTE_BASES.iter() {
|
|
if uri.starts_with(base.0) {
|
|
valid = true;
|
|
base_ref = base.0;
|
|
break;
|
|
}
|
|
}
|
|
if valid {
|
|
Some(DynRoute {
|
|
base: base_ref.into(),
|
|
dynamic: uri.to_string().replace(base_ref, "")
|
|
})
|
|
}
|
|
else {
|
|
None
|
|
}
|
|
}
|
|
|
|
pub fn is_open(path: &str) -> bool {
|
|
/*
|
|
* Simple interface for determining if a route/base is open
|
|
* i.e. requires authentication or not
|
|
*/
|
|
let mut ret = path == SERVER_META;
|
|
for route in DYNAMIC_ROUTE_BASES.iter() {
|
|
if route.1 == true || ret == true{
|
|
ret = true;
|
|
break;
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|