fixes #56 and added tool to recalculate all hashes

This commit is contained in:
Chris
2018-06-15 20:30:00 +02:00
parent 5792bf06e2
commit eefaaf1643
2 changed files with 36 additions and 10 deletions

View File

@@ -452,6 +452,17 @@ class PictshareModel extends Model
if(!$type) if(!$type)
return array('status'=>'ERR','reason'=>'wrong filetype'); return array('status'=>'ERR','reason'=>'wrong filetype');
$tempfile = ROOT.DS.'tmp'.DS.md5(rand(1,999)*rand(0,10000)+time());
file_put_contents($tempfile, file_get_contents($url));
//remove all exif data from jpeg
if($type=='jpg')
{
$res = imagecreatefromjpeg($tempfile);
imagejpeg($res, $tempfile, (defined('JPEG_COMPRESSION')?JPEG_COMPRESSION:90));
}
$url = $tempfile;
$dup_id = $this->isDuplicate($url); $dup_id = $this->isDuplicate($url);
if($dup_id) if($dup_id)
{ {
@@ -464,9 +475,6 @@ class PictshareModel extends Model
$this->saveSHAOfFile($url,$hash); $this->saveSHAOfFile($url,$hash);
} }
if($dup_id) if($dup_id)
return array('status'=>'OK','type'=>$type,'hash'=>$hash,'url'=>DOMAINPATH.PATH.$hash,'domain'=>DOMAINPATH); return array('status'=>'OK','type'=>$type,'hash'=>$hash,'url'=>DOMAINPATH.PATH.$hash,'domain'=>DOMAINPATH);
@@ -474,13 +482,7 @@ class PictshareModel extends Model
$file = ROOT.DS.'upload'.DS.$hash.DS.$hash; $file = ROOT.DS.'upload'.DS.$hash.DS.$hash;
file_put_contents($file, file_get_contents($url)); file_put_contents($file, file_get_contents($url));
unlink($tempfile);
//remove all exif data from jpeg
if($type=='jpg')
{
$res = imagecreatefromjpeg($file);
imagejpeg($res, $file, (defined('JPEG_COMPRESSION')?JPEG_COMPRESSION:90));
}
//re-render new mp4 by calling the re-encode script //re-render new mp4 by calling the re-encode script
if($type=='mp4' && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') if($type=='mp4' && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')

View File

@@ -0,0 +1,24 @@
<?php
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__).DS.'..');
echo "[i] Starting recreation of hashes.csv\n";
$dir = ROOT.DS.'upload'.DS;
$dh = opendir($dir);
$fp = fopen($dir.'hashes.csv','w');
if(!$fp)
exit("[X] Can't open hashes.csv to write");
while (false !== ($hash = readdir($dh))) {
$img = $dir.$hash.DS.$hash;
if(!file_exists($img) || $hash=='.' || $hash=='..') continue;
echo " [s] Calculating $hash\n";
$sha1 = sha1_file($img);
fwrite($fp,"$sha1;$hash\n");
}
fclose($fp);
echo "[i] Finished\n";