vn-docker/cdn/rwmap.pl

27 lines
657 B
Perl
Raw Normal View History

2024-07-02 10:51:13 +00:00
#!/usr/bin/perl
use strict;
use warnings;
use Digest::SHA qw(sha1_hex);
# Desactiva el buffering de salida para que Apache pueda obtener la respuesta inmediatamente
$| = 1;
while (<STDIN>) {
chomp;
my $input = $_;
2024-08-14 09:07:18 +00:00
$input =~ /^\/image\/(.*)\/([a-z0-9-_]+)\.(png)$/;
my $collection = $1;
my $name = $2;
my $extension = $3;
2024-07-02 10:51:13 +00:00
2024-08-14 09:07:18 +00:00
my $sha1 = sha1_hex($name);
my $first = substr($sha1, 0, 2);
my $last = substr($sha1, 1, 2);
my $newPath = "images/$collection/$first/$last/$name.$extension";
2024-07-02 10:51:13 +00:00
2024-08-14 09:07:18 +00:00
if (-e "/usr/local/apache2/htdocs/$newPath") {
print "/$newPath\n";
2024-07-02 10:51:13 +00:00
} else {
2024-08-14 09:07:18 +00:00
print "/image/$input\n";
2024-07-02 10:51:13 +00:00
}
}