Compare commits

...

2 Commits

Author SHA1 Message Date
Javier Segarra f4f2333d36 refs #5576 perf update scripts sh
gitea/salix/pipeline/head There was a failure building this commit Details
2023-12-18 11:33:28 +01:00
Javier Segarra b1d5a62aa5 refs #5576 perf update script.pl 2023-12-18 10:33:45 +01:00
3 changed files with 70 additions and 31 deletions

View File

@ -2,30 +2,65 @@
use strict;
use warnings;
use CGI;
use Digest::SHA qw(sha1_hex);
use CGI;
my $cgi = CGI->new;
my $input_string = $cgi->param('name') || "Hola, mundo!";
my $input_value = $cgi->param('value') || "Hola, mundo!";
my $input_name = $cgi->param('name') || "default";
my $input_value = $cgi->param('value') || "default";
my $new_path;
# Calcula el valor hash MD5 del string
my $hash_value = sha1_hex($input_string);
# Obtiene solo los 2 primeros caracteres del hash MD5
my $first_characters = substr($hash_value, 2, 2);
# Obtiene solo los 2 segundos caracteres del hash MD5
my $second_characters = substr($hash_value, 0, 2);
my $new_path ="images/transform/$first_characters/$second_characters/$input_value";
# Imprime el resultado
# Establecer el tipo de contenido a imagen JPEG
print "Content-type: image/jpeg\n\n";
# Dividir la ruta usando el símbolo "/" para extraaer el nombre del archivo SIN extension
my $fileName= (split('/', $input_name))[-1];
# Dividir la ruta usando el símbolo "/" para extraaer el nombre del archivo CON extension
my $file= (split('/', $input_value))[-1];
my $exists = -e "$input_value";
# print $exists;
# $exists = -e "$input_value";
# print $exists;
if($exists) {
# print "Content-type: text/html\n\n";
$new_path ="$input_value";
# print "<h1>$new_path</h1>";
} else {
# Calcula el valor hash MD5 del string
my $hash_value = sha1_hex($fileName);
# Obtiene solo los 2 primeros caracteres del hash MD5
my $first_characters = substr($hash_value, 0, 2);
# Obtiene solo los 2 segundos caracteres del hash MD5
my $second_characters = substr($hash_value, 1, 2);
$new_path ="images/$first_characters/$second_characters/$file";
# Imprime el resultado
# Establecer el tipo de contenido a imagen JPEG
# print "Content-type: text/html\n\n";
# print "<h1>Ultimo elemento es: $fileName</h1>";
# print "<h1>input_name==>$input_name</h1>";
# print "<h1>input_value==>$input_value</h1>";
# print "<h1>fileName==>$fileName</h1>";
# print "<h1>file==>$file</h1>";
# print "<h1>hash_value==>$hash_value</h1>";
# print "<h1>first_characters==>$first_characters/$second_characters/$input_value</h1>";
# print "<h1>new_path==>$new_path</h1>";
# Abre la imagen en modo binario
open my $imagen, '<', $new_path or die "No se pudo abrir la imagen: $!";
# Abre la imagen en modo binario
# Imprime los bytes de la imagen directamente en la salida estándar
binmode STDOUT;
print while <$imagen>;
# open my $imagen, '<', $new_path or die "No se pudo abrir la imagen: $!";
# Cierra el archivo
close $imagen;
}
# Verifica si $imagen está definida antes de intentar usarla
if (defined $new_path) {
abrir_imagen($new_path);
# print "<h1>HOLA</h1>";
}
sub abrir_imagen {
my ($ruta) = @_;
print "Content-type: image/jpeg\n\n";
open my $imagen, '<', $ruta or die "No se pudo abrir la imagen: $!";
# Imprime los bytes de la imagen directamente en la salida estándar
binmode STDOUT;
print while <$imagen>;
# Cierra el archivo
close $imagen;
}

View File

@ -1,5 +1,5 @@
#!/bin/bash
DIR_LEVELS=2
for collection in */ ; do
for size in "$collection"*/ ; do
for image in "$size"* ; do
@ -7,7 +7,9 @@ for collection in */ ; do
fileName=$(basename "$image")
imageName="${fileName%.*}"
hash=$(echo -n "$imageName" | sha1sum | awk '{print $1}')
path=$(dirname "$image")/${hash:2:2}/${hash:0:2}
first=$(echo "$hash" | cut -c"$inicio"-"$DIR_LEVELS")
second=$(echo "$hash" | cut -c"$DIR_LEVELS"-"$fin")
path=$(dirname "$image")/${first}/${second}
mkdir -p $path
ln -s "$image" "$fileName"
mv $image $path/$fileName

View File

@ -1,27 +1,29 @@
#!/bin/bash
MIN_DIR_LEVELS=0
DIR_LEVELS=2
START=1
END=3
# Directorio que contiene las carpetas con las fotos
directorio_principal=$1
MAIN_DIR=$1
# Iterar a través de cada carpeta en el directorio principal
for image in "$directorio_principal"/*; do
for image in "$MAIN_DIR"/*; do
# Verificar si es un directorio
# if [ -d "$image" ]; then
# Iterar a través de cada imagen en la subcarpeta
# for image in "$image"/*.png; do
# Verificar si es un archivo
if [ -f "$image" ]; then
# Obtener el nombre de la imagen
fileName=$(basename "$image")
imageName="${fileName%.*}"
hash=$(echo -n "$imageName" | sha1sum | awk '{print $1}')
echo "$(dirname "$image")/${hash:0:2}/${hash:2:2}"
path=$(dirname "$image")/${hash:2:2}/${hash:0:2}
first=$(echo "$hash" | cut -c"$START"-"$DIR_LEVELS")
echo "$first"
second=$(echo "$hash" | cut -c"$DIR_LEVELS"-"$END")
echo "$second"
path=$(dirname "$image")/${first}/${second}
mkdir -p $path
# Crear un enlace simbólico en la carpeta principal
mv $image $path/$fileName
ln -s "$image" "$1/$fileName"
fi
# done