diff --git a/classes/backblaze.php b/classes/backblaze.php index e809483..a995e45 100644 --- a/classes/backblaze.php +++ b/classes/backblaze.php @@ -111,7 +111,10 @@ class Backblaze curl_close ($session); // Clean up $data = json_decode($server_output,true); // Tell me about the rabbits, George! $this->ulURL = $data['uploadUrl']; + //var_dump("upload url at load: ".$data['uploadUrl']); $this->ulToken = $data['authorizationToken']; + + //var_dump($data); } function download($hash) diff --git a/inc/example.config.inc.php b/inc/example.config.inc.php index 122e8ba..8cebf73 100644 --- a/inc/example.config.inc.php +++ b/inc/example.config.inc.php @@ -87,3 +87,11 @@ define('SHOW_ERRORS', false); //define('BACKBLAZE_AUTODOWNLOAD', true); //if true, will download images from backblaze if not found local //define('BACKBLAZE_AUTOUPLOAD', true); //if true, will upload images to backblaze when they are uploaded to pictshare //define('BACKBLAZE_AUTODELETE', true); //if true, will delete images from backblaze if they are deleted from pictshare + +//If you have a NAS or some cifs or nfs mounted drive, you can specify this here as a folder +//if a requested hash is not found locally, its looked up on this location. This allows for mounted external spaces +//or just backups on a second drive. +//Also new hashes will be uploaded there (just the originals, not resizes) +//value should be a path **without tailing slash**! + +define('ALT_FOLDER','/mnt'); \ No newline at end of file diff --git a/models/pictsharemodel.php b/models/pictsharemodel.php index 0a4e015..59645bd 100644 --- a/models/pictsharemodel.php +++ b/models/pictsharemodel.php @@ -94,6 +94,16 @@ class PictshareModel extends Model } $data['hash']=$el; } + else if(defined('ALT_FOLDER') && ALT_FOLDER && $this->couldThisBeAnImage($el)) //check alternative folder for the hash + { + $altname=ALT_FOLDER.DS.$el; + //var_dump($altname); + if(file_exists($altname)) + { + $this->uploadImageFromURL($altname,$el); + $data['hash'] = $el; + } + } else if(BACKBLAZE === true && $this->couldThisBeAnImage($el) && BACKBLAZE_AUTODOWNLOAD ===true) //looks like it might be a hash but didn't find it here. Let's see { $b = new Backblaze(); @@ -211,6 +221,16 @@ class PictshareModel extends Model rmdir($base_path); + //delete from alt folder if configured + if(defined('ALT_FOLDER') && ALT_FOLDER) + { + $altname=ALT_FOLDER.DS.$hash; + if(file_exists($altname)) + { + unlink($altname); + } + } + //delete from backblaze if configured if(BACKBLAZE===true && BACKBLAZE_AUTODELETE===true) { @@ -444,7 +464,7 @@ class PictshareModel extends Model return $this->isTypeAllowed($this->getTypeOfFile($url)); } - function uploadImageFromURL($url) + function uploadImageFromURL($url,$forcehash=false) { $type = $this->getTypeOfFile($url); $type = $this->isTypeAllowed($type); @@ -466,12 +486,12 @@ class PictshareModel extends Model $dup_id = $this->isDuplicate($url); if($dup_id) { - $hash = $dup_id; + $hash = $forcehash?$forcehash:$dup_id; $url = ROOT.DS.'upload'.DS.$hash.DS.$hash; } else { - $hash = $this->getNewHash($type); + $hash = $forcehash?$forcehash:$this->getNewHash($type); $this->saveSHAOfFile($url,$hash); } @@ -497,6 +517,15 @@ class PictshareModel extends Model fclose($fh); } + if(defined('ALT_FOLDER') && ALT_FOLDER) + { + $altname=ALT_FOLDER.DS.$hash; + if(!file_exists($altname)) + { + copy($file,$altname); + } + } + if(BACKBLAZE===true && BACKBLAZE_AUTOUPLOAD===true) { $b = new Backblaze(); @@ -512,6 +541,8 @@ class PictshareModel extends Model { $code = getRandomString(32); $file = ROOT.DS.'upload'.DS.'deletecodes'.DS.$code; + if(!is_dir(ROOT.DS.'upload'.DS.'deletecodes')) + mkdir(ROOT.DS.'upload'.DS.'deletecodes'); if(file_exists($file)) continue; file_put_contents($file,$hash); return $code; diff --git a/tools/altfolder_copy.php b/tools/altfolder_copy.php new file mode 100644 index 0000000..c079890 --- /dev/null +++ b/tools/altfolder_copy.php @@ -0,0 +1,65 @@ +isTypeAllowed($type); + if($type) + { + ++$allhashes; + //$localfiles[] = $hash; + if(file_exists(ALT_FOLDER.DS.$hash)) + { + echo " [!] Skipping $hash because it already exists in ".ALT_FOLDER."\n"; + ++$skips; + } + else + { + ++$copied; + echo "[i] Copying $hash\t to ".ALT_FOLDER.DS.$hash." \r"; + if($sim===false) + copy($img,ALT_FOLDER.DS.$hash); + } + } +} + +echo "\n[i] Done\n"; +echo "\n----------- STATS ----------\n\n"; +echo " All files found:\t$allhashes\n"; +echo " Copied files:\t$copied\n"; +echo " Skipped files:\t$skips\n"; \ No newline at end of file diff --git a/upload/deletecodes/.gitignore b/upload/deletecodes/.gitignore deleted file mode 100755 index 86d0cb2..0000000 --- a/upload/deletecodes/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore \ No newline at end of file