Swap url_escape string shenanigans for proper Mojo route methods

This commit is contained in:
Sam Greytalon 2023-10-27 10:20:29 -07:00
parent a7e848d4a1
commit a4f1f18cb4
2 changed files with 26 additions and 36 deletions

60
app/dexter.pl Normal file → Executable file
View File

@ -3,7 +3,6 @@
use Module::Installed::Tiny qw(module_installed);
use Mojolicious::Lite -signatures;
use Mojo::Util qw(url_unescape);
use Readonly;
@ -250,7 +249,7 @@ sub user_has_permission_on_path ($user, $permission, $path) {
my $permit = $rule_ref->[1];
my $permission = $PERMISSIONS{$permission};
next if not $path->to_string =~ m/$regex/;
next if not $path->to_route =~ m/$regex/;
return ( $permission & $permit ) == $permission;
}
@ -287,7 +286,6 @@ sub get_sorts_hash_from_query ($query_string) {
sub turn_string_into_path_using_url ($string, $url) {
my $path = $url->path->clone->merge($string);
$path = sanitize_path($path);
$path = unescape_path($path);
$path = $path->trailing_slash(0);
}
@ -315,7 +313,7 @@ sub user_save_file_to_path ($user, $file, $path) {
my ( $code, $message ) = check_user_can_create_file($user, $path);
return $code, $message if $code != 200;
my $path_string = $ROOT_DIRECTORY . $path->to_string;
my $path_string = $ROOT_DIRECTORY . $path->to_route;
$file->move_to($path_string)
or return 500, "Could not upload file '$path_string'!";
@ -326,7 +324,7 @@ sub user_mkdir_at_path ($user, $path) {
my ( $code, $message ) = check_user_can_create_file($user, $path);
return $code, $message if $code != 200;
my $path_string = $ROOT_DIRECTORY . $path->to_string;
my $path_string = $ROOT_DIRECTORY . $path->to_route;
mkdir($path_string)
or return 500, "Directory '$path_string' could not be created!";
@ -337,7 +335,7 @@ sub user_delete_path ($user, $path) {
my ( $code, $message ) = check_user_can_delete_file($user, $path);
return $code, $message if $code != 200;
my $path_string = $ROOT_DIRECTORY . $path->to_string;
my $path_string = $ROOT_DIRECTORY . $path->to_route;
my $err = 0;
if ( -d $path_string ) {
$err = not rmtree($path_string);
@ -360,8 +358,8 @@ sub user_move_path_to_path ($user, $path, $new_path) {
( $code, $message ) = check_user_can_create_file($user, $new_path);
return $code, $message if $code != 200;
my $path_string = $ROOT_DIRECTORY . $path->to_string;
my $new_path_string = $ROOT_DIRECTORY . $new_path->to_string;
my $path_string = $ROOT_DIRECTORY . $path->to_route;
my $new_path_string = $ROOT_DIRECTORY . $new_path->to_route;
move($path_string, $new_path_string)
or return 500,
"Could not move file '$path_string' to '$new_path_string'!";
@ -370,7 +368,7 @@ sub user_move_path_to_path ($user, $path, $new_path) {
}
sub get_files_at_path ($path) {
my $path_string = $path->to_string;
my $path_string = $path->to_route;
my $directory_path = $ROOT_DIRECTORY . $path_string;
opendir my $directory, $directory_path or return ();
@ -424,14 +422,6 @@ sub sort_symbol_for_order ($sort_order) {
}
}
sub unescape_path ($path) {
my $path_string = $path->to_string;
$path_string = url_unescape($path_string);
return Mojo::Path->new($path_string);
}
sub get_file_with_name ($name) {
my (
$device, $inode, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
@ -446,21 +436,21 @@ sub get_file_with_name ($name) {
}
my %file = (
name => $name,
device => $device,
inode => $inode,
mode => $mode,
nlink => $nlink,
uid => $uid,
gid => $gid,
rdev => $rdev,
size => $size,
atime => $atime,
mtime => $mtime,
ctime => $ctime,
blksize => $blksize,
blocks => $blocks,
type => $type,
name => $name,
device => $device,
inode => $inode,
mode => $mode,
nlink => $nlink,
uid => $uid,
gid => $gid,
rdev => $rdev,
size => $size,
atime => $atime,
mtime => $mtime,
ctime => $ctime,
blksize => $blksize,
blocks => $blocks,
type => $type,
);
return \%file;
@ -550,7 +540,7 @@ sub parse_sort_query ($query_string) {
}
sub check_user_can_create_file ($user, $path) {
my $path_string = $path->to_string;
my $path_string = $path->to_route;
if ( not user_has_permission_on_path($user, 'CREATE', $path) ) {
return 403, "You do not have permission to create '$path_string'!";
@ -560,7 +550,7 @@ sub check_user_can_create_file ($user, $path) {
return 409, "'$path_string' already exists!";
}
my $parent = $path->to_dir->to_string;
my $parent = $path->to_dir->to_route;
if ( not -e $ROOT_DIRECTORY . $parent ) {
return 409, "Parent directory '$parent' does not exist!";
@ -574,7 +564,7 @@ sub check_user_can_create_file ($user, $path) {
}
sub check_user_can_delete_file ($user, $path) {
my $path_string = $path->to_string;
my $path_string = $path->to_route;
if ( not user_has_permission_on_path($user, 'DELETE', $path) ) {
return 403, "You do not have permission to delete '$path_string'!";

View File

@ -68,4 +68,4 @@ function get_file_name_from_url(url) {
}
return name;
}
}