feat core: Do stuff with variables and add error validation, not a working state yet for routes, just preperation.

This commit is contained in:
prplwtf 2024-01-27 19:30:19 +01:00
parent b1c6d4a9d7
commit 349986dffb
3 changed files with 58 additions and 28 deletions

View file

@ -693,54 +693,82 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) ]]; then VCMD="y"
for parent in $Components_Navigation_Routes_; do for parent in $Components_Navigation_Routes_; do
parent="${parent}_" parent="${parent}_"
for child in ${!parent}; do for child in ${!parent}; do
# Route name # Route name
if [[ $child == "Components_Navigation_Routes_"+([0-9])"_Name" ]]; then if [[ $child == "Components_Navigation_Routes_"+([0-9])"_Name" ]]; then COMPONENTS_ROUTE_NAME="${!child}"; fi
echo "[NAME] ${child} ${!child}"
COMPONENTS_ROUTE_NAME="${!child}"
fi
# Route path # Route path
if [[ $child == "Components_Navigation_Routes_"+([0-9])"_Path" ]]; then if [[ $child == "Components_Navigation_Routes_"+([0-9])"_Path" ]]; then COMPONENTS_ROUTE_PATH="${!child}"; fi
echo "[PATH] ${child} ${!child}"
COMPONENTS_ROUTE_PATH="${!child}"
fi
# Route type # Route type
if [[ $child == "Components_Navigation_Routes_"+([0-9])"_Type" ]]; then if [[ $child == "Components_Navigation_Routes_"+([0-9])"_Type" ]]; then COMPONENTS_ROUTE_TYPE="${!child}"; fi
echo "[TYPE] ${child} ${!child}"
COMPONENTS_ROUTE_TYPE="${!child}"
fi
# Route component # Route component
if [[ $child == "Components_Navigation_Routes_"+([0-9])"_Component" ]]; then if [[ $child == "Components_Navigation_Routes_"+([0-9])"_Component" ]]; then COMPONENTS_ROUTE_COMP="${!child}"; fi
echo "[COMPONENT] ${child} ${!child}"
COMPONENTS_ROUTE_COMP="${!child}"
fi
done done
echo " # Route identifier
[NAME] $COMPONENTS_ROUTE_NAME COMPONENTS_ROUTE_IDEN=$(tr -dc '[:lower:]' < /dev/urandom | fold -w 10 | head -n 1)
[PATH] $COMPONENTS_ROUTE_PATH COMPONENTS_ROUTE_IDEN="${COMPONENTS_ROUTE_IDEN^}"
[TYPE] $COMPONENTS_ROUTE_TYPE
[COMP] $COMPONENTS_ROUTE_COMP echo -e "NAME: $COMPONENTS_ROUTE_NAME\nPATH: $COMPONENTS_ROUTE_PATH\nTYPE: $COMPONENTS_ROUTE_TYPE\nCOMP: $COMPONENTS_ROUTE_COMP\nIDEN: $COMPONENTS_ROUTE_IDEN" >> $BLUEPRINT__DEBUG
"
# Return error if type is not defined correctly.
if [[ ( $COMPONENTS_ROUTE_TYPE != "server" ) && ( $COMPONENTS_ROUTE_TYPE != "account" ) ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Navigation route types can only be either 'server' or 'account'."
exit 1
fi
# Prevent escaping components folder.
if [[
( ${COMPONENTS_ROUTE_COMP} == "/"* ) ||
( ${COMPONENTS_ROUTE_COMP} == *"/.."* ) ||
( ${COMPONENTS_ROUTE_COMP} == *"../"* ) ||
( ${COMPONENTS_ROUTE_COMP} == *"/../"* ) ||
( ${COMPONENTS_ROUTE_COMP} == *"\n"* ) ||
( ${COMPONENTS_ROUTE_COMP} == *"@"* ) ||
( ${COMPONENTS_ROUTE_COMP} == *"\\"* )
]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Navigation route component paths may not escape the components directory."
exit 1
fi
# Validate file names for route components.
if [[ ${COMPONENTS_ROUTE_COMP} == *".tsx" ]] ||
[[ ${COMPONENTS_ROUTE_COMP} == *".ts" ]] ||
[[ ${COMPONENTS_ROUTE_COMP} == *".jsx" ]] ||
[[ ${COMPONENTS_ROUTE_COMP} == *".js" ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Navigation route component paths may not end with a file extension."
exit 1
fi
# Return error if identifier is generated incorrectly.
if [[ $COMPONENTS_ROUTE_IDEN == "" ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Failed to generate extension navigation route identifier, halting process."
exit 1
fi
# Return error if routes are defined incorrectly. # Return error if routes are defined incorrectly.
if [[ $COMPONENTS_ROUTE_NAME == "" ]] \ if [[ $COMPONENTS_ROUTE_NAME == "" ]] \
|| [[ $COMPONENTS_ROUTE_PATH == "" ]] \ || [[ $COMPONENTS_ROUTE_PATH == "" ]] \
|| [[ $COMPONENTS_ROUTE_TYPE == "" ]] \ || [[ $COMPONENTS_ROUTE_TYPE == "" ]] \
|| [[ $COMPONENTS_ROUTE_COMP == "" ]]; then || [[ $COMPONENTS_ROUTE_COMP == "" ]]; then
PRINT FATAL "One or more custom routes appear to have undefined fields, expect errors." rm -R ".blueprint/tmp/$n"
PRINT FATAL "One or more extension navigation routes appear to have undefined fields."
exit 1 exit 1
fi fi
# apply routes..
# Clear variables after doing all route stuff for a defined route. # Clear variables after doing all route stuff for a defined route.
COMPONENTS_ROUTE_NAME="" COMPONENTS_ROUTE_NAME=""
COMPONENTS_ROUTE_PATH="" COMPONENTS_ROUTE_PATH=""
COMPONENTS_ROUTE_TYPE="" COMPONENTS_ROUTE_TYPE=""
COMPONENTS_ROUTE_COMP="" COMPONENTS_ROUTE_COMP=""
COMPONENTS_ROUTE_IDEN=""
done done
fi fi
else else

View file

@ -0,0 +1 @@
{ path: '[path]', name: '[name]', component: [component], },

View file

@ -0,0 +1 @@
{ path: '[path]', name: '[name]', component: [component], permission: null, },