From c81b68956b90325c6f729e1aeb1c727cc19a5637 Mon Sep 17 00:00:00 2001 From: Banana Date: Wed, 25 Dec 2019 00:10:02 +0100 Subject: [PATCH] some code recovery from backup --- TODO | 2 +- webroot/lib/management.class.php | 12 ++++++++++++ webroot/lib/summoner.class.php | 22 ++++++++++++++++++++++ webroot/view/stats.inc.php | 1 + webroot/view/stats.php | 2 +- 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 962b2a6..e0d988b 100755 --- a/TODO +++ b/TODO @@ -1,9 +1,9 @@ TODO / Feature list ========================================================================== -+ delete of a link + stats, storage usage. With stats and valid auth display moderation + email import auto reply check + flush local storage of images ++ delete single local storage of a link + sorting + snapshots + bookmark js snippet diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index 1076ac6..42f08b0 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -511,6 +511,18 @@ class Management { return $ret; } + public function storageAmount() { + $ret = 0; + + $_storageFolder = ABSOLUTE_PATH.'/'.LOCAL_STORAGE; + + if(file_exists($_storageFolder) && is_readable($_storageFolder)) { + $ret = Summoner::folderSize(); + } + + return $ret; + } + /** * Load link by given hash. Do not use Link class directly. diff --git a/webroot/lib/summoner.class.php b/webroot/lib/summoner.class.php index e04b8f9..df42dea 100644 --- a/webroot/lib/summoner.class.php +++ b/webroot/lib/summoner.class.php @@ -464,4 +464,26 @@ class Summoner { return $ret; } + + static function folderSize($folder) { + $ret = 0; + + if(file_exists($folder) && is_readable($folder)) { + foreach (glob(rtrim($folder, '/') . '/*', GLOB_NOSORT) as $each) { + $ret += is_file($each) ? filesize($each) : self::folderSize($each); + } + } + + return $ret; + } + + static function humanFileSize($size,$unit="") { + if( (!$unit && $size >= 1<<30) || $unit == "GB") + return number_format($size/(1<<30),2)."GB"; + if( (!$unit && $size >= 1<<20) || $unit == "MB") + return number_format($size/(1<<20),2)."MB"; + if( (!$unit && $size >= 1<<10) || $unit == "KB") + return number_format($size/(1<<10),2)."KB"; + return number_format($size)." bytes"; + } } diff --git a/webroot/view/stats.inc.php b/webroot/view/stats.inc.php index e72953a..041ff41 100644 --- a/webroot/view/stats.inc.php +++ b/webroot/view/stats.inc.php @@ -34,4 +34,5 @@ if(Summoner::simpleAuthCheck() === true) { $linkAmount = $Management->linkAmount(); $tagAmount = $Management->tagAmount(); $categoryAmount = $Management->categoryAmount(); +$localStorageAmount = $Management->storageAmount(); diff --git a/webroot/view/stats.php b/webroot/view/stats.php index 0a4ddd3..f62b99c 100644 --- a/webroot/view/stats.php +++ b/webroot/view/stats.php @@ -75,7 +75,7 @@

Local image storage

-

# Moderation needed:

+

Diskspace used:

Delete all

-- 2.39.5