Decode names received from the filesystem.

This commit is contained in:
Sam Greytalon 2023-11-16 10:27:38 -08:00
parent 251c7640a3
commit b8b7fc68bd
3 changed files with 28 additions and 21 deletions

View File

@ -4,6 +4,7 @@ Dexter is a Mojolicious webapp that handles the generation of index pages under
## Setup
Dexter depends on these Perl modules:
* Cwd
* Encode
* Readonly
* File::Path
* File::Spec
@ -35,6 +36,7 @@ Dexter needs to know about two directories you want it to use:
### Other
* `$MAX_REQUEST_SIZE`: The maximum size of POST requests that Dexter will process.
* `$FS_ENCODING`: The character encoding that the underlying filesystem uses to store filenames. The default value of `UTF-8` is most likely correct.
## License
Dexter is released under Version 3 of the GNU Affero General Public License (see `LICENSE`). The default font- JetBrainsMono from NerdFonts- is released under Version 1.1 of the SIL Open Font License (see `app/public/.assets/FONT-LICENSE`).

View File

@ -4,6 +4,9 @@ use Module::Installed::Tiny qw(module_installed);
use Mojolicious::Lite -signatures;
use Encode::Locale;
use Encode;
use Readonly;
use Cwd;
@ -34,6 +37,7 @@ Readonly::Hash my %MEANING_OF_HTTP_CODE => (
Readonly my $ROOT_DIRECTORY => 'public';
Readonly my $SOCKET_DIRECTORY => '/var/www/run';
Readonly my $TEMP_DIRECTORY => '/tmp/dexter';
Readonly my $FS_ENCODING => 'UTF-8';
Readonly my $MAX_REQUEST_SIZE => $GIGABYTE;
mkdir $TEMP_DIRECTORY;
@ -469,21 +473,22 @@ 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,
name_dec => Encode::decode($FS_ENCODING, $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;

View File

@ -2,14 +2,14 @@
<html lang="en_US">
<head>
<title>Index of <%= $c->req->url->path->to_string %></title>
<title>Index of <%= $c->req->url->path->to_route %></title>
<meta charset="utf-8" />
<link rel="stylesheet" href="/.assets/style.css" />
<script src="/.assets/main.js"></script>
</head>
<body>
<header>
<h1>Index of <%= $c->req->url->path->to_string %></h1>
<h1>Index of <%= $c->req->url->path->to_route %></h1>
</header>
<article>
<table>
@ -64,8 +64,8 @@
% foreach my $file (@$FILES) {
<tr>
<td class="left">
<a href="<%= $file->{name} %>">
<%= $file->{name} %>
<a href="<%= $file->{name_dec} %>">
<%= $file->{name_dec} %>
</a>
<span class="buttons">
% if ( permission_available_at_path('MOVE', $file->{name}) ) {
@ -73,7 +73,7 @@
<a class="button" onclick="file_move(this)">&nbsp;✎&nbsp;</a>
<form action="./" method="post">
<input type="hidden" name="intent" value="move" />
<input type="hidden" name="target_path" value="<%= $file->{name} %>" />
<input type="hidden" name="target_path" value="<%= $file->{name_dec} %>" />
<input type="hidden" name="dest_path" value="" />
</form>
</span>
@ -83,7 +83,7 @@
<a class="button" onclick="file_delete(this)">&nbsp;✖&nbsp;</a>
<form action="./" method="post">
<input type="hidden" name="intent" value="delete" />
<input type="hidden" name="target_path" value="<%= $file->{name} %>" />
<input type="hidden" name="target_path" value="<%= $file->{name_dec} %>" />
</form>
</span>
% }