From 976e10659f36949a63fdc5207c2b67bbb4f5e644 Mon Sep 17 00:00:00 2001 From: Ming Tsay Date: Thu, 20 Oct 2022 20:52:50 +0800 Subject: [PATCH] set order to desc for logs viewer --- .idea/misc.xml | 12 ++++++++++-- app/FileViewer.php | 7 ++++++- app/LogsViewer.php | 1 + templates/index.php | 4 ++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 33fe132..1f3de73 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,8 +4,16 @@ diff --git a/app/FileViewer.php b/app/FileViewer.php index 5a72d3c..e90b65b 100644 --- a/app/FileViewer.php +++ b/app/FileViewer.php @@ -4,6 +4,8 @@ namespace MingTsay\Akanyan; abstract class FileViewer { + protected static bool $orderDesc = false; + protected abstract static function directory(): string; protected abstract static function whitelist(): ?array; @@ -13,10 +15,13 @@ abstract class FileViewer $directory = static::directory(); $whitelist = static::whitelist(); - return array_values(array_filter( + $list = array_values(array_filter( scandir($directory), fn($file) => ($whitelist === null || in_array($file, $whitelist)) && is_file("$directory/$file") )); + + if (static::$orderDesc) rsort($list); + return $list; } public static function read($file): ?string diff --git a/app/LogsViewer.php b/app/LogsViewer.php index 5835706..911532d 100644 --- a/app/LogsViewer.php +++ b/app/LogsViewer.php @@ -4,6 +4,7 @@ namespace MingTsay\Akanyan; class LogsViewer extends FileViewer { + protected static bool $orderDesc = true; protected static function directory(): string { diff --git a/templates/index.php b/templates/index.php index ce92289..28192f9 100644 --- a/templates/index.php +++ b/templates/index.php @@ -50,6 +50,10 @@

【更新紀錄】