mirror of
https://github.com/HaschekSolutions/pictshare.git
synced 2025-11-20 06:58:00 +00:00
fixes #56 and added tool to recalculate all hashes
This commit is contained in:
@@ -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')
|
||||||
|
|||||||
24
tools/recreate_hashlist.php
Normal file
24
tools/recreate_hashlist.php
Normal 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";
|
||||||
Reference in New Issue
Block a user