[add] #452 : Better cache dir stucture

This commit is contained in:
Knah Tsaeb 2013-04-02 14:35:14 +02:00
parent 7675edb5de
commit a12c61efea
2 changed files with 20 additions and 13 deletions

View file

@ -15,6 +15,10 @@ randomSleep=`echo $((RANDOM%20))`
optimizeTool='' # external tool form optimize png
maxQueue=50 # max process in queue
currentProcess=$(ps -e | grep -v grep | grep thumb_ | wc -l)
firstLevel=${md5Site:0:2}
secondLevel=${md5Site:2:2}
startPath=$firstLevel/$secondLevel/
mkdir -p "cache/img/$startPath"
if [ ! -f "cache/config/serverOptions.php" ]
then
@ -42,9 +46,9 @@ then
echo 0
errorCode=`echo $(curl -k --write-out %{http_code} --silent -S --connect-timeout $timeOut \--no-keepalive --output /dev/null $site)`
case $errorCode in
000) cp "bin/000.png" "cache/img/$md5Site""_thumb.png" && cp "bin/000.png" "cache/img/$md5Site.png" ;;
404) cp "bin/404.png" "cache/img/$md5Site""_thumb.png" && cp "bin/404.png" "cache/img/$md5Site.png" ;;
*) cp "bin/error.png" "cache/img/$md5Site""_thumb.png" && cp "bin/error.png" "cache/img/$md5Site.png" ;;
000) cp "bin/000.png" "cache/img/$startPath""$md5Site""_thumb.png" && cp "bin/000.png" "cache/img/$startPath""$md5Site.png" ;;
404) cp "bin/404.png" "cache/img/$startPath""$md5Site""_thumb.png" && cp "bin/404.png" "cache/img/$startPath""$md5Site.png" ;;
*) cp "bin/error.png" "cache/img/$startPath""$md5Site""_thumb.png" && cp "bin/error.png" "cache/img/$startPath""$md5Site.png" ;;
esac
if $log
then
@ -56,31 +60,31 @@ then
fi
if [ $onlyThumb == 1 ]
then
convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbSize" "cache/img/$md5Site""_thumb.png"
convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbSize" "cache/img/$startPath""$md5Site""_thumb.png"
if [ $optimizeTool ]
then
eval $optimizeTool "cache/img/$md5Site""_thumb.png"
eval $optimizeTool "cache/img/$startPath""$md5Site""_thumb.png"
fi
else
convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$md5Site.png"
convert "cache/img/$md5Site.png" -filter Lanczos -thumbnail "$thumbSize" "cache/img/$md5Site""_thumb.png"
convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$startPath""$md5Site.png"
convert "cache/img/$startPath""$md5Site.png" -filter Lanczos -thumbnail "$thumbSize" "cache/img/$startPath""$md5Site""_thumb.png"
if [ $optimizeTool ]
then
eval $optimizeTool "cache/img/$md5Site""_thumb.png" "cache/img/$md5Site.png"
eval $optimizeTool "cache/img/$startPath""$md5Site""_thumb.png" "cache/img/$startPath""$md5Site.png"
fi
fi
rm "cache/tmp/$md5Site.png"
if [ $onlyThumb ]
then
if [[ -f "cache/img/$md5Site""_thumb.png" ]]
if [[ -f "cache/img/$startPath""$md5Site""_thumb.png" ]]
then
echo 1
else
echo 0
fi
else
if [[ -f "cache/img/$md5Site""_thumb.png" && -f "cache/img/$md5Site.png" ]]
if [[ -f "cache/img/$startPath""$md5Site""_thumb.png" && -f "cache/img/$startPath""$md5Site.png" ]]
then
echo 1
else

View file

@ -69,7 +69,6 @@ function testExistImg($file) {
}
}
/**
* Run the bash script for generate thumbnail
*
@ -241,7 +240,10 @@ if ($_GET) {
}
$md5Url = md5($defUrl);
$file = 'cache/img/' . $md5Url;
$startPath = substr($md5Url, 0,2).'/'.substr($md5Url, 2,2).'/';
$file = 'cache/img/'.$startPath.$md5Url;
if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
if (isset($ui['iw']) && (int)$ui['iw'] === 1) {
@ -289,7 +291,8 @@ if ($_POST) {
}
$md5Url = md5($defUrl);
$file = 'cache/img/' . $md5Url;
$startPath = substr($md5Url, 0,2).'/'.substr($md5Url, 2,2).'/';
$file = 'cache/img/'.$startPath . $md5Url;
if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
launchScript($defUrl, $md5Url, $width, $GLOBALS['config']['onlyThumb'], true);