Skip to content
Extraits de code Groupes Projets
Valider e270df41 rédigé par Elliu's avatar Elliu
Parcourir les fichiers

Add env STPKG_TRUST_SOURCE to not convert given files

Conversion is still done to png if given file is not png of gif
parent 16802f9a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -161,17 +161,21 @@ validate_homeserv() { ...@@ -161,17 +161,21 @@ validate_homeserv() {
file_get_width() { file_get_width() {
local WIDTH=$(identify -format "%w" "$1[0]") >/dev/null local WIDTH=$(identify -format "%w" "$1[0]") >/dev/null
local WIDTH=$(( $WIDTH > 256 ? 256 : $WIDTH )) if [ "x$STPKG_TRUST_SOURCE" = "x" ]; then
local WIDTH=$(( $WIDTH > 256 ? 256 : $WIDTH ))
fi
echo "$WIDTH" echo "$WIDTH"
} }
file_get_height() { file_get_height() {
local HEIGHT=$(identify -format "%h" "$1[0]") >/dev/null local HEIGHT=$(identify -format "%h" "$1[0]") >/dev/null
local HEIGHT=$(( $HEIGHT > 256 ? 256 : $HEIGHT )) if [ "x$STPKG_TRUST_SOURCE" = "x" ]; then
local WIDTH=$(( $WIDTH > 256 ? 256 : $WIDTH ))
fi
echo "$HEIGHT" echo "$HEIGHT"
} }
file_get_type() { [[ "$1" == *.gif ]] && echo 'gif' || echo 'png'; } file_get_type() { xdg-mime query filetype "$1" | sed 's+^.*/++'; }
file_get_name() { echo "$1" | cut -f1 -d'.'; } file_get_name() { echo "$1" | cut -f1 -d'.'; }
upload_file() { upload_file() {
...@@ -187,13 +191,18 @@ upload_file() { ...@@ -187,13 +191,18 @@ upload_file() {
picture_process_sticker() { picture_process_sticker() {
# NOTE: This command will display some progress dots... # NOTE: This command will display some progress dots...
local FILE=$1 # The source file
local FILE=$1 # The source file local DEST=$2 # The destination file
local DEST=$2 # The destination file local NAME=$3 # The pretty name of the sticker
local NAME=$3 # The pretty name of the sticker local WIDTH=$4 # The WIDTH!
local WIDTH=$4 # The WIDTH! local HEIGHT=$5 # The HEIGHT!
local HEIGHT=$5 # The HEIGHT! local TYPE=$6 # The type of the file (png/gif/webp)
local TYPE=$6 # The type of the file (png/gif) local DSTTYPE=$7 # The type of the destination file (png/gif)
if [ "x$STPKG_TRUST_SOURCE" != "x" ] && [ "$TYPE" == "$DSTTYPE" ]; then
cp "$FILE" "$DEST"
return
fi
local repage=`[ "x${TYPE}" != "xgif" ] && echo '+repage' || echo ''` local repage=`[ "x${TYPE}" != "xgif" ] && echo '+repage' || echo ''`
local resize=`[ "x${TYPE}" != "xgif" ] && echo "-resize ${WIDTH}x${HEIGHT}" || echo ''` local resize=`[ "x${TYPE}" != "xgif" ] && echo "-resize ${WIDTH}x${HEIGHT}" || echo ''`
...@@ -598,13 +607,18 @@ __edit() { ...@@ -598,13 +607,18 @@ __edit() {
local HEIGHT=$(file_get_height "$FILE") local HEIGHT=$(file_get_height "$FILE")
local TYPE=$(file_get_type "$FILE") local TYPE=$(file_get_type "$FILE")
local NAME=$(file_get_name "$FILE") local NAME=$(file_get_name "$FILE")
local DEST=$(mktemp --suffix=".$TYPE") if [ "x$TYPE" == "xwebp" ]; then
local DSTTYPE="png"
else
local DSTTYPE="$TYPE"
fi
local DEST=$(mktemp --suffix=".$DSTTYPE")
picture_process_sticker "$FILE" "$DEST" "$NAME" "$WIDTH" "$HEIGHT" "$TYPE" # Transform sticker picture (see __pack) picture_process_sticker "$FILE" "$DEST" "$NAME" "$WIDTH" "$HEIGHT" "$TYPE" "$DSTTYPE" # Transform sticker picture (see __pack)
local MXC=$(upload_file "$TYPE" "$DEST" "$NAME") # Upload transformed file (see __pack) local MXC=$(upload_file "$DSTTYPE" "$DEST" "$NAME") # Upload transformed file (see __pack)
jq "del(.stickers[] | select(.body == \"$STICKER_NAME\"))" < "$TEMP" | sponge "$TEMP" jq "del(.stickers[] | select(.body == \"$STICKER_NAME\"))" < "$TEMP" | sponge "$TEMP"
local ST_JSON=$(create_sticker_json "$PACK_NAME" "$NAME" "$WIDTH" "$HEIGHT" "$TYPE" "$MXC") local ST_JSON=$(create_sticker_json "$PACK_NAME" "$NAME" "$WIDTH" "$HEIGHT" "$DSTTYPE" "$MXC")
jq ".stickers += [$ST_JSON]" < $TEMP | sponge $TEMP jq ".stickers += [$ST_JSON]" < $TEMP | sponge $TEMP
;; ;;
...@@ -718,20 +732,25 @@ __pack() { ...@@ -718,20 +732,25 @@ __pack() {
# Get the names and extentions # Get the names and extentions
local TYPE=$(file_get_type "$FILE") local TYPE=$(file_get_type "$FILE")
local NAME=$(file_get_name "$FILE") local NAME=$(file_get_name "$FILE")
local DEST="$DEST_FOLDER/$NAME.$TYPE" if [ "x$TYPE" != "xgif" ] && [ "x$TYPE" != "xpng" ]; then
local DSTTYPE="png"
else
local DSTTYPE="$TYPE"
fi
local DEST="$DEST_FOLDER/$NAME.$DSTTYPE"
# For the progress # For the progress
progress "($CURRENT_FILE/$TOTAL_FILES) $NAME " progress "($CURRENT_FILE/$TOTAL_FILES) $NAME "
local CURRENT_FILE=$[ $CURRENT_FILE + 1 ] local CURRENT_FILE=$[ $CURRENT_FILE + 1 ]
# Transform sticker source picture # Transform sticker source picture
picture_process_sticker "$FILE" "$DEST" "$NAME" "$WIDTH" "$HEIGHT" "$TYPE" picture_process_sticker "$FILE" "$DEST" "$NAME" "$WIDTH" "$HEIGHT" "$TYPE" "$DSTTYPE"
# Add a ',' only if it's not the first in the array # Add a ',' only if it's not the first in the array
echo -n "$FIRST_IN_ARRAY" >> $DEST_INDEX echo -n "$FIRST_IN_ARRAY" >> $DEST_INDEX
# Upload the transformed file # Upload the transformed file
local MXC=$(upload_file "$TYPE" "$DEST" "$NAME") local MXC=$(upload_file "$DSTTYPE" "$DEST" "$NAME")
progress_dot progress_dot
# Calculate the 128x128 format # Calculate the 128x128 format
...@@ -742,12 +761,12 @@ __pack() { ...@@ -742,12 +761,12 @@ __pack() {
local HEIGHT=$(identify -format "%h" "$DEST[0]") >/dev/null local HEIGHT=$(identify -format "%h" "$DEST[0]") >/dev/null
# Add the sticker to the index file # Add the sticker to the index file
create_sticker_json "$PACK_NAME" "$NAME" "$WIDTH" "$HEIGHT" "$TYPE" "$MXC" >> $DEST_INDEX create_sticker_json "$PACK_NAME" "$NAME" "$WIDTH" "$HEIGHT" "$DSTTYPE" "$MXC" >> $DEST_INDEX
# For the report # For the report
[ "x$FIRST_IN_ARRAY" = "x" ] && echo -e "StickerName MXC Type Width Height" [ "x$FIRST_IN_ARRAY" = "x" ] && echo -e "StickerName MXC Type Width Height"
local FIRST_IN_ARRAY="," local FIRST_IN_ARRAY=","
echo -e "$NAME ($MXC) $TYPE $INIT_WIDTH $INIT_HEIGHT" echo -e "$NAME ($MXC) $DSTTYPE $INIT_WIDTH $INIT_HEIGHT"
progress_reset progress_reset
done | column -t done | column -t
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter