Skip to content

Commit

Permalink
2.8.0 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nokonoko committed Jan 23, 2022
1 parent 5833627 commit 841b772
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"allowErrors": false
},
"dest": "dist",
"pkgVersion": "2.7.0",
"pkgVersion": "2.8.0",
"banners": [
"banners/malware_scans.swig",
"banners/donations.swig"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pomf",
"version": "2.7.0",
"version": "2.8.0",
"description": "Kawaii file hosting",
"homepage": "https://demo.pomf.se",
"repository": {
Expand Down
14 changes: 8 additions & 6 deletions static/php/includes/Core.namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function loadConfig()
} catch (Exception) {
throw new Exception('Cant populate settings.', 500);
}
(new Database())->assemblePDO();
Database::assemblePDO();
}
}

Expand Down Expand Up @@ -283,7 +283,7 @@ public static function assemblePDO()
/**
* @throws Exception
*/
public function dbCheckNameExists()
public static function dbCheckNameExists()
{
try {
$q = Settings::$DB->prepare('SELECT COUNT(filename) FROM files WHERE filename = (:name)');
Expand All @@ -298,7 +298,7 @@ public function dbCheckNameExists()
/**
* @throws Exception
*/
public function checkFileBlacklist()
public static function checkFileBlacklist()
{
try {
$q = Settings::$DB->prepare('SELECT hash, COUNT(*) AS count FROM blacklist WHERE hash = (:hash)');
Expand All @@ -316,7 +316,7 @@ public function checkFileBlacklist()
/**
* @throws Exception
*/
public function antiDupe()
public static function antiDupe()
{
try {
$q = Settings::$DB->prepare(
Expand All @@ -327,7 +327,9 @@ public function antiDupe()
$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);
Expand All @@ -337,7 +339,7 @@ public function antiDupe()
/**
* @throws Exception
*/
public function newIntoDB()
public static function newIntoDB()
{
try {
$q = Settings::$DB->prepare(
Expand Down
39 changes: 18 additions & 21 deletions static/php/includes/Upload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/



require_once 'Core.namespace.php';

use Core\Database as Database;
Expand All @@ -39,7 +40,7 @@ class Upload
public static string $TEMP_FILE;


public function reFiles($files): array
public static function reFiles($files): array
{
$result = [];
$files = self::diverseArray($files);
Expand All @@ -54,7 +55,7 @@ public function reFiles($files): array
return $result;
}

public function diverseArray($files): array
public static function diverseArray($files): array
{
$result = [];

Expand All @@ -69,13 +70,13 @@ public function diverseArray($files): array
/**
* @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) {
Expand All @@ -84,16 +85,11 @@ public function uploadFile(): array
}

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)) {
Expand All @@ -108,7 +104,7 @@ public function uploadFile(): array
throw new Exception('Failed to change file permissions', 500);
}

(new Database())->newIntoDB();
Database::newIntoDB();

if (Settings::$SSL) {
$preURL = 'https://';
Expand All @@ -124,7 +120,7 @@ public function uploadFile(): array
];
}

public function fileInfo()
public static function fileInfo()
{
if (isset($_FILES['files'])) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
Expand All @@ -144,17 +140,20 @@ public function fileInfo()
/**
* @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);
}
}

/**
* Check if file extension is blacklisted
* if it does throw an exception.
*
* @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);
Expand All @@ -164,7 +163,7 @@ public function checkExtensionBlacklist()
/**
* @throws Exception
*/
public function generateName(): string
public static function generateName()
{
do {
if (Settings::$FILES_RETRIES === 0) {
Expand All @@ -180,8 +179,6 @@ public function generateName(): string
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);
}
}
4 changes: 2 additions & 2 deletions static/php/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
$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);
Expand Down

0 comments on commit 841b772

Please sign in to comment.