mirror of
https://github.com/nokonoko/Uguu.git
synced 2024-01-06 13:35:15 +00:00
1.5.0 changes
This commit is contained in:
parent
5b30192d33
commit
6b16f63c83
@ -3,7 +3,7 @@
|
||||
"allowErrors": false
|
||||
},
|
||||
"dest": "dist",
|
||||
"pkgVersion": "1.4.0",
|
||||
"pkgVersion": "1.5.0",
|
||||
"banners": [
|
||||
"banners/malware_scans.swig",
|
||||
"banners/donations.swig"
|
||||
|
@ -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 <neku@pomf.se>",
|
||||
"author": "Go Johansson <neku@pomf.se>",
|
||||
"contributors": [
|
||||
"Pomf Community <github.com/pomf/pomf>",
|
||||
"Uguu Community <github.com/nokonoko/uguu>"
|
||||
|
@ -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(
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user