]> 91.132.146.200 Git - selfpaste.git/commitdiff
moved some logic and addede currect mime type info to response
authorBanana <mail@bananas-playground.net>
Sat, 26 Apr 2025 08:00:48 +0000 (10:00 +0200)
committerBanana <mail@bananas-playground.net>
Sat, 26 Apr 2025 08:00:48 +0000 (10:00 +0200)
Signed-off-by: Banana <mail@bananas-playground.net>
CHANGELOG
webroot/index.php
webroot/view/created.inc.php
webroot/view/view.inc.php
webroot/view/welcome.inc.php

index 42a674ef9f48c6fcb1a2d08c2beeb392e9c2d04c..a70e7d1fa8fba2f8c8d5eb240ea0649e83b2cb1e 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,7 @@ yyyymmdd version 1.x Neon
 * Moved and added settings to config file. See update.txt
 * Better logging
 * Updated client/webclient
+* Setting the correct mime type to responses for the browser. FF had a problem with images.
 
 20231009 version 1.5 Fluorine
 * Maintenance release. Updated requirements to current versions if possible
index 0078112abec32f1462ccbc3a9d1080d2b0e34f7d..c3df6300708feb13b8c755c17c14cee20f60ba30 100644 (file)
@@ -13,7 +13,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see http://www.gnu.org/licenses/gpl-3.0.
  *
- * 2019 - 2023 https://://www.bananas-playground.net/projekt/selfpaste
+ * 2019 - 2025 https://://www.bananas-playground.net/projekt/selfpaste
  */
 
 # Encoding and error reporting setting
@@ -63,61 +63,19 @@ if(isset($_POST['dl']) && !empty($_POST['dl'])
     $_create = true;
 }
 
+# default values
 $contentType = 'Content-type: text/html; charset=UTF-8';
 $contentView = 'welcome';
 $httpResponseCode = 200;
 
 if(!empty($_short)) {
-    $contentType = 'Content-type: text/plain; charset=UTF-8';
     $contentView = 'view';
-    $httpResponseCode = 404;
-    $contentBody = 'File not found.';
-
-    $_t = Summoner::b64sl_unpack_id($_short);
-    $_t = (string)$_t;
-    $_p = Summoner::forwardslashStringToPath($_t);
-    $_requestFile = str_ends_with(SELFPASTE_UPLOAD_DIR,'/') ? SELFPASTE_UPLOAD_DIR : SELFPASTE_UPLOAD_DIR.'/';
-    $_requestFile .= $_p;
-    $_requestFile .= $_t;
-    if(is_readable($_requestFile)) {
-        $contentBody = $_requestFile;
-        $httpResponseCode = 200;
-    }
 }
 elseif ($_create === true) {
     $contentView = 'created';
-    $contentType = 'Content-type:application/json;charset=utf-8';
-    $httpResponseCode = 400;
-    $_message = 'Something went wrong.';
-
-    $_file = $_FILES['pasty'];
-
-    $_fileObj = new Mancubus();
-    if($_fileObj->load($_FILES['pasty']) === true) {
-        $_fileObj->setSaveFilename();
-        $_fileObj->setShort();
-        $_fileObj->setStoragePath();
-        $_fileObj->setShortURL();
-
-        $_do = $_fileObj->process();
-        $_message = $_do['message'];
-        if($_do['status'] === true) {
-            $httpResponseCode = 200;
-            if(defined('LOG_CREATION') && LOG_CREATION === true) {
-                Summoner::createLog($_message." ".SELFPASTE_UPLOAD_SECRET[$_POST['dl']]);
-            }
-        }
-    }
-
-    $contentBody = array(
-        'message' => $_message,
-        'status' => $httpResponseCode
-    );
 }
 
-header('X-PROVIDED-BY: selfpaste');
-header($contentType);
-http_response_code($httpResponseCode);
+header('X-Provided-By: selfpaste');
 if(file_exists('view/'.$contentView.'.inc.php')) {
     require_once 'view/'.$contentView.'.inc.php';
 }
index e4a0c30afe44acd70bf79481189d5bf87ff25b80..e9933cb23e1f71766d4022c69c2c5c56f95daf87 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see http://www.gnu.org/licenses/gpl-3.0.
  *
- * 2019 - 2023 https://://www.bananas-playground.net/projekt/selfpaste
+ * 2019 - 2025 https://://www.bananas-playground.net/projekt/selfpaste
  */
-echo json_encode($contentBody)."\n";
+$contentType = 'Content-type:application/json;charset=utf-8';
+$httpResponseCode = 400;
+$_message = 'Something went wrong.';
+
+$_file = $_FILES['pasty'];
+
+$_fileObj = new Mancubus();
+if($_fileObj->load($_FILES['pasty']) === true) {
+    $_fileObj->setSaveFilename();
+    $_fileObj->setShort();
+    $_fileObj->setStoragePath();
+    $_fileObj->setShortURL();
+
+    $_do = $_fileObj->process();
+    $_message = $_do['message'];
+    if($_do['status'] === true) {
+        $httpResponseCode = 200;
+        if(defined('LOG_CREATION') && LOG_CREATION === true) {
+            Summoner::createLog($_message." ".SELFPASTE_UPLOAD_SECRET[$_POST['dl']]);
+        }
+    }
+}
+
+http_response_code($httpResponseCode);
+header('Content-type:application/json;charset=utf-8');
+echo json_encode(array(
+        'message' => $_message,
+        'status' => $httpResponseCode))."\n";
index d83e83e47b1b5f17ff3926c083cf84dd0e8362bc..2f1e8b460e9ba3851dc470786fa551b2dda6ca92 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see http://www.gnu.org/licenses/gpl-3.0.
  *
- * 2019 - 2023 https://://www.bananas-playground.net/projekt/selfpaste
+ * 2019 - 2025 https://://www.bananas-playground.net/projekt/selfpaste
  */
-if (file_exists($contentBody)) {
+
+$_t = Summoner::b64sl_unpack_id($_short);
+$_t = (string)$_t;
+$_p = Summoner::forwardslashStringToPath($_t);
+$_requestFile = str_ends_with(SELFPASTE_UPLOAD_DIR,'/') ? SELFPASTE_UPLOAD_DIR : SELFPASTE_UPLOAD_DIR.'/';
+$_requestFile .= $_p;
+$_requestFile .= $_t;
+if(is_readable($_requestFile)) {
+    $finfo = finfo_open(FILEINFO_MIME_TYPE);
+    $mime = finfo_file($finfo, $_requestFile);
+    finfo_close($finfo);
+
+    http_response_code(200);
+    header('Content-type: '.$mime);
     header('Expires: 0');
     header('Cache-Control: must-revalidate');
     header('Pragma: public');
-    readfile($contentBody);
-    exit;
-}
-else {
-    echo $contentBody;
+    readfile($_requestFile);
+} else {
+    http_response_code(404);
+    header('Content-type: text/plain; charset=UTF-8');
+    $contentBody = 'File not found.';
 }
index 4fe7eecb9c126f43c8c401c16be62f3b75a9c36f..5d0e7de4f66688654135e0a737549ed18ee1d5bb 100644 (file)
@@ -13,8 +13,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see http://www.gnu.org/licenses/gpl-3.0.
  *
- * 2019 - 2023 https://://www.bananas-playground.net/projekt/selfpaste
+ * 2019 - 2025 https://://www.bananas-playground.net/projekt/selfpaste
  */
+header('Content-type: text/html; charset=UTF-8');
 ?>
 <!DOCTYPE HTML>
 <html lang="en">