diff --git a/README.md b/README.md index 39e691c..803efc6 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ PictShare is a selfhostable, open source image, video and text hosting as well a [![Apache License](https://img.shields.io/badge/license-Apache-blue.svg?style=flat)](https://github.com/HaschekSolutions/pictshare/blob/master/LICENSE) # This is the development branch for Version 2 do not use in production +Test site: https://dev.pictshare.net/ (only sometimes on) ## New Features in v2: diff --git a/api/pastebin.php b/api/pastebin.php new file mode 100644 index 0000000..2d8ee31 --- /dev/null +++ b/api/pastebin.php @@ -0,0 +1,39 @@ +'err','reason'=>'Data directory not writable'))); +else if(!isFolderWritable(ROOT.DS.'tmp')) + exit(json_encode(array('status'=>'err','reason'=>'Temp directory not writable'))); + +// check for POSTed text +if($_REQUEST['api_paste_code']) +{ + $hash = getNewHash('txt',$length=10); + $tmpfile = ROOT.DS.'tmp'.DS.$hash; + file_put_contents($tmpfile,$_REQUEST['api_paste_code']); + + //check if this exact paste already exists + $sha1 = sha1_file($tmpfile); + $sha_hash = sha1Exists($sha1); + if($sha_hash) + exit(URL.$sha_hash); + + $answer = (new TextController())->handleUpload($tmpfile,$hash); + if($answer['hash']) + addSha1($answer['hash'],$sha1); + + echo URL.$hash; +} \ No newline at end of file diff --git a/controllers/image/image.controller.php b/controllers/image/image.controller.php index c58968f..28f7724 100644 --- a/controllers/image/image.controller.php +++ b/controllers/image/image.controller.php @@ -53,7 +53,8 @@ class ImageController mkdir(ROOT.DS.'data'.DS.$hash); $file = ROOT.DS.'data'.DS.$hash.DS.$hash; - move_uploaded_file($tmpfile, $file); + copy($tmpfile, $file); + unlink($tmpfile); if(defined('ALT_FOLDER') && ALT_FOLDER) { diff --git a/controllers/text/text.controller.php b/controllers/text/text.controller.php index 2ea77bf..002ad6b 100644 --- a/controllers/text/text.controller.php +++ b/controllers/text/text.controller.php @@ -40,7 +40,8 @@ class TextController } else { - $hash.='.txt'; + if(!endswith($hash,'.txt')) + $hash.='.txt'; if(isExistingHash($hash)) return array('status'=>'err','reason'=>'Custom hash already exists'); } @@ -48,7 +49,8 @@ class TextController mkdir(ROOT.DS.'data'.DS.$hash); $file = ROOT.DS.'data'.DS.$hash.DS.$hash; - move_uploaded_file($tmpfile, $file); + copy($tmpfile, $file); + unlink($tmpfile); if(defined('ALT_FOLDER') && ALT_FOLDER) { diff --git a/controllers/video/video.controller.php b/controllers/video/video.controller.php index b4bee55..1439609 100644 --- a/controllers/video/video.controller.php +++ b/controllers/video/video.controller.php @@ -75,7 +75,8 @@ class VideoController mkdir(ROOT.DS.'data'.DS.$hash); $file = ROOT.DS.'data'.DS.$hash.DS.$hash; - move_uploaded_file($tmpfile, $file); + copy($tmpfile, $file); + unlink($tmpfile); if(!$this->rightEncodedMP4($file)) system("nohup php ".ROOT.DS.'tools'.DS.'re-encode_mp4.php force '.$hash." > /dev/null 2> /dev/null &"); diff --git a/rtfm/PASTEBINIT.md b/rtfm/PASTEBINIT.md new file mode 100644 index 0000000..a930d5e --- /dev/null +++ b/rtfm/PASTEBINIT.md @@ -0,0 +1,25 @@ +# How to use Pictshare text upload with pastebinit + +1. Install [pastebinit](https://help.ubuntu.com/community/Pastebinit) +2. Create a file in /usr/share/pastebinit.d/ called "pictshare.net.conf" +3. Paste the following lines in this new file: + +``` +[pastebin] +basename = pictshare.net +regexp = https://pictshare.net +https = true + +[format] +content = api_paste_code +page = page +regexp = regexp + +[defaults] +page = /api/pastebin.php +regexp = (.*) +``` + +Now you should be able to use pastebinit like this: ```echo "hello world" | pastebinit -b pictshare.net``` + +If you want to use pictshare as your default you can either make an alias or edit ```/usr/bin/pastebinit``` and set ```defaultPB = "pictshare.net"``` \ No newline at end of file