]> jfr.im git - uguu.git/commitdiff
replace name generator method v.1.8.5
authorGo Johansson (neku) <redacted>
Sat, 13 Apr 2024 09:21:27 +0000 (11:21 +0200)
committerGo Johansson (neku) <redacted>
Sat, 13 Apr 2024 09:21:27 +0000 (11:21 +0200)
14 files changed:
.gitignore
README.md
package.json
src/Classes/Connector.php
src/Classes/CuteGrills.php
src/Classes/Database.php
src/Classes/GrillLoader.php
src/Classes/Response.php
src/Classes/Upload.php
src/Classes/expireChecker.php
src/config.json
src/static/php/checkExpire.php
src/static/php/grill.php
src/static/php/upload.php

index 8b1543ca7ade529f7ceaaf43ec6ae09167756294..3873c71d3297140d386b4e9f9c9c053015a9ebbc 100644 (file)
@@ -13,3 +13,4 @@ composer.lock
 docker/uguuForDocker.tar.gz
 !/.php-cs-fixer.cache
 test.php
+.php-cs-fixer.cache
index cd1b118811434260e3345d385c59d736b8e1820b..1d145431bad30699fb028065504403cb416a17be 100755 (executable)
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ See the real world site at [uguu.se](https://uguu.se).
 
 ## Requirements
 
-Tested and working with Nginx + PHP-8.1 + SQLite/MySQL/PostgreSQL + Node.js 18 or higher.
+Tested and working with Nginx + PHP-8.3 + SQLite/MySQL/PostgreSQL + Node.js 18 or higher.
 
 Node.js is used to compile Uguu, after that it runs on PHP.
 
@@ -47,19 +47,13 @@ Hit me up at [@nekunekus](https://twitter.com/nekunekus) or email me at neku@pom
 
 We'd really like if you can take some time to make sure your coding style is
 consistent with the project. Uguu follows [PHP
-PSR-12](https://www.php-fig.org/psr/psr-12/) and [Airbnb JavaScript
+PSR-2](https://www.php-fig.org/psr/psr-12/) and [Airbnb JavaScript
 (ES5)](https://github.com/airbnb/javascript/tree/es5-deprecated/es5) (`airbnb/legacy`)
 coding style guides. We use ESLint and PHPCS tools to enforce these standards.
 
 You can also help by sending us feature requests or writing documentation and
 tests.
 
-## Upcoming Features
-
-* S3 Bucket Support
-* Azure File Storage Support
-* Temporal/RR Support
-
 ## Credits
 
 Uguu is based on [Pomf](http://github.com/pomf/pomf) which was written by Emma Lejack & Go Johansson (nekunekus (nokonoko)) and with help from the open source community.
index fb48f9bce8724060ab869b38c1dc0155f09f441c..243e60cd3ca1d73c82ffb5490475ab319a9c594b 100755 (executable)
@@ -1,6 +1,6 @@
 {
   "name": "uguu",
-  "version": "1.8.4",
+  "version": "1.8.5",
   "description": "Uguu is a simple lightweight temporary file host with support for drop, paste, click and API uploading.",
   "homepage": "https://uguu.se",
   "repository": {
index b22e9937bd8567b19253b119c1a3778601964ea7..9c5715d4cb63c43427037fc3dd6e4c5dab376559 100755 (executable)
@@ -1,87 +1,90 @@
 <?php
-    /*
-     * Uguu
-     *
-     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
-     *
-     * Note that this was previously distributed under the MIT license 2015-2022.
-     *
-     * If you are a company that wants to use Uguu I urge you to contact me to
-     * solve any potential license issues rather then using pre-2022 code.
-     *
-     * A special thanks goes out to the open source community around the world
-     * for supporting and being the backbone of projects like Uguu.
-     *
-     * This project can be found at <https://github.com/nokonoko/Uguu>.
-     *
-     * This program is free software: you can redistribute it and/or modify
-     * it under the terms of the GNU General Public License as published by
-     * the Free Software Foundation, either version 3 of the License, or
-     * (at your option) any later version.
-     *
-     * This program is distributed in the hope that it will be useful,
-     * but WITHOUT ANY WARRANTY; without even the implied warranty of
-     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-     * GNU General Public License for more details.
-     *
-     * You should have received a copy of the GNU General Public License
-     * along with this program.  If not, see <https://www.gnu.org/licenses/>.
-     */
-    
-    namespace Pomf\Uguu\Classes;
-    
-    use PDO;
-    
-    class Connector extends Database
+/*
+ * Uguu
+ *
+ * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+ *
+ * Note that this was previously distributed under the MIT license 2015-2022.
+ *
+ * If you are a company that wants to use Uguu I urge you to contact me to
+ * solve any potential license issues rather then using pre-2022 code.
+ *
+ * A special thanks goes out to the open source community around the world
+ * for supporting and being the backbone of projects like Uguu.
+ *
+ * This project can be found at <https://github.com/nokonoko/Uguu>.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+namespace Pomf\Uguu\Classes;
+
+use PDO;
+use Random\Randomizer;
+
+class Connector extends Database
+{
+    public PDO $DB;
+    public string $dbType;
+    public array $CONFIG;
+    public Response $response;
+    public Randomizer $randomizer;
+        
+    public function errorHandler(int $errno, string $errstr):void
     {
-        public PDO $DB;
-        public string $dbType;
-        public array $CONFIG;
-        public Response $response;
+        if ($this->CONFIG['DEBUG']) {
+            $this->response->error(500, 'Server error: ' . $errstr);
+        } else {
+            $this->response->error(500, 'Server error.');
+        }
+    }
         
-        public function errorHandler(int $errno, string $errstr):void
-        {
+    public function fatalErrorHandler():void
+    {
+        if (!is_null($e = error_get_last())) {
             if ($this->CONFIG['DEBUG']) {
-                $this->response->error(500, 'Server error: ' . $errstr);
+                $this->response->error(500, 'FATAL Server error: ' . print_r($e, true));
             } else {
                 $this->response->error(500, 'Server error.');
             }
         }
+    }
         
-        public function fatalErrorHandler():void
-        {
-            if (!is_null($e = error_get_last())) {
-                if ($this->CONFIG['DEBUG']) {
-                    $this->response->error(500, 'FATAL Server error: ' . print_r($e, true));
-                } else {
-                    $this->response->error(500, 'Server error.');
-                }
-            }
-        }
-        
-        /**
-         * Reads the config.json file and populates the CONFIG property with the settings
-         * Also assembles the PDO DB connection and registers error handlers.
-         *
-         */
-        public function __construct()
-        {
-            $this->response = new Response('json');
-            if (!file_exists(__DIR__ . '/../config.json')) {
-                $this->response->error(500, 'Cant read settings file.');
-            }
-            $this->CONFIG = json_decode(
-               file_get_contents(__DIR__ . '/../config.json'),
-               true,
-            );
-            ini_set('display_errors', 0);
-            set_error_handler([$this, "errorHandler"]);
-            register_shutdown_function([$this, "fatalErrorHandler"]);
-            $this->dbType = $this->CONFIG['DB_MODE'];
-            $this->DB = new PDO(
-               $this->CONFIG['DB_MODE'] . ':' . $this->CONFIG['DB_PATH'],
-               $this->CONFIG['DB_USER'],
-               $this->CONFIG['DB_PASS'],
-            );
+    /**
+     * Reads the config.json file and populates the CONFIG property with the settings
+     * Also assembles the PDO DB connection and registers error handlers.
+     *
+     */
+    public function __construct()
+    {
+        $this->response = new Response('json');
+        if (!file_exists(__DIR__ . '/../config.json')) {
+            $this->response->error(500, 'Cant read settings file.');
         }
-    }
\ No newline at end of file
+        $this->CONFIG = json_decode(
+            file_get_contents(__DIR__ . '/../config.json'),
+            true,
+        );
+        ini_set('display_errors', 0);
+        set_error_handler([$this, "errorHandler"]);
+        register_shutdown_function([$this, "fatalErrorHandler"]);
+        $this->dbType = $this->CONFIG['DB_MODE'];
+        $this->DB = new PDO(
+            $this->CONFIG['DB_MODE'] . ':' . $this->CONFIG['DB_PATH'],
+            $this->CONFIG['DB_USER'],
+            $this->CONFIG['DB_PASS'],
+        );
+        $this->randomizer = new Randomizer();
+    }
+}
index 42ec149b867f696e2344c117792adea77a0189c7..4f51fe71b6cde0009ca10c65ee2056a12923cf87 100755 (executable)
@@ -1,60 +1,60 @@
 <?php
-    /*
-     * Uguu
-     *
-     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
-     *
-     * Note that this was previously distributed under the MIT license 2015-2022.
-     *
-     * If you are a company that wants to use Uguu I urge you to contact me to
-     * solve any potential license issues rather then using pre-2022 code.
-     *
-     * A special thanks goes out to the open source community around the world
-     * for supporting and being the backbone of projects like Uguu.
-     *
-     * This project can be found at <https://github.com/nokonoko/Uguu>.
-     *
-     * This program is free software: you can redistribute it and/or modify
-     * it under the terms of the GNU General Public License as published by
-     * the Free Software Foundation, either version 3 of the License, or
-     * (at your option) any later version.
-     *
-     * This program is distributed in the hope that it will be useful,
-     * but WITHOUT ANY WARRANTY; without even the implied warranty of
-     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-     * GNU General Public License for more details.
-     *
-     * You should have received a copy of the GNU General Public License
-     * along with this program.  If not, see <https://www.gnu.org/licenses/>.
-     */
-    
-    namespace Pomf\Uguu\Classes;
+/*
+ * Uguu
+ *
+ * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+ *
+ * Note that this was previously distributed under the MIT license 2015-2022.
+ *
+ * If you are a company that wants to use Uguu I urge you to contact me to
+ * solve any potential license issues rather then using pre-2022 code.
+ *
+ * A special thanks goes out to the open source community around the world
+ * for supporting and being the backbone of projects like Uguu.
+ *
+ * This project can be found at <https://github.com/nokonoko/Uguu>.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
     
-    class CuteGrills
-    {
-        public array $GRILLS;
+namespace Pomf\Uguu\Classes;
+
+class CuteGrills
+{
+    public array $GRILLS;
         
-        /**
-         * Loads the list of grills, then redirects to a random grill
-         */
-        public function showGrills():void
-        {
-            $this->loadGrills();
-            if (!headers_sent()) {
-                header(
-                   'Location: /img/grills/' .
+    /**
+     * Loads the list of grills, then redirects to a random grill
+     */
+    public function showGrills():void
+    {
+        $this->loadGrills();
+        if (!headers_sent()) {
+            header(
+                'Location: /img/grills/' .
                    $this->GRILLS[array_rand($this->GRILLS)],
-                   true,
-                   303,
-                );
-            }
+                true,
+                303,
+            );
         }
+    }
         
-        /**
-         * Loads the images from the `img/grills/` directory into the `GRILLS` array
-         */
-        public function loadGrills():void
-        {
-            $this->GRILLS = array_slice(scandir('img/grills/'), 2);
-        }
+    /**
+     * Loads the images from the `img/grills/` directory into the `GRILLS` array
+     */
+    public function loadGrills():void
+    {
+        $this->GRILLS = array_slice(scandir('img/grills/'), 2);
     }
+}
index 482ab672092ae4fbefecee878bcfd014ba8040d2..0d73e79ade0114aab3000f9cfe60cdced0d730af 100755 (executable)
 <?php
-    /*
    * Uguu
    *
    * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
    *
    * Note that this was previously distributed under the MIT license 2015-2022.
    *
    * If you are a company that wants to use Uguu I urge you to contact me to
    * solve any potential license issues rather then using pre-2022 code.
    *
    * A special thanks goes out to the open source community around the world
    * for supporting and being the backbone of projects like Uguu.
    *
    * This project can be found at <https://github.com/nokonoko/Uguu>.
    *
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program.  If not, see <https://www.gnu.org/licenses/>.
    */
+/*
+ * Uguu
+ *
+ * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+ *
+ * Note that this was previously distributed under the MIT license 2015-2022.
+ *
+ * If you are a company that wants to use Uguu I urge you to contact me to
+ * solve any potential license issues rather then using pre-2022 code.
+ *
+ * A special thanks goes out to the open source community around the world
+ * for supporting and being the backbone of projects like Uguu.
+ *
+ * This project can be found at <https://github.com/nokonoko/Uguu>.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
     
-    namespace Pomf\Uguu\Classes;
+namespace Pomf\Uguu\Classes;
+
+use PDO;
     
-    use PDO;
-    
-    class Database
+class Database
+{
+    public function dbCheckNameExists(string $name):bool
     {
-        public function dbCheckNameExists(string $name):bool
-        {
-            $query = match ($this->dbType) {
-                'pgsql' => 'SELECT EXISTS(SELECT id FROM files WHERE filename = (:name)), filename FROM files WHERE filename = (:name) LIMIT 1',
-                default => 'SELECT filename FROM files WHERE filename = (:name) AND EXISTS (SELECT id FROM files WHERE filename = (:name)) LIMIT 1'
-            };
-            $q = $this->DB->prepare($query);
-            $q->bindValue(':name', $name);
-            $q->execute();
-            $result = $q->fetch();
-            $q->closeCursor();
-            if (isset($result['exists']) and $result['exists']) {
-                return true;
-            } elseif ($result) {
-                return true;
-            }
-            return false;
+        $query = match ($this->dbType) {
+            'pgsql' => 'SELECT EXISTS(SELECT id FROM files WHERE filename = (:name)), filename FROM files WHERE filename = (:name) LIMIT 1',
+            default => 'SELECT filename FROM files WHERE filename = (:name) AND EXISTS (SELECT id FROM files WHERE filename = (:name)) LIMIT 1'
+        };
+        $q = $this->DB->prepare($query);
+        $q->bindValue(':name', $name);
+        $q->execute();
+        $result = $q->fetch();
+        $q->closeCursor();
+        if (isset($result['exists']) and $result['exists']) {
+            return true;
+        } elseif ($result) {
+            return true;
         }
+        return false;
+    }
         
-        public function checkFileBlacklist(string $hash):void
-        {
-            $query = match ($this->dbType) {
-                'pgsql' => 'SELECT EXISTS(SELECT id FROM blacklist WHERE hash = (:hash)), hash FROM blacklist WHERE hash = (:hash) LIMIT 1',
-                default => 'SELECT id FROM blacklist WHERE EXISTS(SELECT id FROM blacklist WHERE hash = (:hash)) LIMIT 1'
-            };
-            $q = $this->DB->prepare($query);
-            $q->bindValue(':hash', $hash);
-            $q->execute();
-            $result = $q->fetch();
-            $q->closeCursor();
-            if (isset($result['exists']) and $result['exists']) {
-                $this->response->error(415, 'File blacklisted.');
-            } elseif ($result) {
-                $this->response->error(415, 'File blacklisted.');
-            }
+    public function checkFileBlacklist(string $hash):void
+    {
+        $query = match ($this->dbType) {
+            'pgsql' => 'SELECT EXISTS(SELECT id FROM blacklist WHERE hash = (:hash)), hash FROM blacklist WHERE hash = (:hash) LIMIT 1',
+            default => 'SELECT id FROM blacklist WHERE EXISTS(SELECT id FROM blacklist WHERE hash = (:hash)) LIMIT 1'
+        };
+        $q = $this->DB->prepare($query);
+        $q->bindValue(':hash', $hash);
+        $q->execute();
+        $result = $q->fetch();
+        $q->closeCursor();
+        if (isset($result['exists']) and $result['exists']) {
+            $this->response->error(415, 'File blacklisted.');
+        } elseif ($result) {
+            $this->response->error(415, 'File blacklisted.');
         }
+    }
         
-        public function antiDupe(string $hash):array
-        {
-            $query = match ($this->dbType) {
-                'pgsql' => 'SELECT EXISTS(SELECT id FROM files WHERE hash = (:hash)), filename FROM files WHERE hash = (:hash) LIMIT 1',
-                default => 'SELECT filename FROM files WHERE hash = (:hash) AND EXISTS (SELECT id FROM files WHERE hash = (:hash)) LIMIT 1'
-            };
-            $q = $this->DB->prepare($query);
-            $q->bindValue(':hash', $hash);
-            $q->execute();
-            $result = $q->fetch();
-            $q->closeCursor();
-            if (!$result) {
-                return [
-                   'result' => false,
-                ];
-            } else {
-                return [
-                   'result' => true,
-                   'name'   => $result['filename'],
-                ];
-            }
+    public function antiDupe(string $hash):array
+    {
+        $query = match ($this->dbType) {
+            'pgsql' => 'SELECT EXISTS(SELECT id FROM files WHERE hash = (:hash)), filename FROM files WHERE hash = (:hash) LIMIT 1',
+            default => 'SELECT filename FROM files WHERE hash = (:hash) AND EXISTS (SELECT id FROM files WHERE hash = (:hash)) LIMIT 1'
+        };
+        $q = $this->DB->prepare($query);
+        $q->bindValue(':hash', $hash);
+        $q->execute();
+        $result = $q->fetch();
+        $q->closeCursor();
+        if (!$result) {
+            return [
+               'result' => false,
+            ];
+        } else {
+            return [
+               'result' => true,
+               'name'   => $result['filename'],
+            ];
         }
+    }
         
-        public function newIntoDB(array $FILE_INFO, array $fingerPrintInfo):void
-        {
-            $q = $this->DB->prepare(
-               'INSERT INTO files (hash, originalname, filename, size, date, ip)' .
+    public function newIntoDB(array $FILE_INFO, array $fingerPrintInfo):void
+    {
+        $q = $this->DB->prepare(
+            'INSERT INTO files (hash, originalname, filename, size, date, ip)' .
                'VALUES (:hash, :orig, :name, :size, :date, :ip)',
-            );
-            $q->bindValue(':hash', $FILE_INFO['XXH']);
-            $q->bindValue(':orig', $FILE_INFO['NAME']);
-            $q->bindValue(':name', $FILE_INFO['FILENAME']);
-            $q->bindValue(':size', $FILE_INFO['SIZE'], PDO::PARAM_INT);
-            $q->bindValue(':date', $fingerPrintInfo['timestamp']);
-            $q->bindValue(':ip', $fingerPrintInfo['ip']);
-            $q->execute();
-            $q->closeCursor();
-        }
+        );
+        $q->bindValue(':hash', $FILE_INFO['XXH']);
+        $q->bindValue(':orig', $FILE_INFO['NAME']);
+        $q->bindValue(':name', $FILE_INFO['FILENAME']);
+        $q->bindValue(':size', $FILE_INFO['SIZE'], PDO::PARAM_INT);
+        $q->bindValue(':date', $fingerPrintInfo['timestamp']);
+        $q->bindValue(':ip', $fingerPrintInfo['ip']);
+        $q->execute();
+        $q->closeCursor();
+    }
         
-        public function createRateLimit(array $fingerPrintInfo):void
-        {
-            $q = $this->DB->prepare(
-               'INSERT INTO ratelimit (iphash, files, time)' .
+    public function createRateLimit(array $fingerPrintInfo):void
+    {
+        $q = $this->DB->prepare(
+            'INSERT INTO ratelimit (iphash, files, time)' .
                'VALUES (:iphash, :files, :time)',
+        );
+        $q->bindValue(':iphash', $fingerPrintInfo['ip_hash']);
+        $q->bindValue(':files', $fingerPrintInfo['files_amount']);
+        $q->bindValue(':time', $fingerPrintInfo['timestamp']);
+        $q->execute();
+        $q->closeCursor();
+    }
+        
+    public function updateRateLimit(int $fCount, bool $iStamp, array $fingerPrintInfo):void
+    {
+        if ($iStamp) {
+            $q = $this->DB->prepare(
+                'UPDATE ratelimit SET files = (:files), time = (:time) WHERE iphash = (:iphash)',
             );
-            $q->bindValue(':iphash', $fingerPrintInfo['ip_hash']);
-            $q->bindValue(':files', $fingerPrintInfo['files_amount']);
             $q->bindValue(':time', $fingerPrintInfo['timestamp']);
-            $q->execute();
-            $q->closeCursor();
+        } else {
+            $q = $this->DB->prepare(
+                'UPDATE ratelimit SET files = (:files) WHERE iphash = (:iphash)',
+            );
         }
+        $q->bindValue(':files', $fCount);
+        $q->bindValue(':iphash', $fingerPrintInfo['ip_hash']);
+        $q->execute();
+        $q->closeCursor();
+    }
         
-        public function updateRateLimit(int $fCount, bool $iStamp, array $fingerPrintInfo):void
-        {
-            if ($iStamp) {
-                $q = $this->DB->prepare(
-                   'UPDATE ratelimit SET files = (:files), time = (:time) WHERE iphash = (:iphash)',
-                );
-                $q->bindValue(':time', $fingerPrintInfo['timestamp']);
-            } else {
-                $q = $this->DB->prepare(
-                   'UPDATE ratelimit SET files = (:files) WHERE iphash = (:iphash)',
-                );
-            }
-            $q->bindValue(':files', $fCount);
-            $q->bindValue(':iphash', $fingerPrintInfo['ip_hash']);
-            $q->execute();
-            $q->closeCursor();
+    public function compareTime(int $timestamp, int $seconds_d):bool
+    {
+        $diff = time() - $timestamp;
+        if ($diff > $seconds_d) {
+            return true;
         }
+        return false;
+    }
         
-        public function compareTime(int $timestamp, int $seconds_d):bool
-        {
-            $diff = time() - $timestamp;
-            if ($diff > $seconds_d) {
-                return true;
-            }
+    public function checkRateLimit(array $fingerPrintInfo, int $rateTimeout, int $fileLimit):bool
+    {
+        $query = match ($this->dbType) {
+            'pgsql' => 'SELECT EXISTS(SELECT id FROM ratelimit WHERE iphash = (:iphash)), id, iphash, files, time FROM ratelimit WHERE iphash = (:iphash) LIMIT 1',
+            default => 'SELECT * FROM ratelimit WHERE iphash = (:iphash) AND EXISTS (SELECT id FROM ratelimit WHERE iphash = (:iphash)) LIMIT 1'
+        };
+        $q = $this->DB->prepare($query);
+        $q->bindValue(':iphash', $fingerPrintInfo['ip_hash']);
+        $q->execute();
+        $result = $q->fetch();
+        $q->closeCursor();
+        //If there is no other match a record does not exist, create one.
+        if (!$result) {
+            $this->createRateLimit($fingerPrintInfo);
             return false;
         }
-        
-        public function checkRateLimit(array $fingerPrintInfo, int $rateTimeout, int $fileLimit):bool
-        {
-            $query = match ($this->dbType) {
-                'pgsql' => 'SELECT EXISTS(SELECT id FROM ratelimit WHERE iphash = (:iphash)), id, iphash, files, time FROM ratelimit WHERE iphash = (:iphash) LIMIT 1',
-                default => 'SELECT * FROM ratelimit WHERE iphash = (:iphash) AND EXISTS (SELECT id FROM ratelimit WHERE iphash = (:iphash)) LIMIT 1'
-            };
-            $q = $this->DB->prepare($query);
-            $q->bindValue(':iphash', $fingerPrintInfo['ip_hash']);
-            $q->execute();
-            $result = $q->fetch();
-            $q->closeCursor();
-            //If there is no other match a record does not exist, create one.
-            if (!$result) {
-                $this->createRateLimit($fingerPrintInfo);
-                return false;
-            }
-            // Apply rate-limit when file count reached and timeout not reached.
-            if ($result['files'] === $fileLimit and !$this->compareTime($result['time'], $rateTimeout)) {
-                return true;
-            }
-            // Update timestamp if timeout reached, reset file count and add the incoming file count.
-            if ($this->compareTime($result['time'], $rateTimeout)) {
-                $this->updateRateLimit($fingerPrintInfo['files_amount'], true, $fingerPrintInfo);
-                return false;
-            }
-            // Add filecount, timeout not reached.
-            if ($result['files'] < $fileLimit and !$this->compareTime($result['time'], $rateTimeout)) {
-                $this->updateRateLimit($result['files'] + $fingerPrintInfo['files_amount'], false, $fingerPrintInfo);
-                return false;
-            }
+        // Apply rate-limit when file count reached and timeout not reached.
+        if ($result['files'] === $fileLimit and !$this->compareTime($result['time'], $rateTimeout)) {
+            return true;
+        }
+        // Update timestamp if timeout reached, reset file count and add the incoming file count.
+        if ($this->compareTime($result['time'], $rateTimeout)) {
+            $this->updateRateLimit($fingerPrintInfo['files_amount'], true, $fingerPrintInfo);
+            return false;
+        }
+        // Add filecount, timeout not reached.
+        if ($result['files'] < $fileLimit and !$this->compareTime($result['time'], $rateTimeout)) {
+            $this->updateRateLimit($result['files'] + $fingerPrintInfo['files_amount'], false, $fingerPrintInfo);
             return false;
         }
-    }
\ No newline at end of file
+        return false;
+    }
+}
index d5588b68c693ac98b2881f1f29302a783e7f60c4..f0233aff46b5fc8f9488ffc2f211cac4c7aa56bc 100755 (executable)
@@ -1,39 +1,39 @@
 <?php
-    /*
    * Uguu
    *
    * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
    *
    * Note that this was previously distributed under the MIT license 2015-2022.
    *
    * If you are a company that wants to use Uguu I urge you to contact me to
    * solve any potential license issues rather then using pre-2022 code.
    *
    * A special thanks goes out to the open source community around the world
    * for supporting and being the backbone of projects like Uguu.
    *
    * This project can be found at <https://github.com/nokonoko/Uguu>.
    *
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program.  If not, see <https://www.gnu.org/licenses/>.
    */
+/*
+ * Uguu
+ *
+ * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+ *
+ * Note that this was previously distributed under the MIT license 2015-2022.
+ *
+ * If you are a company that wants to use Uguu I urge you to contact me to
+ * solve any potential license issues rather then using pre-2022 code.
+ *
+ * A special thanks goes out to the open source community around the world
+ * for supporting and being the backbone of projects like Uguu.
+ *
+ * This project can be found at <https://github.com/nokonoko/Uguu>.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
     
-    namespace Pomf\Uguu\Classes;
-    
-    class GrillLoader extends CuteGrills
+namespace Pomf\Uguu\Classes;
+
+class GrillLoader extends CuteGrills
+{
+    public function __construct()
     {
-        public function __construct()
-        {
-            $this->showGrills();
-        }
+        $this->showGrills();
     }
+}
index c9e231bcbd39c231c2fd8086959d7ffde3c5d168..4eafece270965f0045aa79f0661b7134ccd60d9e 100755 (executable)
 <?php
-    /*
-     * Uguu
+/*
+ * Uguu
+ *
+ * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+ *
+ * Note that this was previously distributed under the MIT license 2015-2022.
+ *
+ * If you are a company that wants to use Uguu I urge you to contact me to
+ * solve any potential license issues rather then using pre-2022 code.
+ *
+ * A special thanks goes out to the open source community around the world
+ * for supporting and being the backbone of projects like Uguu.
+ *
+ * This project can be found at <https://github.com/nokonoko/Uguu>.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+    
+namespace Pomf\Uguu\Classes;
+
+class Response
+{
+    public string $type;
+        
+    /**
+     * Takes a string as an argument and sets the header to the appropriate content type
      *
-     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+     * @param $response_type string The type of response you want to return.
+     *                       Valid options are: csv, html, json, text.
+     */
+    public function __construct(string $response_type)
+    {
+        switch ($response_type) {
+            case 'csv':
+                header('Content-Type: text/csv; charset=UTF-8');
+                $this->type = $response_type;
+                break;
+            case 'html':
+                header('Content-Type: text/html; charset=UTF-8');
+                $this->type = $response_type;
+                break;
+            case 'json':
+                header('Content-Type: application/json; charset=UTF-8');
+                $this->type = $response_type;
+                break;
+            case 'gyazo':
+                header('Content-Type: text/plain; charset=UTF-8');
+                $this->type = 'text';
+                break;
+            case 'text':
+                header('Content-Type: text/plain; charset=UTF-8');
+                $this->type = $response_type;
+                break;
+            default:
+                header('Content-Type: application/json; charset=UTF-8');
+                $this->type = 'json';
+                break;
+        }
+    }
+        
+    /**
+     * Returns a string based on the type of response requested
      *
-     * Note that this was previously distributed under the MIT license 2015-2022.
+     * @param $code mixed The HTTP status code to return.
+     * @param $desc string The description of the error.
+     */
+    public function error(int $code, string $desc):string
+    {
+        $response = match ($this->type) {
+            'csv' => $this->csvError($desc),
+            'html' => $this->htmlError($code, $desc),
+            'json' => $this->jsonError($code, $desc),
+            'text' => $this->textError($code, $desc),
+        };
+        http_response_code($code);
+        echo $response;
+        exit(1);
+    }
+        
+    /* Returning a string that contains the error message. */
+    private static function csvError(string $description):string
+    {
+        return '"error"' . "\r\n" . "\"$description\"" . "\r\n";
+    }
+        
+    /**
+     * Returns a string containing an HTML paragraph element with the error code and description
      *
-     * If you are a company that wants to use Uguu I urge you to contact me to
-     * solve any potential license issues rather then using pre-2022 code.
+     * @param $code        int|string The error code.
+     * @param $description string The description of the error.
      *
-     * A special thanks goes out to the open source community around the world
-     * for supporting and being the backbone of projects like Uguu.
+     * @return string A string.
+     */
+    private static function htmlError(int|string $code, string $description):string
+    {
+        return '<p>ERROR: (' . $code . ') ' . $description . '</p>';
+    }
+        
+    /**
+     * Returns a JSON string with the error code and description
      *
-     * This project can be found at <https://github.com/nokonoko/Uguu>.
+     * @param $code        int|string The error code.
+     * @param $description string The description of the error.
      *
-     * This program is free software: you can redistribute it and/or modify
-     * it under the terms of the GNU General Public License as published by
-     * the Free Software Foundation, either version 3 of the License, or
-     * (at your option) any later version.
+     * @return bool|string A JSON string
+     */
+    private static function jsonError(int|string $code, string $description):bool|string
+    {
+        return json_encode([
+           'success'     => false,
+           'errorcode'   => $code,
+           'description' => $description,
+        ], JSON_PRETTY_PRINT);
+    }
+        
+    /**
+     * Returns a string that contains the error code and description
      *
-     * This program is distributed in the hope that it will be useful,
-     * but WITHOUT ANY WARRANTY; without even the implied warranty of
-     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-     * GNU General Public License for more details.
+     * @param $code        int|string The error code.
+     * @param $description string The description of the error.
      *
-     * You should have received a copy of the GNU General Public License
-     * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+     * @return string A string with the error code and description.
      */
-    
-    namespace Pomf\Uguu\Classes;
-    
-    class Response
+    private static function textError(int|string $code, string $description):string
     {
-        public string $type;
-        
-        /**
-         * Takes a string as an argument and sets the header to the appropriate content type
-         *
-         * @param $response_type string The type of response you want to return.
-         *                       Valid options are: csv, html, json, text.
-         */
-        public function __construct(string $response_type)
-        {
-            switch ($response_type) {
-                case 'csv':
-                    header('Content-Type: text/csv; charset=UTF-8');
-                    $this->type = $response_type;
-                    break;
-                case 'html':
-                    header('Content-Type: text/html; charset=UTF-8');
-                    $this->type = $response_type;
-                    break;
-                case 'json':
-                    header('Content-Type: application/json; charset=UTF-8');
-                    $this->type = $response_type;
-                    break;
-                case 'gyazo':
-                    header('Content-Type: text/plain; charset=UTF-8');
-                    $this->type = 'text';
-                    break;
-                case 'text':
-                    header('Content-Type: text/plain; charset=UTF-8');
-                    $this->type = $response_type;
-                    break;
-                default:
-                    header('Content-Type: application/json; charset=UTF-8');
-                    $this->type = 'json';
-                    break;
-            }
-        }
-        
-        /**
-         * Returns a string based on the type of response requested
-         *
-         * @param $code mixed The HTTP status code to return.
-         * @param $desc string The description of the error.
-         */
-        public function error(int $code, string $desc):string
-        {
-            $response = match ($this->type) {
-                'csv' => $this->csvError($desc),
-                'html' => $this->htmlError($code, $desc),
-                'json' => $this->jsonError($code, $desc),
-                'text' => $this->textError($code, $desc),
-            };
-            http_response_code($code);
-            echo $response;
-            exit(1);
-        }
-        
-        /* Returning a string that contains the error message. */
-        private static function csvError(string $description):string
-        {
-            return '"error"' . "\r\n" . "\"$description\"" . "\r\n";
-        }
-        
-        /**
-         * Returns a string containing an HTML paragraph element with the error code and description
-         *
-         * @param $code        int|string The error code.
-         * @param $description string The description of the error.
-         *
-         * @return string A string.
-         */
-        private static function htmlError(int|string $code, string $description):string
-        {
-            return '<p>ERROR: (' . $code . ') ' . $description . '</p>';
-        }
+        return 'ERROR: (' . $code . ') ' . $description;
+    }
         
-        /**
-         * Returns a JSON string with the error code and description
-         *
-         * @param $code        int|string The error code.
-         * @param $description string The description of the error.
-         *
-         * @return bool|string A JSON string
-         */
-        private static function jsonError(int|string $code, string $description):bool|string
-        {
-            return json_encode([
-               'success'     => false,
-               'errorcode'   => $code,
-               'description' => $description,
-            ], JSON_PRETTY_PRINT);
-        }
-        
-        /**
-         * Returns a string that contains the error code and description
-         *
-         * @param $code        int|string The error code.
-         * @param $description string The description of the error.
-         *
-         * @return string A string with the error code and description.
-         */
-        private static function textError(int|string $code, string $description):string
-        {
-            return 'ERROR: (' . $code . ') ' . $description;
-        }
-        
-        /**
-         * "If the type is csv, then call the csvSuccess function,
-         * if the type is html, then call the htmlSuccess function, etc."
-         *
-         * The `match` keyword is a new feature in PHP 8. It's a lot like a switch statement, but it's more powerful
-         *
-         * @param $files array An array of file objects.
-         */
-        public function send(array $files):void
-        {
-            $response = match ($this->type) {
-                'csv' => $this->csvSuccess($files),
-                'html' => $this->htmlSuccess($files),
-                'json' => $this->jsonSuccess($files),
-                'text' => $this->textSuccess($files),
-            };
-            http_response_code(200); // "200 OK". Success.
-            echo $response;
-        }
+    /**
+     * "If the type is csv, then call the csvSuccess function,
+     * if the type is html, then call the htmlSuccess function, etc."
+     *
+     * The `match` keyword is a new feature in PHP 8. It's a lot like a switch statement, but it's more powerful
+     *
+     * @param $files array An array of file objects.
+     */
+    public function send(array $files):void
+    {
+        $response = match ($this->type) {
+            'csv' => $this->csvSuccess($files),
+            'html' => $this->htmlSuccess($files),
+            'json' => $this->jsonSuccess($files),
+            'text' => $this->textSuccess($files),
+        };
+        http_response_code(200); // "200 OK". Success.
+        echo $response;
+    }
         
-        /**
-         * Takes an array of files and returns a CSV string
-         *
-         * @param $files array An array of files that have been uploaded.
-         *
-         * @return string A string of the files in the array.
-         */
-        private static function csvSuccess(array $files):string
-        {
-            $result = '"name","url","hash","size"' . "\r\n";
-            foreach ($files as $file) {
-                $result .= '"' . $file['name'] . '"' . ',' .
-                   '"' . $file['url'] . '"' . ',' .
-                   '"' . $file['hash'] . '"' . ',' .
-                   '"' . $file['size'] . '"' . "\r\n";
-            }
-            return $result;
+    /**
+     * Takes an array of files and returns a CSV string
+     *
+     * @param $files array An array of files that have been uploaded.
+     *
+     * @return string A string of the files in the array.
+     */
+    private static function csvSuccess(array $files):string
+    {
+        $result = '"name","url","hash","size"' . "\r\n";
+        foreach ($files as $file) {
+            $result .= '"' . $file['name'] . '"' . ',' .
+               '"' . $file['url'] . '"' . ',' .
+               '"' . $file['hash'] . '"' . ',' .
+               '"' . $file['size'] . '"' . "\r\n";
         }
+        return $result;
+    }
         
-        /**
-         * Takes an array of files and returns a string of HTML links
-         *
-         * @param $files array An array of files to be uploaded.
-         *
-         * @return string the result of the foreach loop.
-         */
-        private static function htmlSuccess(array $files):string
-        {
-            $result = '';
-            foreach ($files as $file) {
-                $result .= '<a href="' . $file['url'] . '">' . $file['url'] . '</a><br>';
-            }
-            return $result;
+    /**
+     * Takes an array of files and returns a string of HTML links
+     *
+     * @param $files array An array of files to be uploaded.
+     *
+     * @return string the result of the foreach loop.
+     */
+    private static function htmlSuccess(array $files):string
+    {
+        $result = '';
+        foreach ($files as $file) {
+            $result .= '<a href="' . $file['url'] . '">' . $file['url'] . '</a><br>';
         }
+        return $result;
+    }
         
-        /**
-         * Returns a JSON string that contains a success message and the files that were uploaded
-         *
-         * @param $files array The files to be uploaded.
-         *
-         * @return bool|string A JSON string
-         */
-        private static function jsonSuccess(array $files):bool|string
-        {
-            return json_encode([
-               'success' => true,
-               'files'   => $files,
-            ], JSON_PRETTY_PRINT);
-        }
+    /**
+     * Returns a JSON string that contains a success message and the files that were uploaded
+     *
+     * @param $files array The files to be uploaded.
+     *
+     * @return bool|string A JSON string
+     */
+    private static function jsonSuccess(array $files):bool|string
+    {
+        return json_encode([
+           'success' => true,
+           'files'   => $files,
+        ], JSON_PRETTY_PRINT);
+    }
         
-        /**
-         * Takes an array of files and returns a string of URLs
-         *
-         * @param $files array The files to be uploaded.
-         *
-         * @return string the url of the file.
-         */
-        private static function textSuccess(array $files):string
-        {
-            $result = '';
-            foreach ($files as $file) {
-                $result .= $file['url'] . "\n";
-            }
-            return $result;
+    /**
+     * Takes an array of files and returns a string of URLs
+     *
+     * @param $files array The files to be uploaded.
+     *
+     * @return string the url of the file.
+     */
+    private static function textSuccess(array $files):string
+    {
+        $result = '';
+        foreach ($files as $file) {
+            $result .= $file['url'] . "\n";
         }
-    }
\ No newline at end of file
+        return $result;
+    }
+}
index a01cef592a7b89ef70c24ffe365dc4ef180337eb..894e8df6e56d6274398e20cdc3d16223df0d6639 100755 (executable)
 <?php
-    /*
-     * Uguu
-     *
-     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
-     * @links
-     *
-     * Note that this was previously distributed under the MIT license 2015-2022.
-     *
-     * If you are a company that wants to use Uguu I urge you to contact me to
-     * solve any potential license issues rather then using pre-2022 code.
-     *
-     * A special thanks goes out to the open source community around the world
-     * for supporting and being the backbone of projects like Uguu.
-     *
-     * This project can be found at <https://github.com/nokonoko/Uguu>.
+/*
+ * Uguu
+ *
+ * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+ * @links
+ *
+ * Note that this was previously distributed under the MIT license 2015-2022.
+ *
+ * If you are a company that wants to use Uguu I urge you to contact me to
+ * solve any potential license issues rather then using pre-2022 code.
+ *
+ * A special thanks goes out to the open source community around the world
+ * for supporting and being the backbone of projects like Uguu.
+ *
+ * This project can be found at <https://github.com/nokonoko/Uguu>.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+namespace Pomf\Uguu\Classes;
+
+class Upload extends Response
+{
+    public array $FILE_INFO;
+    public array $fingerPrintInfo;
+    private mixed $Connector;
+        
+    /**
+     * Resolves and processes an array of files, performing various checks and operations on each file.
      *
-     * This program is free software: you can redistribute it and/or modify
-     * it under the terms of the GNU General Public License as published by
-     * the Free Software Foundation, either version 3 of the License, or
-     * (at your option) any later version.
+     * Check if the file is a dupe (if enabled).
+     * Generate a new name (if not a dupe).
+     * Generate hash of the file.
+     * Get the extension of the file.
+     * Get the MIME of the file.
+     * Get the size of the file.
      *
-     * This program is distributed in the hope that it will be useful,
-     * but WITHOUT ANY WARRANTY; without even the implied warranty of
-     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-     * GNU General Public License for more details.
+     * @param array $files An array of file data. Each element should be an associative array
+     *                     *             with the following keys:
+     *                     *             - 'tmp_name' : The temporary name of the uploaded file.
+     *                     *             - 'name'     : The original name of the file.
+     *                     *             - 'size'     : The size of the file in bytes.
      *
-     * You should have received a copy of the GNU General Public License
-     * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+     * @return array An array containing information about each uploaded file. Each element of the array
+     * *             is an associative array with the following keys:
+     * *             - 'temp_name' : The temporary name of the uploaded file.
+     * *             - 'name'      : The processed name of the file after checking for length and removing tags.
+     * *             - 'size'      : The size of the uploaded file in bytes.
+     * *             - 'xxh'       : The xxhash of the uploaded file.
+     * *             - 'extension' : The file extension.
+     * *             - 'mime'      : The MIME type of the file.
+     * *             - 'dupe'      : Indicates if the uploaded file is a duplicate.
+     * *             - 'filename'  : The final filename of the uploaded file.
      */
-    
-    namespace Pomf\Uguu\Classes;
-    
-    class Upload extends Response
+    public function reFiles(array $files):array
     {
-        public array $FILE_INFO;
-        public array $fingerPrintInfo;
-        private mixed $Connector;
-        
-        /**
-         * Resolves and processes an array of files, performing various checks and operations on each file.
-         *
-         * Check if the file is a dupe (if enabled).
-         * Generate a new name (if not a dupe).
-         * Generate hash of the file.
-         * Get the extension of the file.
-         * Get the MIME of the file.
-         * Get the size of the file.
-         *
-         * @param array $files An array of file data. Each element should be an associative array
-         *                     *             with the following keys:
-         *                     *             - 'tmp_name' : The temporary name of the uploaded file.
-         *                     *             - 'name'     : The original name of the file.
-         *                     *             - 'size'     : The size of the file in bytes.
-         *
-         * @return array An array containing information about each uploaded file. Each element of the array
-         * *             is an associative array with the following keys:
-         * *             - 'temp_name' : The temporary name of the uploaded file.
-         * *             - 'name'      : The processed name of the file after checking for length and removing tags.
-         * *             - 'size'      : The size of the uploaded file in bytes.
-         * *             - 'xxh'       : The xxhash of the uploaded file.
-         * *             - 'extension' : The file extension.
-         * *             - 'mime'      : The MIME type of the file.
-         * *             - 'dupe'      : Indicates if the uploaded file is a duplicate.
-         * *             - 'filename'  : The final filename of the uploaded file.
-         */
-        public function reFiles(array $files):array
-        {
-            $this->Connector = new Connector();
-            $result = [];
-            $files = $this->diverseArray($files);
-            foreach ($files as $file) {
-                $this->FILE_INFO = [
-                   'TEMP_NAME' => $file['tmp_name'],
-                   'NAME'      => strip_tags($this->checkNameLength($file['name'])),
-                   'SIZE'      => $file['size'],
-                   'XXH'       => hash_file('xxh3', $file['tmp_name']),
-                   'EXTENSION' => $this->fileExtension($file),
-                   'MIME'      => $this->fileMIME($file),
-                   'DUPE'      => false,
-                   'FILENAME'  => null,
-                ];
-                // Check if anti dupe is enabled
-                if ($this->Connector->CONFIG['ANTI_DUPE']) {
-                    // Check if hash exists in DB, if it does return the name of the file
-                    $dupeResult = $this->Connector->antiDupe($this->FILE_INFO['XXH']);
-                    if ($dupeResult['result']) {
-                        $this->FILE_INFO['FILENAME'] = $dupeResult['name'];
-                        $this->FILE_INFO['DUPE'] = true;
-                    }
-                }
-                // If its not a dupe then generate a new name
-                if (!$this->FILE_INFO['DUPE']) {
-                    $this->FILE_INFO['FILENAME'] = $this->generateName($this->FILE_INFO['EXTENSION']);
+        $this->Connector = new Connector();
+        $result = [];
+        $files = $this->diverseArray($files);
+        foreach ($files as $file) {
+            $this->FILE_INFO = [
+               'TEMP_NAME' => $file['tmp_name'],
+               'NAME'      => strip_tags($this->checkNameLength($file['name'])),
+               'SIZE'      => $file['size'],
+               'XXH'       => hash_file('xxh3', $file['tmp_name']),
+               'EXTENSION' => $this->fileExtension($file),
+               'MIME'      => $this->fileMIME($file),
+               'DUPE'      => false,
+               'FILENAME'  => null,
+            ];
+            // Check if anti dupe is enabled
+            if ($this->Connector->CONFIG['ANTI_DUPE']) {
+                // Check if hash exists in DB, if it does return the name of the file
+                $dupeResult = $this->Connector->antiDupe($this->FILE_INFO['XXH']);
+                if ($dupeResult['result']) {
+                    $this->FILE_INFO['FILENAME'] = $dupeResult['name'];
+                    $this->FILE_INFO['DUPE'] = true;
                 }
-                $result[] = [
-                   $this->FILE_INFO['TEMP_NAME'],
-                   $this->FILE_INFO['NAME'],
-                   $this->FILE_INFO['SIZE'],
-                   $this->FILE_INFO['XXH'],
-                   $this->FILE_INFO['EXTENSION'],
-                   $this->FILE_INFO['MIME'],
-                   $this->FILE_INFO['DUPE'],
-                   $this->FILE_INFO['FILENAME'],
-                ];
             }
-            return $result;
+            // If its not a dupe then generate a new name
+            if (!$this->FILE_INFO['DUPE']) {
+                $this->FILE_INFO['FILENAME'] = $this->generateName($this->FILE_INFO['EXTENSION']);
+            }
+            $result[] = [
+               $this->FILE_INFO['TEMP_NAME'],
+               $this->FILE_INFO['NAME'],
+               $this->FILE_INFO['SIZE'],
+               $this->FILE_INFO['XXH'],
+               $this->FILE_INFO['EXTENSION'],
+               $this->FILE_INFO['MIME'],
+               $this->FILE_INFO['DUPE'],
+               $this->FILE_INFO['FILENAME'],
+            ];
         }
+        return $result;
+    }
         
-        /**
-         * Rearranges a multidimensional array by exchanging the keys of the first and second level.
-         *
-         * @param array $files The multidimensional array to be rearranged.
-         *
-         * @return array The rearranged array with exchanged keys of the first and second level.
-         */
-        public function diverseArray(array $files):array
-        {
-            $result = [];
-            foreach ($files as $key1 => $value1) {
-                foreach ($value1 as $key2 => $value2) {
-                    $result[$key2][$key1] = $value2;
-                }
+    /**
+     * Rearranges a multidimensional array by exchanging the keys of the first and second level.
+     *
+     * @param array $files The multidimensional array to be rearranged.
+     *
+     * @return array The rearranged array with exchanged keys of the first and second level.
+     */
+    public function diverseArray(array $files):array
+    {
+        $result = [];
+        foreach ($files as $key1 => $value1) {
+            foreach ($value1 as $key2 => $value2) {
+                $result[$key2][$key1] = $value2;
             }
-            return $result;
         }
+        return $result;
+    }
         
-        /**
-         * Performs various checks (if enabled), insert info into database, moves file to storage
-         * location, then returns an array of file information.
-         *
-         * If a check is triggered or another error occurs it will return an error stating why
-         * the file was unable to be uploaded.
-         *
-         * @return array An array containing the following information:
-         *               - hash     : The hash value of the uploaded file
-         *               - name     : The name of the uploaded file
-         *               - filename : The filename of the uploaded file
-         *               - url      : The URL of the uploaded file
-         *               - size     : The size of the uploaded file
-         *               - dupe     : Boolean indicating whether the file is a duplicate
-         */
-        public function uploadFile():array
-        {
-            if ($this->Connector->CONFIG['RATE_LIMIT']) {
-                if (
-                   $this->Connector->checkRateLimit(
-                      $this->fingerPrintInfo,
-                      $this->Connector->CONFIG['RATE_LIMIT_TIMEOUT'],
-                      $this->Connector->CONFIG['RATE_LIMIT_FILES'],
-                   )
-                ) {
-                    $this->Connector->response->error(
-                       500,
-                       'Rate limit, please wait ' . $this->Connector->CONFIG['RATE_LIMIT_TIMEOUT'] .
+    /**
+     * Performs various checks (if enabled), insert info into database, moves file to storage
+     * location, then returns an array of file information.
+     *
+     * If a check is triggered or another error occurs it will return an error stating why
+     * the file was unable to be uploaded.
+     *
+     * @return array An array containing the following information:
+     *               - hash     : The hash value of the uploaded file
+     *               - name     : The name of the uploaded file
+     *               - filename : The filename of the uploaded file
+     *               - url      : The URL of the uploaded file
+     *               - size     : The size of the uploaded file
+     *               - dupe     : Boolean indicating whether the file is a duplicate
+     */
+    public function uploadFile():array
+    {
+        if ($this->Connector->CONFIG['RATE_LIMIT']) {
+            if (
+                $this->Connector->checkRateLimit(
+                    $this->fingerPrintInfo,
+                    $this->Connector->CONFIG['RATE_LIMIT_TIMEOUT'],
+                    $this->Connector->CONFIG['RATE_LIMIT_FILES'],
+                )
+            ) {
+                $this->Connector->response->error(
+                    500,
+                    'Rate limit, please wait ' . $this->Connector->CONFIG['RATE_LIMIT_TIMEOUT'] .
                        ' seconds before uploading again.',
-                    );
-                }
-            }
-            if ($this->Connector->CONFIG['BLACKLIST_DB']) {
-                $this->Connector->checkFileBlacklist($this->FILE_INFO['XXH']);
-            }
-            if ($this->Connector->CONFIG['FILTER_MODE'] && empty($this->FILE_INFO['EXTENSION'])) {
-                $this->checkMimeBlacklist();
-            }
-            if ($this->Connector->CONFIG['FILTER_MODE'] && !empty($this->FILE_INFO['EXTENSION'])) {
-                $this->checkMimeBlacklist();
-                $this->checkExtensionBlacklist();
-            }
-            if (!$this->Connector->CONFIG['FILTER_MODE'] && empty($this->FILE_INFO['EXTENSION'])) {
-                $this->checkMimeWhitelist();
+                );
             }
-            if (!$this->Connector->CONFIG['FILTER_MODE'] && !empty($this->FILE_INFO['EXTENSION'])) {
-                $this->checkMimeWhitelist();
-                $this->checkExtensionWhitelist();
+        }
+        if ($this->Connector->CONFIG['BLACKLIST_DB']) {
+            $this->Connector->checkFileBlacklist($this->FILE_INFO['XXH']);
+        }
+        if ($this->Connector->CONFIG['FILTER_MODE'] && empty($this->FILE_INFO['EXTENSION'])) {
+            $this->checkMimeBlacklist();
+        }
+        if ($this->Connector->CONFIG['FILTER_MODE'] && !empty($this->FILE_INFO['EXTENSION'])) {
+            $this->checkMimeBlacklist();
+            $this->checkExtensionBlacklist();
+        }
+        if (!$this->Connector->CONFIG['FILTER_MODE'] && empty($this->FILE_INFO['EXTENSION'])) {
+            $this->checkMimeWhitelist();
+        }
+        if (!$this->Connector->CONFIG['FILTER_MODE'] && !empty($this->FILE_INFO['EXTENSION'])) {
+            $this->checkMimeWhitelist();
+            $this->checkExtensionWhitelist();
+        }
+        // If its not a dupe then skip checking if file can be written and
+        // skip inserting it into the DB.
+        if (!$this->FILE_INFO['DUPE']) {
+            if (!is_dir($this->Connector->CONFIG['FILES_ROOT'])) {
+                $this->Connector->response->error(500, 'File storage path not accessible.');
             }
-            // If its not a dupe then skip checking if file can be written and
-            // skip inserting it into the DB.
-            if (!$this->FILE_INFO['DUPE']) {
-                if (!is_dir($this->Connector->CONFIG['FILES_ROOT'])) {
-                    $this->Connector->response->error(500, 'File storage path not accessible.');
-                }
-                if (
-                   !move_uploaded_file(
-                      $this->FILE_INFO['TEMP_NAME'],
-                      $this->Connector->CONFIG['FILES_ROOT'] .
+            if (
+                !move_uploaded_file(
+                    $this->FILE_INFO['TEMP_NAME'],
+                    $this->Connector->CONFIG['FILES_ROOT'] .
                       $this->FILE_INFO['FILENAME'],
-                   )
-                ) {
-                    $this->Connector->response->error(500, 'Failed to move file to destination.');
-                }
-                if (!chmod($this->Connector->CONFIG['FILES_ROOT'] . $this->FILE_INFO['FILENAME'], 0644)) {
-                    $this->Connector->response->error(500, 'Failed to change file permissions.');
-                }
-                $this->Connector->newIntoDB($this->FILE_INFO, $this->fingerPrintInfo);
+                )
+            ) {
+                $this->Connector->response->error(500, 'Failed to move file to destination.');
             }
-            return [
-               'hash'     => $this->FILE_INFO['XXH'],
-               'name'     => $this->FILE_INFO['NAME'],
-               'filename' => $this->FILE_INFO['FILENAME'],
-               'url'      => 'https://' . $this->Connector->CONFIG['FILE_DOMAIN'] . '/' . $this->FILE_INFO['FILENAME'],
-               'size'     => $this->FILE_INFO['SIZE'],
-               'dupe'     => $this->FILE_INFO['DUPE'],
-            ];
+            if (!chmod($this->Connector->CONFIG['FILES_ROOT'] . $this->FILE_INFO['FILENAME'], 0644)) {
+                $this->Connector->response->error(500, 'Failed to change file permissions.');
+            }
+            $this->Connector->newIntoDB($this->FILE_INFO, $this->fingerPrintInfo);
         }
+        return [
+           'hash'     => $this->FILE_INFO['XXH'],
+           'name'     => $this->FILE_INFO['NAME'],
+           'filename' => $this->FILE_INFO['FILENAME'],
+           'url'      => 'https://' . $this->Connector->CONFIG['FILE_DOMAIN'] . '/' . $this->FILE_INFO['FILENAME'],
+           'size'     => $this->FILE_INFO['SIZE'],
+           'dupe'     => $this->FILE_INFO['DUPE'],
+        ];
+    }
         
-        /**
-         * Takes the amount of files that are being uploaded, and creates a fingerprint of the user's IP address,
-         * user agent, and the amount of files being uploaded.
-         *
-         * @param $files_amount int The amount of files that are being uploaded.
-         *
-         */
-        public function fingerPrint(int $files_amount):void
-        {
-            if (!empty($_SERVER['HTTP_USER_AGENT'])) {
-                $USER_AGENT = filter_var($_SERVER['HTTP_USER_AGENT'], FILTER_SANITIZE_ENCODED);
-                $ip = null;
-                if ($this->Connector->CONFIG['LOG_IP']) {
-                    $ip = $_SERVER['REMOTE_ADDR'];
-                }
-                $this->fingerPrintInfo = [
-                   'timestamp'    => time(),
-                   'useragent'    => $USER_AGENT,
-                   'ip'           => $ip,
-                   'ip_hash'      => hash('xxh3', $_SERVER['REMOTE_ADDR'] . $USER_AGENT),
-                   'files_amount' => $files_amount,
-                ];
-            } else {
-                $this->Connector->response->error(500, 'Invalid user agent.');
+    /**
+     * Takes the amount of files that are being uploaded, and creates a fingerprint of the user's IP address,
+     * user agent, and the amount of files being uploaded.
+     *
+     * @param $files_amount int The amount of files that are being uploaded.
+     *
+     */
+    public function fingerPrint(int $files_amount):void
+    {
+        if (!empty($_SERVER['HTTP_USER_AGENT'])) {
+            $USER_AGENT = filter_var($_SERVER['HTTP_USER_AGENT'], FILTER_SANITIZE_ENCODED);
+            $ip = null;
+            if ($this->Connector->CONFIG['LOG_IP']) {
+                $ip = $_SERVER['REMOTE_ADDR'];
             }
+            $this->fingerPrintInfo = [
+               'timestamp'    => time(),
+               'useragent'    => $USER_AGENT,
+               'ip'           => $ip,
+               'ip_hash'      => hash('xxh3', $_SERVER['REMOTE_ADDR'] . $USER_AGENT),
+               'files_amount' => $files_amount,
+            ];
+        } else {
+            $this->Connector->response->error(500, 'Invalid user agent.');
         }
+    }
         
-        /**
-         * Returns the MIME type of a file
-         *
-         * @param $file array The file to be checked.
-         *
-         * @return string The MIME type of the file.
-         */
-        public function fileMIME(array $file):string
-        {
-            $FILE_INFO = finfo_open(FILEINFO_MIME_TYPE);
-            return finfo_file($FILE_INFO, $file['tmp_name']);
-        }
+    /**
+     * Returns the MIME type of a file
+     *
+     * @param $file array The file to be checked.
+     *
+     * @return string The MIME type of the file.
+     */
+    public function fileMIME(array $file):string
+    {
+        $FILE_INFO = finfo_open(FILEINFO_MIME_TYPE);
+        return finfo_file($FILE_INFO, $file['tmp_name']);
+    }
         
-        /**
-         * Determines the double dot file extension from the given file.
-         *
-         * If the last two elements of the array contain double dots, those will be extracted and concatenated.
-         * If the resulting double-dot extension is present in the whitelist, it will be returned.
-         * Otherwise, the last element of the array will be returned.
-         *
-         * @param array $extension An array of strings representing file extensions.
-         *
-         * @return string The extracted extension.
-         */
-        public function doubleDotExtension(array $extension):string
-        {
-            $doubleDotArray = array_slice($extension, -2, 2);
-            $doubleDot = strtolower(preg_replace('/[^a-zA-Z.]/', '', join('.', $doubleDotArray)));
-            if (in_array($doubleDot, $this->Connector->CONFIG['DOUBLE_DOTS_EXTENSIONS'])) {
-                return $doubleDot;
-            } else {
-                return end($extension);
-            }
+    /**
+     * Determines the double dot file extension from the given file.
+     *
+     * If the last two elements of the array contain double dots, those will be extracted and concatenated.
+     * If the resulting double-dot extension is present in the whitelist, it will be returned.
+     * Otherwise, the last element of the array will be returned.
+     *
+     * @param array $extension An array of strings representing file extensions.
+     *
+     * @return string The extracted extension.
+     */
+    public function doubleDotExtension(array $extension):string
+    {
+        $doubleDotArray = array_slice($extension, -2, 2);
+        $doubleDot = strtolower(preg_replace('/[^a-zA-Z.]/', '', join('.', $doubleDotArray)));
+        if (in_array($doubleDot, $this->Connector->CONFIG['DOUBLE_DOTS_EXTENSIONS'])) {
+            return $doubleDot;
         }
+        return end($extension);
+    }
         
-        /**
-         * Determines the file extension from the given file.
-         *
-         * The method checks if the file name contains a dot (.). If it does, the file name is split
-         * using the dot as the delimiter to extract the extension. The number of dots in the file name
-         * is also counted to handle special cases.
-         *
-         * If the file name contains exactly two dots, the method calls the doubleDotExtension() function
-         * to handle the special case. Otherwise, the method returns the last element of the exploded
-         * file name array, which represents the extension.
-         *
-         * @param array $file The file array containing the name of the file.
-         *
-         * @return string|bool The file extension if it exists, or false if the file name does not contain a dot.
-         */
-        public function fileExtension(array $file):string|bool
-        {
-            if (str_contains($file['name'], '.')) {
-                $extension = explode('.', $file['name']);
-                $dotCount = substr_count($file['name'], '.');
-                return match ($dotCount) {
-                    2 => $this->doubleDotExtension($extension),
-                    default => end($extension)
-                };
-            }
-            return false;
+    /**
+     * Determines the file extension from the given file.
+     *
+     * The method checks if the file name contains a dot (.). If it does, the file name is split
+     * using the dot as the delimiter to extract the extension. The number of dots in the file name
+     * is also counted to handle special cases.
+     *
+     * If the file name contains exactly two dots, the method calls the doubleDotExtension() function
+     * to handle the special case. Otherwise, the method returns the last element of the exploded
+     * file name array, which represents the extension.
+     *
+     * @param array $file The file array containing the name of the file.
+     *
+     * @return string|bool The file extension if it exists, or false if the file name does not contain a dot.
+     */
+    public function fileExtension(array $file):string|bool
+    {
+        if (str_contains($file['name'], '.')) {
+            $extension = explode('.', $file['name']);
+            $dotCount = substr_count($file['name'], '.');
+            return match ($dotCount) {
+                2 => $this->doubleDotExtension($extension),
+                default => end($extension)
+            };
         }
+        return false;
+    }
         
-        /**
-         * Checks if the MIME type of the uploaded file is in the blacklist.
-         *
-         * If the MIME is in the blacklist, an error is returned indicating that the filetype
-         * is not allowed.
-         *
-         */
-        public function checkMimeBlacklist():void
-        {
-            if (in_array($this->FILE_INFO['MIME'], $this->Connector->CONFIG['FILTER_MIME'])) {
-                $this->Connector->response->error(415, 'Filetype not allowed');
-            }
+    /**
+     * Checks if the MIME type of the uploaded file is in the blacklist.
+     *
+     * If the MIME is in the blacklist, an error is returned indicating that the filetype
+     * is not allowed.
+     *
+     */
+    public function checkMimeBlacklist():void
+    {
+        if (in_array($this->FILE_INFO['MIME'], $this->Connector->CONFIG['FILTER_MIME'])) {
+            $this->Connector->response->error(415, 'Filetype not allowed');
         }
+    }
         
-        /**
-         * Checks if the MIME type of the uploaded file is in the whitelist.
-         *
-         * If the MIME type is not in the whitelist, an error is returned indicating that the filetype
-         * is not allowed.
-         *
-         */
-        public function checkMimeWhitelist():void
-        {
-            if (!in_array($this->FILE_INFO['MIME'], $this->Connector->CONFIG['FILTER_MIME'])) {
-                $this->Connector->response->error(415, 'Filetype not allowed');
-            }
+    /**
+     * Checks if the MIME type of the uploaded file is in the whitelist.
+     *
+     * If the MIME type is not in the whitelist, an error is returned indicating that the filetype
+     * is not allowed.
+     *
+     */
+    public function checkMimeWhitelist():void
+    {
+        if (!in_array($this->FILE_INFO['MIME'], $this->Connector->CONFIG['FILTER_MIME'])) {
+            $this->Connector->response->error(415, 'Filetype not allowed');
         }
+    }
         
-        /**
-         * Checks if the extension of the uploaded file is in the blacklist.
-         *
-         * If the extension is in the blacklist, an error is returned indicating that the filetype
-         * is not allowed.
-         *
-         */
-        public function checkExtensionBlacklist():void
-        {
-            if (in_array($this->FILE_INFO['EXTENSION'], $this->Connector->CONFIG['FILTER_EXTENSIONS'])) {
-                $this->Connector->response->error(415, 'Filetype not allowed');
-            }
+    /**
+     * Checks if the extension of the uploaded file is in the blacklist.
+     *
+     * If the extension is in the blacklist, an error is returned indicating that the filetype
+     * is not allowed.
+     *
+     */
+    public function checkExtensionBlacklist():void
+    {
+        if (in_array($this->FILE_INFO['EXTENSION'], $this->Connector->CONFIG['FILTER_EXTENSIONS'])) {
+            $this->Connector->response->error(415, 'Filetype not allowed');
         }
+    }
         
-        /**
-         * Checks if the extension of the uploaded file is in the whitelist.
-         *
-         * If the extension is not in the whitelist, an error is returned indicating that the filetype
-         * is not allowed.
-         *
-         */
-        public function checkExtensionWhitelist():void
-        {
-            if (!in_array($this->FILE_INFO['EXTENSION'], $this->Connector->CONFIG['FILTER_EXTENSIONS'])) {
-                $this->Connector->response->error(415, 'Filetype not allowed');
-            }
+    /**
+     * Checks if the extension of the uploaded file is in the whitelist.
+     *
+     * If the extension is not in the whitelist, an error is returned indicating that the filetype
+     * is not allowed.
+     *
+     */
+    public function checkExtensionWhitelist():void
+    {
+        if (!in_array($this->FILE_INFO['EXTENSION'], $this->Connector->CONFIG['FILTER_EXTENSIONS'])) {
+            $this->Connector->response->error(415, 'Filetype not allowed');
         }
+    }
         
-        /**
-         * Checks if the length of the given filename exceeds 250 characters.
-         *
-         * If the length of the filename exceeds 250 characters, it is truncated to a maximum of 250 characters.
-         * Otherwise, the filename remains unchanged.
-         *
-         * @param string $fileName The filename to check the length for.
-         *
-         * @return string The filename, either unchanged or truncated if its length exceeds 250 characters.
-         */
-        public function checkNameLength(string $fileName):string
-        {
-            if (strlen($fileName) > 250) {
-                return substr($fileName, 0, 250);
-            } else {
-                return $fileName;
-            }
+    /**
+     * Checks if the length of the given filename exceeds 250 characters.
+     *
+     * If the length of the filename exceeds 250 characters, it is truncated to a maximum of 250 characters.
+     * Otherwise, the filename remains unchanged.
+     *
+     * @param string $fileName The filename to check the length for.
+     *
+     * @return string The filename, either unchanged or truncated if its length exceeds 250 characters.
+     */
+    public function checkNameLength(string $fileName):string
+    {
+        if (strlen($fileName) > 250) {
+            return substr($fileName, 0, 250);
         }
+        return $fileName;
+    }
         
-        /**
-         * Generates a unique name for a file.
-         *
-         * This method generates a random name for a file by selecting characters from the ID_CHARSET
-         * defined in the Connector's CONFIG. If an extension is provided, it appends the extension
-         * to the generated name. The method then checks if the generated name already exists in the
-         * database using the dbCheckNameExists() function. If the generated name
-         * already exists, it generates a new name until a unique one is found. If the maximum number
-         * of retries is reached, an error is returned.
-         *
-         * @param string $extension The extension of the file.
-         *
-         * @return string The generated unique name for the file.
-         */
-        public function generateName(string $extension):string
-        {
-            do {
-                if ($this->Connector->CONFIG['FILES_RETRIES'] === 0) {
-                    $this->Connector->response->error(500, 'Gave up trying to find an unused name!');
-                }
-                $NEW_NAME = '';
-                for ($i = 0; $i < $this->Connector->CONFIG['NAME_LENGTH']; $i++) {
-                    $index = rand(0, strlen($this->Connector->CONFIG['ID_CHARSET']) - 1);
-                    $NEW_NAME .= $this->Connector->CONFIG['ID_CHARSET'][$index];
-                }
-                if ($extension) {
-                    $NEW_NAME .= '.' . $extension;
-                }
-            } while ($this->Connector->dbCheckNameExists($NEW_NAME));
-            return $NEW_NAME;
-        }
+    /**
+     * Generates a unique name for a file.
+     *
+     * This method generates a random name for a file by selecting characters from the ID_CHARSET
+     * defined in the Connector's CONFIG. If an extension is provided, it appends the extension
+     * to the generated name. The method then checks if the generated name already exists in the
+     * database using the dbCheckNameExists() function. If the generated name
+     * already exists, it generates a new name until a unique one is found. If the maximum number
+     * of retries is reached, an error is returned.
+     *
+     * @param string $extension The extension of the file.
+     *
+     * @return string The generated unique name for the file.
+     */
+    public function generateName(string $extension):string
+    {
+        do {
+            if ($this->Connector->CONFIG['FILES_RETRIES'] === 0) {
+                $this->Connector->response->error(500, 'Gave up trying to find an unused name!');
+            }
+            $NEW_NAME = $this->Connector->randomizer->getBytesFromString(
+                $this->Connector->CONFIG['ID_CHARSET'],
+                $this->Connector->CONFIG['NAME_LENGTH'],
+            );
+            if ($extension) {
+                $NEW_NAME .= '.' . $extension;
+            }
+        } while ($this->Connector->dbCheckNameExists($NEW_NAME));
+        return $NEW_NAME;
     }
+}
index 635067887e7327e6459db7e2b0ecb8aa84a43136..f06b384c5c7ac59f77cf59f89dd07068c49ed4c0 100755 (executable)
 <?php
-    /*
    * Uguu
    *
    * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
    *
    * Note that this was previously distributed under the MIT license 2015-2022.
    *
    * If you are a company that wants to use Uguu I urge you to contact me to
    * solve any potential license issues rather then using pre-2022 code.
    *
    * A special thanks goes out to the open source community around the world
    * for supporting and being the backbone of projects like Uguu.
    *
    * This project can be found at <https://github.com/nokonoko/Uguu>.
    *
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program.  If not, see <https://www.gnu.org/licenses/>.
    */
+/*
+ * Uguu
+ *
+ * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+ *
+ * Note that this was previously distributed under the MIT license 2015-2022.
+ *
+ * If you are a company that wants to use Uguu I urge you to contact me to
+ * solve any potential license issues rather then using pre-2022 code.
+ *
+ * A special thanks goes out to the open source community around the world
+ * for supporting and being the backbone of projects like Uguu.
+ *
+ * This project can be found at <https://github.com/nokonoko/Uguu>.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
     
-    namespace Pomf\Uguu\Classes;
+namespace Pomf\Uguu\Classes;
+
+use PDO;
     
-    use PDO;
+class expireChecker
+{
+    public PDO $DB;
+    public string $dbType;
+    public array $CONFIG;
+    public string $timeUnit;
+    /**
+     * @var \Pomf\Uguu\Classes\Response
+     */
+    private Response $response;
     
-    class expireChecker
+    public function checkDB():bool|array
     {
-        public PDO $DB;
-        public string $dbType;
-        public array $CONFIG;
-        public string $timeUnit;
-        
-        public function checkDB():bool|array
-        {
-            if (is_int($this->CONFIG['expireTime'])) {
-                $this->timeUnit = strtoupper($this->CONFIG['expireTimeUnit']);
-                if (!in_array($this->timeUnit, ['SECONDS', 'MINUTES', 'HOURS', 'DAYS', 'WEEKS', 'MONTHS', 'YEARS'])) {
-                    $this->timeUnit = "HOURS";
-                }
-                $query = match ($this->dbType) {
-                    'pgsql' => 'SELECT id, filename FROM files WHERE date < EXTRACT(epoch from NOW() - INTERVAL \'' . $this->CONFIG['expireTime'] . ' ' . $this->timeUnit . '\')',
-                    default => 'SELECT id, filename FROM files WHERE date <= strftime(\'%s\', datetime(\'now\', \'-' . $this->CONFIG['expireTime'] . ' ' . $this->timeUnit . '\'));'
-                };
-                $q = $this->DB->prepare($query);
-                $q->execute();
-                $result = $q->fetchAll(PDO::FETCH_ASSOC);
-                $q->closeCursor();
-                $returnArray = [
-                   'ids'       => [],
-                   'filenames' => [],
-                ];
-                foreach ($result as $array) {
-                    $returnArray['ids'][] = $array['id'];
-                    $returnArray['filenames'][] = $array['filename'];
-                }
-                return $returnArray;
-            } else {
-                return false;
+        if (is_int($this->CONFIG['expireTime'])) {
+            $this->timeUnit = strtoupper($this->CONFIG['expireTimeUnit']);
+            if (!in_array($this->timeUnit, ['SECONDS', 'MINUTES', 'HOURS', 'DAYS', 'WEEKS', 'MONTHS', 'YEARS'])) {
+                $this->timeUnit = "HOURS";
             }
-        }
-        
-        public function cleanRateLimitDB():void
-        {
             $query = match ($this->dbType) {
-                'pgsql' => 'DELETE FROM ratelimit WHERE time < EXTRACT(epoch from NOW() - INTERVAL \'24 HOURS\')',
-                default => 'DELETE FROM ratelimit WHERE time <= strftime(\'%s\', datetime(\'now\', \'-24 HOURS\'));'
+                'pgsql' => 'SELECT id, filename FROM files WHERE date < EXTRACT(epoch from NOW() - INTERVAL \'' . $this->CONFIG['expireTime'] . ' ' . $this->timeUnit . '\')',
+                default => 'SELECT id, filename FROM files WHERE date <= strftime(\'%s\', datetime(\'now\', \'-' . $this->CONFIG['expireTime'] . ' ' . $this->timeUnit . '\'));'
             };
             $q = $this->DB->prepare($query);
             $q->execute();
+            $result = $q->fetchAll(PDO::FETCH_ASSOC);
             $q->closeCursor();
+            $returnArray = [
+               'ids'       => [],
+               'filenames' => [],
+            ];
+            foreach ($result as $array) {
+                $returnArray['ids'][] = $array['id'];
+                $returnArray['filenames'][] = $array['filename'];
+            }
+            return $returnArray;
+        } else {
+            return false;
         }
+    }
         
-        public function deleteFiles(array $filenames):void
-        {
-            foreach ($filenames as $filename) {
-                unlink($this->CONFIG['FILES_ROOT'] . $filename);
-            }
+    public function cleanRateLimitDB():void
+    {
+        $query = match ($this->dbType) {
+            'pgsql' => 'DELETE FROM ratelimit WHERE time < EXTRACT(epoch from NOW() - INTERVAL \'24 HOURS\')',
+            default => 'DELETE FROM ratelimit WHERE time <= strftime(\'%s\', datetime(\'now\', \'-24 HOURS\'));'
+        };
+        $q = $this->DB->prepare($query);
+        $q->execute();
+        $q->closeCursor();
+    }
+        
+    public function deleteFiles(array $filenames):void
+    {
+        foreach ($filenames as $filename) {
+            unlink($this->CONFIG['FILES_ROOT'] . $filename);
         }
+    }
         
-        public function deleteFromDB(array $ids):void
-        {
-            foreach ($ids as $id) {
-                $query = match ($this->dbType) {
-                    'pgsql' => 'DELETE FROM files WHERE id = (:id)',
-                    default => 'DELETE FROM files WHERE id = (:id)'
-                };
-                $q = $this->DB->prepare($query);
-                $q->bindValue(':id', $id);
-                $q->execute();
-                $q->closeCursor();
-            }
+    public function deleteFromDB(array $ids):void
+    {
+        foreach ($ids as $id) {
+            $query = match ($this->dbType) {
+                'pgsql' => 'DELETE FROM files WHERE id = (:id)',
+                default => 'DELETE FROM files WHERE id = (:id)'
+            };
+            $q = $this->DB->prepare($query);
+            $q->bindValue(':id', $id);
+            $q->execute();
+            $q->closeCursor();
         }
+    }
         
-        /**
-         * Reads the config.json file and populates the CONFIG property with the settings
-         * Also assembles the PDO DB connection and registers error handlers.
-         *
-         */
-        public function __construct()
-        {
-            $this->response = new Response('json');
-            if (!file_exists(__DIR__ . '/../config.json')) {
-                $this->response->error(500, 'Cant read settings file.');
-            }
-            $this->CONFIG = json_decode(
-               file_get_contents(__DIR__ . '/../config.json'),
-               true,
-            );
-            ini_set('display_errors', 0);
-            $this->dbType = $this->CONFIG['DB_MODE'];
-            $this->DB = new PDO(
-               $this->CONFIG['DB_MODE'] . ':' . $this->CONFIG['DB_PATH'],
-               $this->CONFIG['DB_USER'],
-               $this->CONFIG['DB_PASS'],
-            );
+    /**
+     * Reads the config.json file and populates the CONFIG property with the settings
+     * Also assembles the PDO DB connection and registers error handlers.
+     *
+     */
+    public function __construct()
+    {
+        $this->response = new Response('json');
+        if (!file_exists(__DIR__ . '/../config.json')) {
+            $this->response->error(500, 'Cant read settings file.');
         }
+        $this->CONFIG = json_decode(
+            file_get_contents(__DIR__ . '/../config.json'),
+            true,
+        );
+        ini_set('display_errors', 0);
+        $this->dbType = $this->CONFIG['DB_MODE'];
+        $this->DB = new PDO(
+            $this->CONFIG['DB_MODE'] . ':' . $this->CONFIG['DB_PATH'],
+            $this->CONFIG['DB_USER'],
+            $this->CONFIG['DB_PASS'],
+        );
     }
-
-
-
-
-
+}
index c744c279ad781b5f6a3748362a8490b039ee8aa0..e3d646a0ef67e883a9724336c192359c92d7af48 100755 (executable)
@@ -1,6 +1,6 @@
 {
   "dest": "dist",
-  "pkgVersion": "1.8.4",
+  "pkgVersion": "1.8.5",
   "pages": [
     "index.ejs",
     "faq.ejs",
index eb8e4bcc6ec274a2f1c9497f0e68bbe3f4867ae9..7d08c3eaa8d4b00011a330a1ebd4964bbeb65e12 100755 (executable)
@@ -1,43 +1,43 @@
 <?php
-    /*
-     * Uguu
-     *
-     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
-     *
-     * Note that this was previously distributed under the MIT license 2015-2022.
-     *
-     * If you are a company that wants to use Uguu I urge you to contact me to
-     * solve any potential license issues rather then using pre-2022 code.
-     *
-     * A special thanks goes out to the open source community around the world
-     * for supporting and being the backbone of projects like Uguu.
-     *
-     * This project can be found at <https://github.com/nokonoko/Uguu>.
-     *
-     * This program is free software: you can redistribute it and/or modify
-     * it under the terms of the GNU General Public License as published by
-     * the Free Software Foundation, either version 3 of the License, or
-     * (at your option) any later version.
-     *
-     * This program is distributed in the hope that it will be useful,
-     * but WITHOUT ANY WARRANTY; without even the implied warranty of
-     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-     * GNU General Public License for more details.
-     *
-     * You should have received a copy of the GNU General Public License
-     * along with this program.  If not, see <https://www.gnu.org/licenses/>.
-     */
-    
-    require_once __DIR__ . '/vendor/autoload.php';
-    
-    use Pomf\Uguu\Classes\expireChecker;
-    
-    $check = new expireChecker();
-    $dbResult = $check->checkDB();
-    $check->cleanRateLimitDB();
-    if (empty($dbResult['ids'])) {
-        echo "No file(s) expired, nothing to do.";
-    } else {
-        $check->deleteFromDB($dbResult['ids']);
-        $check->deleteFiles($dbResult['filenames']);
-    }
\ No newline at end of file
+/*
+ * Uguu
+ *
+ * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+ *
+ * Note that this was previously distributed under the MIT license 2015-2022.
+ *
+ * If you are a company that wants to use Uguu I urge you to contact me to
+ * solve any potential license issues rather then using pre-2022 code.
+ *
+ * A special thanks goes out to the open source community around the world
+ * for supporting and being the backbone of projects like Uguu.
+ *
+ * This project can be found at <https://github.com/nokonoko/Uguu>.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+require_once __DIR__ . '/vendor/autoload.php';
+
+use Pomf\Uguu\Classes\expireChecker;
+
+$check = new expireChecker();
+$dbResult = $check->checkDB();
+$check->cleanRateLimitDB();
+if (empty($dbResult['ids'])) {
+    echo "No file(s) expired, nothing to do.";
+} else {
+    $check->deleteFromDB($dbResult['ids']);
+    $check->deleteFiles($dbResult['filenames']);
+}
index 92eac59d05147678f7a4ad84c9b4be55f9853a4d..b5390b72398240a523d4a4c64e3c1dfb8441cf2c 100755 (executable)
@@ -1,35 +1,35 @@
 <?php
-    /*
    * Uguu
    *
    * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
    *
    * Note that this was previously distributed under the MIT license 2015-2022.
    *
    * If you are a company that wants to use Uguu I urge you to contact me to
    * solve any potential license issues rather then using pre-2022 code.
    *
    * A special thanks goes out to the open source community around the world
    * for supporting and being the backbone of projects like Uguu.
    *
    * This project can be found at <https://github.com/nokonoko/Uguu>.
    *
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program.  If not, see <https://www.gnu.org/licenses/>.
    */
+/*
+ * Uguu
+ *
+ * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+ *
+ * Note that this was previously distributed under the MIT license 2015-2022.
+ *
+ * If you are a company that wants to use Uguu I urge you to contact me to
+ * solve any potential license issues rather then using pre-2022 code.
+ *
+ * A special thanks goes out to the open source community around the world
+ * for supporting and being the backbone of projects like Uguu.
+ *
+ * This project can be found at <https://github.com/nokonoko/Uguu>.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
     
-    require_once __DIR__ . '/../vendor/autoload.php';
+require_once __DIR__ . '/../vendor/autoload.php';
     
-    use Pomf\Uguu\Classes\GrillLoader;
+use Pomf\Uguu\Classes\GrillLoader;
     
-    new GrillLoader();
+new GrillLoader();
index ee4d5c3536f1f40becf6a0d5095ca1b88595d92f..9fd5153512926e72798193f990d30cdbd061f6a0 100755 (executable)
@@ -1,58 +1,57 @@
 <?php
-    /*
-     * Uguu
-     *
-     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
-     *
-     * Note that this was previously distributed under the MIT license 2015-2022.
-     *
-     * If you are a company that wants to use Uguu I urge you to contact me to
-     * solve any potential license issues rather then using pre-2022 code.
-     *
-     * A special thanks goes out to the open source community around the world
-     * for supporting and being the backbone of projects like Uguu.
-     *
-     * This project can be found at <https://github.com/nokonoko/Uguu>.
-     *
-     * This program is free software: you can redistribute it and/or modify
-     * it under the terms of the GNU General Public License as published by
-     * the Free Software Foundation, either version 3 of the License, or
-     * (at your option) any later version.
-     *
-     * This program is distributed in the hope that it will be useful,
-     * but WITHOUT ANY WARRANTY; without even the implied warranty of
-     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-     * GNU General Public License for more details.
-     *
-     * You should have received a copy of the GNU General Public License
-     * along with this program.  If not, see <https://www.gnu.org/licenses/>.
-     */
-    
-    require_once __DIR__ . '/../vendor/autoload.php';
-    
-    use Pomf\Uguu\Classes\Upload;
-    use Pomf\Uguu\Classes\Response;
-    
-    function handleFiles(string $outputFormat, array $files):void
-    {
-        $upload = new Upload($outputFormat);
-        $files = $upload->reFiles($files);
-        $fCount = count($files);
-        $upload->fingerPrint($fCount);
-        $res = [];
-        $i = 0;
-        while ($i < $fCount) {
-            $res[] = $upload->uploadFile();
-            $i++;
-        }
-        if (!empty($res)) {
-            $upload->send($res);
-        }
+/*
+ * Uguu
+ *
+ * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+ *
+ * Note that this was previously distributed under the MIT license 2015-2022.
+ *
+ * If you are a company that wants to use Uguu I urge you to contact me to
+ * solve any potential license issues rather then using pre-2022 code.
+ *
+ * A special thanks goes out to the open source community around the world
+ * for supporting and being the backbone of projects like Uguu.
+ *
+ * This project can be found at <https://github.com/nokonoko/Uguu>.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+require_once __DIR__ . '/../vendor/autoload.php';
+use Pomf\Uguu\Classes\Upload;
+use Pomf\Uguu\Classes\Response;
+
+function handleFiles(string $outputFormat, array $files):void
+{
+    $upload = new Upload($outputFormat);
+    $files = $upload->reFiles($files);
+    $fCount = count($files);
+    $upload->fingerPrint($fCount);
+    $res = [];
+    $i = 0;
+    while ($i < $fCount) {
+        $res[] = $upload->uploadFile();
+        $i++;
     }
-    
-    $resType = (isset($_GET['output']) and !empty($_GET['output'])) ? strtolower(preg_replace('/[^a-zA-Z]/', '', $_GET['output'])) : 'json';
-    $response = new Response($resType);
-    if (!isset($_FILES['files']) or empty($_FILES['files'])) {
-        $response->error(400, 'No input file(s)');
+    if (!empty($res)) {
+        $upload->send($res);
     }
-    handleFiles($resType, $_FILES['files']);
\ No newline at end of file
+}
+
+$resType = (isset($_GET['output']) and !empty($_GET['output'])) ? strtolower(preg_replace('/[^a-zA-Z]/', '', $_GET['output'])) : 'json';
+$response = new Response($resType);
+if (!isset($_FILES['files']) or empty($_FILES['files'])) {
+    $response->error(400, 'No input file(s)');
+}
+handleFiles($resType, $_FILES['files']);