From 6b16f63c835e995ba0b97e6b3fa0d78a3ce68c9c Mon Sep 17 00:00:00 2001 From: Go Johansson Date: Sun, 23 Jan 2022 12:33:37 +0100 Subject: [PATCH] 1.5.0 changes --- dist.json | 2 +- package.json | 6 ++--- static/php/includes/Core.namespace.php | 14 ++++++----- static/php/includes/Upload.class.php | 34 +++++++++++--------------- static/php/upload.php | 4 +-- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/dist.json b/dist.json index 3b44d09..c9f1e8a 100644 --- a/dist.json +++ b/dist.json @@ -3,7 +3,7 @@ "allowErrors": false }, "dest": "dist", - "pkgVersion": "1.4.0", + "pkgVersion": "1.5.0", "banners": [ "banners/malware_scans.swig", "banners/donations.swig" diff --git a/package.json b/package.json index e4a57d5..6aa703b 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "uguu", - "version": "1.4.0", + "version": "1.5.0", "description": "Kawaii file host", "homepage": "https://uguu.se/", "repository": { "type": "git", - "url": "https://github.com/nokonoko/pomf" + "url": "https://github.com/nokonoko/uguu" }, - "author": "Eric Johansson ", + "author": "Go Johansson ", "contributors": [ "Pomf Community ", "Uguu Community " diff --git a/static/php/includes/Core.namespace.php b/static/php/includes/Core.namespace.php index bbb216b..b566533 100644 --- a/static/php/includes/Core.namespace.php +++ b/static/php/includes/Core.namespace.php @@ -87,7 +87,7 @@ namespace Core { } catch (Exception) { throw new Exception('Cant populate settings.', 500); } - (new Database())->assemblePDO(); + Database::assemblePDO(); } } @@ -283,7 +283,7 @@ namespace Core { /** * @throws Exception */ - public function dbCheckNameExists() + public static function dbCheckNameExists() { try { $q = Settings::$DB->prepare('SELECT COUNT(filename) FROM files WHERE filename = (:name)'); @@ -298,7 +298,7 @@ namespace Core { /** * @throws Exception */ - public function checkFileBlacklist() + public static function checkFileBlacklist() { try { $q = Settings::$DB->prepare('SELECT hash, COUNT(*) AS count FROM blacklist WHERE hash = (:hash)'); @@ -316,7 +316,7 @@ namespace Core { /** * @throws Exception */ - public function antiDupe() + public static function antiDupe() { try { $q = Settings::$DB->prepare( @@ -327,7 +327,9 @@ namespace Core { $q->execute(); $result = $q->fetch(); if ($result['count'] > 0) { - return $result['filename']; + Upload::$NEW_NAME_FULL = $result['filename']; + } else { + Upload::generateName(); } } catch (Exception) { throw new Exception('Cant check for dupes in DB.', 500); @@ -337,7 +339,7 @@ namespace Core { /** * @throws Exception */ - public function newIntoDB() + public static function newIntoDB() { try { $q = Settings::$DB->prepare( diff --git a/static/php/includes/Upload.class.php b/static/php/includes/Upload.class.php index edf9b7c..31bb2d1 100644 --- a/static/php/includes/Upload.class.php +++ b/static/php/includes/Upload.class.php @@ -39,7 +39,7 @@ class Upload public static string $TEMP_FILE; - public function reFiles($files): array + public static function reFiles($files): array { $result = []; $files = self::diverseArray($files); @@ -54,7 +54,7 @@ class Upload return $result; } - public function diverseArray($files): array + public static function diverseArray($files): array { $result = []; @@ -69,13 +69,13 @@ class Upload /** * @throws Exception */ - public function uploadFile(): array + public static function uploadFile(): array { - (new Settings())->loadConfig(); - (new Upload())->fileInfo(); + Settings::loadConfig(); + self::fileInfo(); if (Settings::$BLACKLIST_DB) { - (new Database())->checkFileBlacklist(); + Database::checkFileBlacklist(); } if (Settings::$FILTER_MODE) { @@ -84,16 +84,11 @@ class Upload } if (Settings::$ANTI_DUPE) { - $result = (new Database())->antiDupe(); - if (isset($result)) { - self::$NEW_NAME_FULL = $result; - } else { - (new Upload())->generateName(); - } + Database::antiDupe(); } if (!Settings::$ANTI_DUPE) { - (new Upload())->generateName(); + self::generateName(); } if (!is_dir(Settings::$FILES_ROOT)) { @@ -108,7 +103,7 @@ class Upload throw new Exception('Failed to change file permissions', 500); } - (new Database())->newIntoDB(); + Database::newIntoDB(); if (Settings::$SSL) { $preURL = 'https://'; @@ -124,7 +119,7 @@ class Upload ]; } - public function fileInfo() + public static function fileInfo() { if (isset($_FILES['files'])) { $finfo = finfo_open(FILEINFO_MIME_TYPE); @@ -144,7 +139,7 @@ class Upload /** * @throws Exception */ - public function checkMimeBlacklist() + public static function checkMimeBlacklist() { if (in_array(self::$FILE_MIME, Settings::$BLOCKED_MIME)) { throw new Exception('Filetype not allowed.', 415); @@ -157,7 +152,7 @@ class Upload * * @throws Exception */ - public function checkExtensionBlacklist() + public static function checkExtensionBlacklist() { if (in_array(self::$FILE_EXTENSION, Settings::$BLOCKED_EXTENSIONS)) { throw new Exception('Filetype not allowed.', 415); @@ -167,7 +162,7 @@ class Upload /** * @throws Exception */ - public function generateName(): string + public static function generateName() { do { if (Settings::$FILES_RETRIES === 0) { @@ -183,7 +178,6 @@ class Upload self::$NEW_NAME_FULL = self::$NEW_NAME; self::$NEW_NAME_FULL .= '.' . self::$FILE_EXTENSION; } - } while ((new Database())->dbCheckNameExists() > 0); - return self::$NEW_NAME_FULL; + } while (Database::dbCheckNameExists() > 0); } } \ No newline at end of file diff --git a/static/php/upload.php b/static/php/upload.php index 27ff3e3..37458a9 100644 --- a/static/php/upload.php +++ b/static/php/upload.php @@ -24,11 +24,11 @@ $type = $_GET['output'] ?? 'json'; $response = (new Core\Response($type)); if (isset($_FILES['files'])) { - $uploads = (new Upload())->reFiles($_FILES['files']); + $uploads = Upload::reFiles($_FILES['files']); try { foreach ($uploads as $upload) { - $res[] = (new Upload())->uploadFile(); + $res[] = Upload::uploadFile(); } if (isset($res)) { $response->send($res);